-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathSynMacroRecorder_TLB.pas
339 lines (298 loc) · 9.42 KB
/
SynMacroRecorder_TLB.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
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
unit SynMacroRecorder_TLB;
{$WARN SYMBOL_PLATFORM OFF}
interface
uses
Windows, Classes, SysUtils, ActiveX, ComObj, StdVcl, binary_TLB, UMacroInput;
type
{ Process editor related commands and routines }
TSynMacroHandler = class(TAutoObject, ISynMacroHandler)
private
fMacroRecorder, fScriptControl, fEditor: TObject;
fUpdateCallback: UnicodeString;
protected
procedure ExecuteCommand(const ACommand, AData: WideString; ACount: Integer); safecall;
procedure Prompt(const ATitle, APrompt, AUpdateCallback, AConfirmCallback: WideString); safecall;
function Get_CaretX: Integer; safecall;
function Get_CaretY: Integer; safecall;
function Get_CurrText: WideString; safecall;
procedure Set_CaretX(Value: Integer); safecall;
procedure Set_CaretY(Value: Integer); safecall;
procedure Set_CurrText(const Value: WideString); safecall;
procedure SetCaretAndSelection(ACaretX, ACaretY, AStartX, AStartY, AEndX, AEndY: Integer); safecall;
function Get_MacroDir: WideString; safecall;
function Get_CurrChar: WideString; safecall;
function Get_CurrWord: WideString; safecall;
function Get_HasSelection: WordBool; safecall;
procedure Set_CurrChar(const Value: WideString); safecall;
procedure Set_CurrWord(const Value: WideString); safecall;
function Get_BlockBeginX: Integer; safecall;
function Get_BlockBeginY: Integer; safecall;
function Get_BlockEndX: Integer; safecall;
function Get_BlockEndY: Integer; safecall;
procedure Set_BlockBeginX(Value: Integer); safecall;
procedure Set_BlockBeginY(Value: Integer); safecall;
procedure Set_BlockEndX(Value: Integer); safecall;
procedure Set_BlockEndY(Value: Integer); safecall;
function GetLine(ALine: Integer): WideString; safecall;
function Get_TabSize: Integer; safecall;
function Get_WordBeginX: Integer; safecall;
function Get_WordEndX: Integer; safecall;
procedure Set_TabSize(Value: Integer); safecall;
function Get_LineCount: Integer; safecall;
public
function PromptUpdated(const Response: WideString): WideString;
property MacroRecorder: TObject read fMacroRecorder write fMacroRecorder;
property ScriptControl: TObject read fScriptControl write fScriptControl;
property Editor: TObject read fEditor write fEditor;
end;
implementation
uses
ComServ, Controls, Variants, aw_SCtrl, SynMacroRecorder, SynEditTypes,
SynEditKeyCmds, SynEdit;
{ TSynMacroHandler }
// -----------------------------------------------------------------------------
procedure TSynMacroHandler.ExecuteCommand(const ACommand, AData: WideString;
ACount: Integer);
var
I, J, Command: Integer;
NewBufferCoord: TBufferCoord;
begin
Command := SynEditKeyCmds.ConvertCodeStringToCommand(ACommand);
for J := 0 to Pred(ACount) do
begin
if Command >= ecUserCommandFirst then
(fMacroRecorder as TSynMacroRecorder).ProcessUserCommand(Command, AData)
else case Command of
ecGotoXY, ecSelGotoXY, ecOffsetCaret, ecSelOffsetCaret:
begin
I := Pos(',', AData);
if I > 0 then
begin
with NewBufferCoord do
begin
Char := StrToIntDef(Trim(Copy(AData, 1, Pred(I))), 0);
Line := StrToIntDef(Trim(Copy(AData, Succ(I), MaxInt)), 0);
end;
(fEditor as TSynEdit).CommandProcessor(Command, #0, @NewBufferCoord);
end
else
(fEditor as TSynEdit).CommandProcessor(ecNone, #0, nil);
end;
ecChar:
if Length(AData) > 0 then
(fEditor as TSynEdit).CommandProcessor(Command, AData[1], nil)
else
(fEditor as TSynEdit).CommandProcessor(ecNone, #0, nil);
ecString:
for I := 1 to Length(AData) do
(fEditor as TSynEdit).CommandProcessor(ecChar, AData[I], nil);
else
(fEditor as TSynEdit).CommandProcessor(Command, #0, nil);
end;
end;
end;
procedure TSynMacroHandler.Prompt(const ATitle, APrompt, AUpdateCallback, AConfirmCallback: WideString);
var
fPrompt: TFrmMacroInput;
begin
fPrompt := TFrmMacroInput.Create({MainForm}nil);
try
with fPrompt do
begin
Caption := ATitle;
lblPrompt.Caption := APrompt;
MacroHandler := Self;
fUpdateCallback := AUpdateCallback;
ShowModal;
if ModalResult = mrOk then
(fScriptControl as TawScriptControl).CallFunction(AConfirmCallback,
[memoResponse.Text]);
end;
finally
FreeAndnil(fPrompt);
end;
end;
function TSynMacroHandler.PromptUpdated(const Response: WideString): WideString;
begin
try
Result := VarToWideStrDef((fScriptControl as TawScriptControl).CallFunction(fUpdateCallback,
[Response]), EmptyStr);
finally
end;
end;
function TSynMacroHandler.Get_CaretX: Integer;
begin
Result := (fEditor as TSynEdit).CaretX;
end;
function TSynMacroHandler.Get_CaretY: Integer;
begin
Result := (fEditor as TSynEdit).CaretY;
end;
function TSynMacroHandler.Get_CurrText: WideString;
begin
Result := (fEditor as TSynEdit).SelText;
end;
procedure TSynMacroHandler.Set_CaretX(Value: Integer);
begin
(fEditor as TSynEdit).CaretX := Value;
end;
procedure TSynMacroHandler.Set_CaretY(Value: Integer);
begin
(fEditor as TSynEdit).CaretY := Value;
end;
procedure TSynMacroHandler.Set_CurrText(const Value: WideString);
begin
(fEditor as TSynEdit).SelText := Value;
end;
procedure TSynMacroHandler.SetCaretAndSelection(ACaretX, ACaretY, AStartX,
AStartY, AEndX, AEndY: Integer);
begin
(fEditor as TSynEdit).SetCaretAndSelection(BufferCoord(ACaretX, ACaretY),
BufferCoord(AStartX, AStartY), BufferCoord(AEndX, AEndY));
end;
function TSynMacroHandler.Get_MacroDir: WideString;
begin
Result := IncludeTrailingPathDelimiter(ExtractFilePath((fMacroRecorder as
TCustomSynMacroRecorder).FileName));
end;
function TSynMacroHandler.Get_CurrChar: WideString;
var
Editor: TSynEdit;
begin
Editor := (fEditor as TSynEdit);
Result := Editor.GetCharAtRowCol(Editor.CaretXY);
end;
function TSynMacroHandler.Get_CurrWord: WideString;
var
Editor: TSynEdit;
begin
Editor := (fEditor as TSynEdit);
Result := Editor.GetWordAtRowCol(Editor.CaretXY);
end;
function TSynMacroHandler.Get_HasSelection: WordBool;
var
Editor: TSynEdit;
begin
Editor := (fEditor as TSynEdit);
Result := Editor.SelAvail;
end;
procedure TSynMacroHandler.Set_CurrChar(const Value: WideString);
var
Editor: TSynEdit;
begin
Editor := (fEditor as TSynEdit);
Editor.SetCharAtRowCol(Editor.CaretXY, Value[1]);
end;
procedure TSynMacroHandler.Set_CurrWord(const Value: WideString);
var
Editor: TSynEdit;
begin
Editor := (fEditor as TSynEdit);
Editor.SetWordAtRowCol(Editor.CaretXY, Value);
end;
function TSynMacroHandler.Get_BlockBeginX: Integer;
var
Editor: TSynEdit;
begin
Editor := (fEditor as TSynEdit);
Result := Editor.BlockBegin.Char;
end;
function TSynMacroHandler.Get_BlockBeginY: Integer;
var
Editor: TSynEdit;
begin
Editor := (fEditor as TSynEdit);
Result := Editor.BlockBegin.Line;
end;
function TSynMacroHandler.Get_BlockEndX: Integer;
var
Editor: TSynEdit;
begin
Editor := (fEditor as TSynEdit);
Result := Editor.BlockEnd.Char;
end;
function TSynMacroHandler.Get_BlockEndY: Integer;
var
Editor: TSynEdit;
begin
Editor := (fEditor as TSynEdit);
Result := Editor.BlockEnd.Line;
end;
procedure TSynMacroHandler.Set_BlockBeginX(Value: Integer);
var
Editor: TSynEdit;
begin
Editor := (fEditor as TSynEdit);
Editor.BlockBegin := BufferCoord(Value, Editor.BlockBegin.Line);
end;
procedure TSynMacroHandler.Set_BlockBeginY(Value: Integer);
var
Editor: TSynEdit;
begin
Editor := (fEditor as TSynEdit);
Editor.BlockBegin := BufferCoord(Editor.BlockBegin.Char, Value);
end;
procedure TSynMacroHandler.Set_BlockEndX(Value: Integer);
var
Editor: TSynEdit;
begin
Editor := (fEditor as TSynEdit);
Editor.BlockEnd := BufferCoord(Value, Editor.BlockEnd.Line);
end;
procedure TSynMacroHandler.Set_BlockEndY(Value: Integer);
var
Editor: TSynEdit;
begin
Editor := (fEditor as TSynEdit);
Editor.BlockEnd := BufferCoord(Editor.BlockEnd.Char, Value);
end;
function TSynMacroHandler.GetLine(ALine: Integer): WideString;
var
Editor: TSynEdit;
begin
{
Editor := (fEditor as TSynEdit);
Result := EmptyStr;
if (ALine > 0) and (ALine <= Editor.Lines.Count) then
Result := Editor.Lines[Pred(ALine)];
}
end;
function TSynMacroHandler.Get_TabSize: Integer;
var
Editor: TSynEdit;
begin
Editor := (fEditor as TSynEdit);
Result := Editor.TabWidth;
end;
function TSynMacroHandler.Get_WordBeginX: Integer;
var
Editor: TSynEdit;
begin
Editor := (fEditor as TSynEdit);
Result := Editor.WordStart.Char;
end;
function TSynMacroHandler.Get_WordEndX: Integer;
var
Editor: TSynEdit;
begin
Editor := (fEditor as TSynEdit);
Result := Editor.WordEnd.Char;
end;
procedure TSynMacroHandler.Set_TabSize(Value: Integer);
var
Editor: TSynEdit;
begin
Editor := (fEditor as TSynEdit);
Editor.TabWidth := Value;
end;
function TSynMacroHandler.Get_LineCount: Integer;
var
Editor: TSynEdit;
begin
Editor := (fEditor as TSynEdit);
Result := Editor.Lines.Count;
end;
//initialization
// TAutoObjectFactory.Create(ComServer, TSynMacroHandler, Class_SynMacroHandler,
// ciMultiInstance, tmApartment);
end.