-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFarAPI.pas
265 lines (236 loc) · 7.69 KB
/
FarAPI.pas
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
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
unit FarAPI;
Interface
{$I PRJDefines.inc}
uses
Plugin,
PluginLng,
SysUtils,
Windows;
type
TInitDialogItem = packed record
ItemType: integer;
X1, Y1, X2, Y2: integer;
Focus: integer;
Selected: Bool;
{
Param: record case integer of
0: (Selected: BOOL);
1: (History: PChar);
2: (Mask: PChar);
3: (ListItems: PFarList);
4: (ListPos: integer);
5: (VBuf: PCharInfo);
end;
}
Flags: DWORD;
DefaultButton: BOOL;
Data: record case Integer of
0: (MsgID: DWORD);
1: (Message: PChar);
end;
end;
TInitDialogItemArr = packed array [0..Pred(MaxInt div SizeOf(TInitDialogItem))] of TInitDialogItem;
PInitDialogItemArr = ^TInitDialogItemArr;
function GetPluginPath: String;
procedure SetStartupInfo(var aInfo: TPluginStartupInfo); stdcall;
function GetMsg(aMsgId: TMessageStrings): PChar;
function Message(Flags: DWORD; HelpTopic: PChar;
AItems: array of const; ButtonsNumber: Integer): Integer;
function SaveScreen(X1, Y1, X2, Y2: integer): THandle;
procedure RestoreScreen(hScreen: THandle);
function CmpName(const Pattern: PChar; const FileName: PChar;
SkipPath: BOOL): Bool;
function Control(hPlugin: THandle; Command: integer; Param: pointer): integer;
procedure InitDialogItems(Init: PInitDialogItemArr; Item: PFarDialogItemArray;
ItemsNumber: integer);
function DialogEx(X1, Y1: integer; X2, Y2: integer; HelpTopic: PChar;
Items: PFarDialogItemArray; ItemsNumber: integer;
Reserved: DWORD; Flags: DWORD; DlgProc: TFarApiWindowProc;
Param: integer): integer;
function DefDlgProc(hDlg: THandle; Msg: integer; Param1: integer; Param2: integer): integer;
function SendDlgMessage(hDlg: THandle; Msg: integer; Param1: integer; Param2: integer): integer;
function CheckForEsc: Boolean;
function ConvertNameToReal(const Src: PChar; Dest: PChar; DestSize: Integer): Integer;
{
function GetDirList(const aDir: PChar;
var aPanelItems: PPluginPanelItemArr;
var aItemsNumber: integer): integer;
procedure FreeDirList(const aPanelItems: PPluginPanelItemArr);
}
Implementation
var
PluginStartupInfo: TPluginStartupInfo;
FSF: TFarStandardFunctions;
hConInp: THandle;
function GetPluginPath: String;
{
var
F: TextFile;
}
begin
Result:=ExtractFileDir(StrPas(PChar(@PluginStartupInfo.ModuleName)))+'\';
{
AssignFile(F, 'c:\debug.txt');
Rewrite(F);
Writeln(F, Result);
CloseFile(F);
}
end;
procedure SetStartupInfo(var aInfo: TPluginStartupInfo); stdcall;
var
Size: Integer;
begin
Size:=aInfo.StructSize;
if Size>SizeOf(TPluginStartupInfo) then Size:=SizeOf(TPluginStartupInfo);
Move(aInfo, PluginStartupInfo, Size);
PluginStartupInfo.StructSize:=Size;
Size:=aInfo.FSF^.StructSize;
if Size>SizeOf(TFarStandardFunctions) then Size:=SizeOf(TFarStandardFunctions);
Move(aInfo.FSF^, FSF, Size);
FSF.StructSize:=Size;
PluginStartupInfo.FSF:=@FSF;
end;
function GetMsg(aMsgId: TMessageStrings): PChar;
begin
with PluginStartupInfo do
Result:=GetMsg(ModuleNumber,integer(aMsgId));
end;
function Message(Flags: DWORD; HelpTopic: PChar;
AItems: array of const; ButtonsNumber: Integer): Integer;
var
Items: PPCharArray;
ItemsNumber: Integer;
I: Integer;
begin
ItemsNumber := High(AItems)+1;
GetMem(Items, SizeOf(PChar)*ItemsNumber);
for I := 0 to High(AItems) do
with AItems[I] do
case VType of
vtInteger: Items^[I] := GetMsg(TMessageStrings(VInteger));
vtPChar: Items^[I] := VPChar;
vtAnsiString: Items^[I] := VAnsiString;
else{nil} Items^[I] := ' ';
end;
with PluginStartupInfo do
Result := Message(ModuleNumber,
Flags,
HelpTopic,
Items,
ItemsNumber,
ButtonsNumber);
FreeMem(Items);
end;
function SaveScreen(X1, Y1, X2, Y2: integer): THandle;
begin
Result:=PluginStartupInfo.SaveScreen(X1, Y1, X2, Y2);
end;
procedure RestoreScreen(hScreen: THandle);
begin
PluginStartupInfo.RestoreScreen(hScreen);
end;
function CmpName(const Pattern: PChar; const FileName: PChar;
SkipPath: BOOL): Bool;
begin
Result:=Bool(PluginStartupInfo.CmpName(Pattern, FileName, Integer(SkipPath)));
end;
function Control(hPlugin: THandle; Command: integer; Param: pointer): integer;
begin
Result:=PluginStartupInfo.Control(hPlugin, Command, Param);
end;
procedure InitDialogItems(Init: PInitDialogItemArr; Item: PFarDialogItemArray;
ItemsNumber: integer);
var
i: integer;
begin
for i:=0 to ItemsNumber-1 do
begin
Item^[I].ItemType:=Init^[I].ItemType;
Item^[I].X1:=Init^[I].X1;
Item^[I].Y1:=Init^[I].Y1;
Item^[I].X2:=Init^[I].X2;
Item^[I].Y2:=Init^[I].Y2;
Item^[I].Focus:=Init^[I].Focus;
Item^[I].Param.Selected:=Integer(Init^[I].Selected);
Item^[I].Flags:=Init^[I].Flags;
Item^[I].DefaultButton:=Integer(Init^[I].DefaultButton);
if Init^[I].Data.MsgID<2000 then
StrCopy(Item^[I].Data.Data, GetMsg(TMessageStrings(Init^[I].Data.MsgID)))
else
StrCopy(Item^[I].Data.Data, Init^[I].Data.Message);
end;
end;
function DialogEx(X1, Y1: integer; X2, Y2: integer; HelpTopic: PChar;
Items: PFarDialogItemArray; ItemsNumber: integer;
Reserved: DWORD; Flags: DWORD; DlgProc: TFarApiWindowProc;
Param: integer): integer;
begin
Result:=PluginStartupInfo.DialogEx(PluginStartupInfo.ModuleNumber,
X1, Y1, X2, Y2, HelpTopic,
Items, ItemsNumber, Reserved,
Flags, DlgProc, Param);
end;
function DefDlgProc(hDlg: THandle; Msg: integer; Param1: integer; Param2: integer): integer;
begin
Result:=PluginStartupInfo.DefDlgProc(hDlg, Msg, Param1, Param2);
end;
function SendDlgMessage(hDlg: THandle; Msg: integer; Param1: integer; Param2: integer): integer;
begin
Result:=PluginStartupInfo.SendDlgMessage(hDlg, Msg, Param1, Param2);
end;
function CheckForEsc: Boolean;
var
Rec: TInputRecord;
ReadCount: DWord;
begin
Result:=False;
repeat
PeekConsoleInput(hConInp, rec, 1, ReadCount);
if ReadCount>0 then
begin
ReadConsoleInput(hConInp, rec, 1, ReadCount);
if (Rec.EventType=KEY_EVENT) and
(Rec.Event.KeyEvent.wVirtualKeyCode=VK_ESCAPE) and
(Rec.Event.KeyEvent.bKeyDown) then
Result:=True;
end
until ReadCount=0;
end;
function ConvertNameToReal(const Src: PChar; Dest: PChar; DestSize: Integer): Integer;
begin
Result:=PluginStartupInfo.FSF^.ConvertNameToReal(Src, Dest, DestSize);
end;
(*
bool CheckForEsc(void)
{
bool EC=false;
INPUT_RECORD rec;
static HANDLE hConInp=GetStdHandle(STD_INPUT_HANDLE);
DWORD ReadCount;
while (1)
{
PeekConsoleInput(hConInp,&rec,1,&ReadCount);
if (ReadCount==0) break;
ReadConsoleInput(hConInp,&rec,1,&ReadCount);
if (rec.EventType==KEY_EVENT)
if (rec.Event.KeyEvent.wVirtualKeyCode==VK_ESCAPE &&
rec.Event.KeyEvent.bKeyDown) EC=true;
}
return(EC);
}
*)
{
function GetDirList(const aDir: PChar;
var aPanelItems: PPluginPanelItemArr;
var aItemsNumber: integer): integer;
begin
Result:=PluginStartupInfo.GetDirList(aDir, aPanelItems, aItemsNumber);
end;
procedure FreeDirList(const aPanelItems: PPluginPanelItemArr);
begin
PluginStartupInfo.FreeDirList(aPanelItems);
end;
}
initialization
hConInp:=GetStdHandle(STD_INPUT_HANDLE);
End.