-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathamScript.Host.API.pas
More file actions
250 lines (201 loc) · 9.44 KB
/
amScript.Host.API.pas
File metadata and controls
250 lines (201 loc) · 9.44 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
unit amScript.Host.API;
(*
* Copyright © 2012 Anders Melander
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*)
interface
// -----------------------------------------------------------------------------
//
// This unit contains the interfaces that should be implemented by the host
// application in order to provide integration to the script debugger.
//
// -----------------------------------------------------------------------------
uses
SysUtils,
Classes,
amScript.Provider.API;
const
sScriptAttachmentFilenamePrefix = '';//'\';
var
sScriptHostConditionalDefine: string = ''; // TODO : Move to ScriptSettings
// -----------------------------------------------------------------------------
//
// IScriptHostAlertWindow
//
// -----------------------------------------------------------------------------
// Used by the debugger/editor to display alert messages.
// See ScriptHostAlertWindow.pas for a sample implementation.
// -----------------------------------------------------------------------------
type
IScriptHostAlertWindow = interface;
IScriptHostAlertEventSink = interface
['{C50A44A9-5373-417D-B92B-64E2648A9171}']
procedure AlertClicked(const AlertWindow: IScriptHostAlertWindow);
procedure AlertClosed(const AlertWindow: IScriptHostAlertWindow);
end;
IScriptHostAlertWindow = interface
['{735EB7C9-3A3C-4DD3-A32E-090CCA1CF3A0}']
procedure SetEventSink(const EventSink: IScriptHostAlertEventSink; Data: pointer);
procedure Close;
function GetData: pointer;
property Data: pointer read GetData;
end;
// -----------------------------------------------------------------------------
//
// IScriptHostApplication
//
// -----------------------------------------------------------------------------
// The application is represented by a single IScriptHostApplication.
// The application can optionally contain one or more documents.
// The ActiveDocument property indicates the currently active document.
// -----------------------------------------------------------------------------
IScriptHostDocument = interface;
IScriptHostApplication = interface
['{15B8D15D-9F31-4916-B2D2-2E8A40C77258}']
procedure Subscribe(const Subscriber: IInterface);
procedure Unsubscribe(const Subscriber: IInterface);
// HasDocuments is True if the host application supprots documents/attachments.
function GetHasDocuments: boolean;
property HasDocuments: boolean read GetHasDocuments;
function GetActiveDocument: IScriptHostDocument;
// ActiveDocument should return nil if application doesn't support documents or no document is active.
property ActiveDocument: IScriptHostDocument read GetActiveDocument;
// AddAlertMessage is called by the debugger to display alert messages.
// At some point this will be moved to a separate interface since it's very seldom used.
function AddAlertMessage(const ACaption, AMessage: string; AImageIndex: integer = -1; ATimeout: integer = -1): IScriptHostAlertWindow;
end;
{$SCOPEDENUMS ON}
TScriptHostApplicationNotification = (notifySubscribe, notifyUnsubscribe, notifyClosing);
{$SCOPEDENUMS OFF}
IScriptHostApplicationNotification = interface
['{A41C2E98-ECAC-468E-ACA0-C7664165CD0E}']
procedure ApplicationNotify(const ScriptHostApplication: IScriptHostApplication; Notification: TScriptHostApplicationNotification);
end;
IScriptHostApplicationCloseNotification = interface
['{7919DA77-3529-4239-8A7D-C0C077ED6119}']
procedure ApplicationCloseQuery(const ScriptHostApplication: IScriptHostApplication; var CanClose: boolean);
end;
// -----------------------------------------------------------------------------
//
// IScriptHostDocument
//
// -----------------------------------------------------------------------------
// An application can contain zero, one or more instances of IScriptHostDocument.
// It is up to the application to decide what the IScriptHostDocument object
// represents. It commonly represents a document or a file.
// -----------------------------------------------------------------------------
IScriptHostFiles = interface;
IScriptHostDocument = interface
['{BC6FB7B2-C02C-4D99-B240-51113E9D8D7A}']
procedure Initialize(const ScriptHostApplication: IScriptHostApplication);
procedure Finalize;
procedure Subscribe(const Subscriber: IInterface);
procedure Unsubscribe(const Subscriber: IInterface);
function GetFilename: string;
property Filename: string read GetFilename;
function GetAllowEdit: boolean;
property AllowEdit: boolean read GetAllowEdit;
function GetFiles: IScriptHostFiles;
property Files: IScriptHostFiles read GetFiles;
// ActiveItem represent a state object within the document.
// It is up to the application to decide what that is.
function GetActiveItem: TObject;
property ActiveItem: TObject read GetActiveItem;
procedure Changed;
end;
{$SCOPEDENUMS ON}
TScriptHostDocumentNotification = (notifySubscribe, notifyUnsubscribe, notifyShutdown);
{$SCOPEDENUMS OFF}
IScriptHostDocumentNotification = interface
['{7D75775F-880A-431E-9BAF-6AE59205E8DA}']
procedure HostDocumentNotify(const Document: IScriptHostDocument; Notification: TScriptHostDocumentNotification);
end;
IScriptHostDocumentCloseNotification = interface
['{522D6959-AA77-4375-B7D1-537EC3D2CBA2}']
procedure HostDocumentCloseQuery(const Document: IScriptHostDocument; var CanClose: boolean);
end;
// -----------------------------------------------------------------------------
//
// IScriptHostFile
//
// -----------------------------------------------------------------------------
// A document can contain files - also called attachments.
// These files can be made available to the script file system, both at run and
// compile time, through the IScriptHostFile and IScriptHostFiles interfaces.
// -----------------------------------------------------------------------------
IScriptHostFile = interface
['{708395D4-F483-49D1-9E25-A0113D334127}']
procedure Subscribe(const Subscriber: IInterface);
procedure Unsubscribe(const Subscriber: IInterface);
procedure LoadFromStream(AStream: TStream);
procedure SaveToStream(AStream: TStream);
// Wrap the attachment in a script provider
function CreateScriptProvider: IScriptProvider;
// Return the internal stream if the object has one.
// Return nil if it hasn't. The stream must be both readable and writable.
// Can be used to avoid the overhead of creating a temporary memory stream which is often
// necessary when LoadFromStream/SaveToStream is used.
function GetStream: TStream;
property Stream: TStream read GetStream;
function GetFileSize: Int64;
property FileSize: Int64 read GetFileSize;
function GetName: string;
property Name: string read GetName;
end;
{$SCOPEDENUMS ON}
TScriptHostFileNotification = (notifyFree);
{$SCOPEDENUMS OFF}
IScriptHostFileNotification = interface
['{7D75775F-880A-431E-9BAF-6AE59205E8DA}']
procedure HostDocumentNotify(const ScriptHostFile: IScriptHostFile; Notification: TScriptHostFileNotification);
end;
IScriptHostFiles = interface
['{93246E6B-0B4B-4D12-A509-071539AECB85}']
function TryGetFile(const Filename: string; out ScriptHostFile: IScriptHostFile): boolean;
function Add(const Name, Filename: string): IScriptHostFile;
procedure Remove(const AFile: IScriptHostFile);
end;
// -----------------------------------------------------------------------------
//
// ScriptHostApplication
//
// -----------------------------------------------------------------------------
// Reference to the script host application.
// Must be set by the host application before the debugger can be used.
// -----------------------------------------------------------------------------
function ScriptHostApplication: IScriptHostApplication;
procedure RegisterScriptHostApplication(const AScriptHostApplication: IScriptHostApplication);
// Set ScriptDebuggerIsApplication=True if the debugger should become the application main form.
// Requires that RegisterScriptHostApplication() has not been called and that
// Application.MainForm=nil when the debugger is invoked.
var
ScriptDebuggerIsApplication: boolean = False;
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
implementation
// -----------------------------------------------------------------------------
//
// ScriptHostApplication
//
// -----------------------------------------------------------------------------
var
FScriptHostApplication: IScriptHostApplication = nil;
procedure RegisterScriptHostApplication(const AScriptHostApplication: IScriptHostApplication);
begin
FScriptHostApplication := AScriptHostApplication;
end;
function ScriptHostApplication: IScriptHostApplication;
begin
Result := FScriptHostApplication;
end;
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
initialization
finalization
FScriptHostApplication := nil;
end.