-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathamScript.Editor.API.pas
More file actions
323 lines (263 loc) · 9.68 KB
/
amScript.Editor.API.pas
File metadata and controls
323 lines (263 loc) · 9.68 KB
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
unit amScript.Editor.API;
interface
uses
System.Classes,
System.SysUtils,
System.Types,
Vcl.Controls,
Vcl.Menus,
Vcl.ImgList,
dwsSymbolDictionary,
dwsSuggestions,
amScript.Provider.API;
// -----------------------------------------------------------------------------
//
// Code completion stuff
//
// -----------------------------------------------------------------------------
const
SuggestionCategoryNames: array[TdwsSuggestionCategory] of string = (
'Unknown',
'Unit',
'Type',
'Class',
'Record',
'Interface',
'Delegate',
'Function',
'Procedure',
'Method',
'Constructor',
'Destructor',
'Property',
'Enum',
'Element',
'Parameter',
'Field',
'Variable',
'Const',
'Reserved',
'Special'
);
SuggestionCategoryShortNames: array[TdwsSuggestionCategory] of string = (
'unknown',
'unit',
'type',
'class',
'record',
'interface',
'delegate',
'function',
'procedure',
'method',
'constructor',
'destructor',
'property',
'enum',
'element',
'param',
'field',
'var',
'const',
'reserved',
'special'
);
// -----------------------------------------------------------------------------
//
// IScriptEditor
//
// -----------------------------------------------------------------------------
type
IScriptEditor = interface;
TScriptEditorNotification = (
seNotifyInitialize,
seNotifyFinalize,
seNotifyActivate,
seNotifyDeactivate,
seNotifyClose,
seNotifySaving,
seNotifySaved,
seNotifyChanged
);
IScriptEditorNotification = interface
['{681FCB76-C436-4CBE-89DB-0A1A1F425595}']
procedure ScriptEditorNotification(const AEditor: IScriptEditor; ANotification: TScriptEditorNotification);
end;
TScriptEditorAction = (
seActionGotoLineNumber,
seActionOpenFileUnderCursor,
seActionToggleDeclImpl,
seActionRepeatSearch,
seActionToggleBreakPoint,
seActionAutoCompletionPropose,
seActionContextHelp,
seActionSelectNextTab,
seActionSelectPrevTab
);
IScriptEditorActionHandler = interface
['{52730461-FD76-4DB3-9217-764DAF7C6489}']
function EditorActionHandler(const AEditor: IScriptEditor; AAction: TScriptEditorAction): boolean;
end;
IScriptEditorInternal = interface
['{80772E3F-7F74-4088-885B-284ACA0D02D7}']
procedure Initialize(AImages: TCustomImageList);
procedure Finalize;
end;
TBufferPos = record
Line: integer;
Column: integer;
class operator Equal(const a, b: TBufferPos): Boolean;
class operator Implicit(const a: TBufferPos): TPoint;
end;
TSearchReplaceOptions = set of (srRegEx, srMatchCase, srWholeWord, srBackwards, srEntireScope, srSelectedOnly, srReplace, srReplaceAll, srPrompt);
TScriptEditorHostNotification = (
ehNotifyCompiled,
ehNotifyResetDebugState,
ehNotifyDpiChanged,
ehNotifyInvalidate
);
IScriptEditor = interface
['{4CAE41F8-188A-420C-AC60-48E7699DE047}']
procedure Subscribe(const ASubscriber: IScriptEditorNotification);
procedure Unsubscribe(const ASubscriber: IScriptEditorNotification);
procedure HostNotification(Notification: TScriptEditorHostNotification);
procedure EditorActivated;
procedure EditorDeactivated;
procedure InvalidateLine(ALine: integer = -1);
function _SaveAs: boolean;
function Save: boolean;
function CloseQuery: boolean;
procedure LoadFromFile(const AFilename: string);
procedure LoadFromStream(Stream: TStream);
procedure LoadFromString(const AScript: string);
function SaveToStream(Stream: TStream): boolean;
procedure GotoLine(ALine: Integer; ACol: Integer = 1; MoveCurrent: boolean = True);
function WordStart(const BufferPos: TBufferPos): TBufferPos;
function WordAt(const BufferPos: TBufferPos): string;
procedure MarkModified(Line: integer = -1);
procedure Undo;
function CanUndo: boolean;
function HasSelection: boolean;
procedure SelectAll;
function GetSelectedText: string;
procedure SetSelectedText(const Value: string);
property SelectedText: string read GetSelectedText write SetSelectedText;
function SearchReplace(const ASearchText, AReplaceText: string; const AOptions: TSearchReplaceOptions): integer;
procedure CopyToClipboard;
procedure CutToClipboard;
procedure PasteFromClipboard;
function CanPaste: boolean;
function GetCaretPos: TBufferPos;
procedure SetCaretPos(const Value: TBufferPos);
property CaretPos: TBufferPos read GetCaretPos write SetCaretPos;
function GetBlockBegin: TBufferPos;
procedure SetBlockBegin(const Value: TBufferPos);
property BlockBegin: TBufferPos read GetBlockBegin write SetBlockBegin;
function GetBlockEnd: TBufferPos;
procedure SetBlockEnd(const Value: TBufferPos);
property BlockEnd: TBufferPos read GetBlockEnd write SetBlockEnd;
function GetLines: TStrings;
property Lines: TStrings read GetLines;
procedure FindDeclaration(const ABufferPos: TBufferPos; ASymbolUsage: TSymbolUsage);
function GetHasProvider: boolean;
property HasProvider: boolean read GetHasProvider;
function GetScriptProvider: IScriptProvider;
procedure SetScriptProvider(const Value: IScriptProvider);
property ScriptProvider: IScriptProvider read GetScriptProvider write SetScriptProvider;
function GetScript: string;
procedure SetScript(const Value: string);
property Script: string read GetScript write SetScript;
function GetCanClose: boolean;
property CanClose: boolean read GetCanClose;
function GetCaption: string;
procedure SetCaption(const Value: string);
property Caption: string read GetCaption write SetCaption;
function GetUnitName: string;
property UnitName: string read GetUnitName;
function InternalUnitName: string;
function GetFilename: TFileName;
procedure SetFileName(const Value: TFileName);
property FileName: TFileName read GetFilename write SetFileName;
function GetInsertMode: boolean;
procedure SetInsertMode(const Value: boolean);
property InsertMode: boolean read GetInsertMode write SetInsertMode;
function GetModified: boolean;
property Modified: boolean read GetModified;
procedure ClearModified;
function GetIsReadOnly: Boolean;
procedure SetIsReadOnly(const Value: Boolean);
property IsReadOnly: Boolean read GetIsReadOnly write SetIsReadOnly;
end;
// -----------------------------------------------------------------------------
//
// IScriptEditorContainer
//
// -----------------------------------------------------------------------------
// Facilitates "communication" from the editor to the container control.
// Specifically it allows the editor to embed itself within the container
// control and to set the caption of the container control.
// The object is owned, via reference counting, by the editor.
// -----------------------------------------------------------------------------
// The IScriptEditorContainer object is created by the ScriptEditorFactory.
// -----------------------------------------------------------------------------
type
IScriptEditorContainer = interface
['{4010092B-5B02-4966-984A-57F8A3C991C1}']
// SetCaption is called by the editor to update the caption of the container
// (e.g. a tab sheet).
procedure SetCaption(const ACaption: string);
// EmbedEditorControl is called by the editor to embed the editor control
// within the container control.
procedure EmbedEditorControl(AControl: TControl);
end;
// -----------------------------------------------------------------------------
//
// IScriptEditorHost
//
// -----------------------------------------------------------------------------
type
IScriptEditorHost = interface
['{AEBC9E98-DFDD-432C-93E1-05579594520A}']
function CreateEditor(const AName: string; FileMustExist: boolean; const CurrentScriptProvider: IScriptProvider): Boolean; overload;
// function CreateEditor(const ScriptProvider: IScriptProvider = nil): IScriptEditor; overload;
function GetMainUnit: IScriptEditor;
procedure SetMainUnit(const Value: IScriptEditor);
property MainUnit: IScriptEditor read GetMainUnit write SetMainUnit;
function GetMainUnitName: string;
property MainUnitName: string read GetMainUnitName;
function GetActiveEditor: IScriptEditor;
procedure SetActiveEditor(const Editor: IScriptEditor);
property ActiveEditor: IScriptEditor read GetActiveEditor write SetActiveEditor;
function GetEditorPagePopupMenu: TPopupMenu;
function PromptSaveScript(var Filename: string; const Foldername: string = ''): boolean;
function DpiScale(Value: Integer): Integer;
end;
type
TScriptDebuggerEditorFactory = function(const AEditorHost: IScriptEditorHost; AContainerControl: TWinControl): IScriptEditor;
ScriptEditorFactory = record
class procedure RegisterFactory(Factory: TScriptDebuggerEditorFactory); static;
class function CreateEditor(const AEditorHost: IScriptEditorHost; AContainerControl: TWinControl): IScriptEditor; static;
end;
implementation
var
FEditorFactory: TScriptDebuggerEditorFactory;
class procedure ScriptEditorFactory.RegisterFactory(Factory: TScriptDebuggerEditorFactory);
begin
FEditorFactory := Factory;
end;
class function ScriptEditorFactory.CreateEditor(const AEditorHost: IScriptEditorHost; AContainerControl: TWinControl): IScriptEditor;
begin
Assert(Assigned(FEditorFactory));
Result := FEditorFactory(AEditorHost, AContainerControl);
end;
{ TBufferPos }
class operator TBufferPos.Equal(const a, b: TBufferPos): Boolean;
begin
Result := (a.Line = b.Line) and (a.Column = b.Column);
end;
class operator TBufferPos.Implicit(const a: TBufferPos): TPoint;
begin
Result.X := a.Column;
Result.Y := a.Line;
end;
end.