-
Notifications
You must be signed in to change notification settings - Fork 0
/
Tinn.dpr
226 lines (202 loc) · 6.99 KB
/
Tinn.dpr
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
program Tinn;
{
The contents of this file are subject to the terms and conditions found under
the GNU General Public License Version 2 or later (the "GPL").
See http://www.opensource.org/licenses/gpl-license.html or
http://www.fsf.org/copyleft/gpl.html for further information.
}
uses
FastMM4,
Forms,
Windows,
SysUtils,
Messages,
classes,
ufrmMain in 'ufrmMain.pas' {frmTinnMain},
uAbout in 'uAbout.pas' {AboutBox},
uGotoBox in 'uGotoBox.pas' {GotoBox},
uDMSyn in 'uDMSyn.pas' {dmSyn: TDataModule},
ufrmEditor in 'ufrmEditor.pas' {frmEditor},
dlgSearchText in 'dlgSearchText.pas' {TextSearchDialog},
dlgReplaceText in 'dlgReplaceText.pas' {TextReplaceDialog},
ufrmPrintPreview in 'ufrmPrintPreview.pas' {frmPrintPreview},
ufrmSynColor in 'ufrmSynColor.pas' {dlgSynColor},
udlgAppOptions in 'udlgAppOptions.pas' {dlgAppOptions},
AsciiChart in 'AsciiChart.pas' {fmAsciiChart},
ufrmSearchResults in 'ufrmSearchResults.pas' {frmSearchResults},
udlgSearchInFiles in 'udlgSearchInFiles.pas' {dlgSearchInFiles},
BrowseForFolder in 'BrowseForFolder.pas',
uActionMacro in 'uActionMacro.pas',
ufrmProject in 'ufrmProject.pas' {frmProject},
ufrmCodeCompletion in 'ufrmCodeCompletion.pas' {FrmCodeCompletion},
uFrmConnect in 'uFrmConnect.pas' {FrmConnect},
uFrmCompileErrors in 'uFrmCompileErrors.pas' {FrmCompileErrors},
uPLSQLLExer in 'uPLSQLLExer.pas',
uFormExternalTools in 'uFormExternalTools.pas' {FormExternalTools},
utypese in 'utypese.pas',
uQueryGrid in 'uQueryGrid.pas' {FrmQueryGrid},
uFrmJumpProc in 'uFrmJumpProc.pas' {JumpProc},
VDMUnit,
uPLSQLRefactor in 'uPLSQLRefactor.pas',
ufrmRefactorVariableRename in 'ufrmRefactorVariableRename.pas' {FormVariableRefactoringChoice},
uFrmJumpObj in 'uFrmJumpObj.pas' {FrmJumpObj};
{$R *.RES}
Var
Previous: HWnd;
{This code, to allow file association and open doubleclicked file in the running
instance of app was written by Andrius Adamonis
and I tweaked it to work for me}
Function EnumWindowsCallback(Handle: HWnd; Param: LParam): Boolean; Stdcall;
Function IsMyClass: Boolean;
Var
ClassName: Array[0..30] Of Char;
Begin
GetClassName(Handle, ClassName, 30);
Result := (StrIComp(ClassName, 'TfrmTinnMain') = 0) And
(SendMessage(Handle, WM_FINDINSTANCE, 0, 0) = MyUniqueConst);
End;
var
vCurrVirtual : BOOL;
vMyClass : boolean;
vOwnerHWND : HWND;
Begin
vMyClass:=IsMyClass;
if vMyClass then
begin
vOwnerHWND:=GetWindow(Handle, GW_OWNER );
vCurrVirtual:=IsOnCurrentDesktop(vOwnerHWND);//sprawdza czy okno na aktualnym wirtualnym dekstopie https://stackoverflow.com/questions/41803962/using-ivirtualdesktopmanager-in-delphi
end;
Result := Not (vMyClass and vCurrVirtual); { needs True to continue }
If Not Result Then Previous := Handle;
End;
procedure FillFileList(FileList : TStringList);
var
i : integer;
intPos : integer;
handle: THandle;
intPos1, intPos2 : integer;
curFile: WIN32_FIND_DATA;
Path : string;
begin
for i := 1 to ParamCount do // Loop through all the parameters and build a file list
begin
intPos := pos('*', ParamStr(i));
intPos1 := pos('/', ParamStr(i));
intPos2 := pos('@', ParamStr(i));
if (intPos1>0) and (intPos2>0) then begin
FileList.Add(ParamStr(i));
end else if intPos > 0 then // Do multi file globbing
begin
Path := ExtractFilePath(ExpandFileName(ParamStr(i)));
handle := FindFirstFile(PChar(ParamStr(i)), curFile);
if FileExists(Path + curFile.cFilename) then
FileList.Add('"' + Path + curFile.cFilename + '"');
while FindNextFile(Handle, curFile) do
begin
if FileExists(Path + curFile.cFilename) then
FileList.Add('"' + Path + curFile.cFilename + '"');
end;
end // End globbing
else
begin // Do single file open
if FileExists(ParamStr(i)) then // Check for file
begin
if (i < ParamCount) then // Check for line number
intPos := pos('ln=',ParamStr(i+1))
else
intPos := -1;
if (intPos > 0) then
begin
FileList.Add('"' + ExpandFileName(ParamStr(i)) + '"' + ',' + Copy(ParamStr(i+1), intPos + 3, length(ParamStr(i+1))));
end
else
FileList.Add('"' + ExpandFileName(ParamStr(i)) + '"');
end
else // Create a new file
begin
if ParamStr(i)<>'-n' then begin
// Check for the line request
intPos := pos('ln=',ParamStr(i));
if (intPos = 0) then
begin
Path := ExtractFilePath(ExpandFileName(ParamStr(i)));
// if the path isn't already in the file name, add it
if pos(Path, ParamStr(i)) = 0 then
FileList.Add('"' + Path + ParamStr(i) + '"')
else
FileList.Add('"' + ParamStr(i) + '"');
end;
end;
end;
end; // End single file open
end; // End param loop
end;
Var
Atom: TAtom;
FileList : TStringList;
i : integer;
LineNumberJump : integer;
tmpInfo : TStringList;
vSwitch : String;
begin
if ParamCount>0 then
vSwitch:=ParamStr(1);
FileList := TStringList.create;
Previous := 0;
EnumWindows(@EnumWindowsCallback, 0);
If (Previous <> 0) then
begin
if (vSwitch<>'-n') or (ID_NO=Application.MessageBox('Would you like to open a new instance of Tinn?',
'Tinn - Running Instance Found',MB_YESNO+MB_ICONQUESTION+MB_DEFBUTTON2)) then
Begin
SetForegroundWindow(Previous);
PostMessage(Previous, WM_RESTOREAPP, 0, 0);
If ParamCount > 0 Then
Begin
{Path := ExtractFilePath(ExpandFileName(ParamStr(1)));
Atom := GlobalAddAtom(PChar(Path + ParamStr(1)));
SendMessage(Previous, WM_OPENEDITOR, Atom, 0);
GlobalDeleteAtom(Atom);}
FillFileList(FileList);
if (FileList.Count > 0) then
begin
for i := 0 to FileList.Count - 1 do
begin
Atom := GlobalAddAtom(PChar(FileList.Strings[i]));
SendMessage(Previous, WM_OPENEDITOR, Atom, 0);
GlobalDeleteAtom(Atom);
end;
end;
End;
Exit;
End;
end;
Application.Initialize;
Application.Title := 'Tinn';
Application.CreateForm(TdmSyn, dmSyn);
if (ParamCount > 0) then
begin
FillFileList(FileList);
end;
if FileList.Count > 0 then
dmSyn.boolLoadedFileFromStartUp := true;
Application.CreateForm(TfrmTinnMain, frmTinnMain);
Application.CreateForm(TfrmPrintPreview, frmPrintPreview);
if (dmSyn.boolLoadedFileFromStartUp) then
begin
for i := 0 to FileList.Count - 1 do
begin
tmpInfo := TStringList.create;
tmpInfo.CommaText := FileList.Strings[i];
if (tmpInfo.Count = 2) then
begin
LineNumberJump := StrToIntDef(tmpInfo.Strings[1], 0);
frmTinnMain.OpenFileIntoTinn(tmpInfo.Strings[0], LineNumberJump);
end
else
frmTinnMain.OpenFileIntoTinn(tmpInfo.Strings[0]);
end;
end;
FileList.free;
Application.Run;
end.