1 | unit ULDStudioAPI;
|
---|
2 |
|
---|
3 | {$mode delphi}{$H+}
|
---|
4 |
|
---|
5 | interface
|
---|
6 |
|
---|
7 | uses
|
---|
8 | Classes, SysUtils, UModularSystem, ActnList, Menus, Forms, USource,
|
---|
9 | SpecializedList, URegistry;
|
---|
10 |
|
---|
11 | type
|
---|
12 | TDockTarget = (dtCenter, dtLeft, dtRight, dtBottom, dtTop);
|
---|
13 | TOpenFileEvent = procedure (FileName: string) of object;
|
---|
14 | TRegisterFileTypeEvent = procedure (FileType: TSourceType) of object;
|
---|
15 | TRegisterFormEvent = procedure (Form: TForm) of object;
|
---|
16 | TRegisterActionEvent = procedure (Action: TAction) of object;
|
---|
17 | TRegisterMainMenuItemEvent = procedure (MenuItem: TMenuItem; ParentItem: TMenuItem;
|
---|
18 | Index: Integer) of object;
|
---|
19 | TUnregisterMainMenuItemEvent = procedure (MenuItem: TMenuItem) of object;
|
---|
20 | TDockFormEvent = procedure (Form: TForm; Target: TDockTarget) of object;
|
---|
21 | TGetRegistryContextEvent = function: TRegistryContext of object;
|
---|
22 | TRegisterFileTemplateEvent = procedure (Template: TFileTemplate) of object;
|
---|
23 |
|
---|
24 | { TLDStudioAPI }
|
---|
25 |
|
---|
26 | TLDStudioAPI = class(TAPI)
|
---|
27 | private
|
---|
28 | FOnDockForm: TDockFormEvent;
|
---|
29 | FOnGetRegistryContext: TGetRegistryContextEvent;
|
---|
30 | FOnOpenFile: TOpenFileEvent;
|
---|
31 | FOnRegisterAction: TRegisterActionEvent;
|
---|
32 | FOnRegisterFileTemplate: TRegisterFileTemplateEvent;
|
---|
33 | FOnRegisterFileType: TRegisterFileTypeEvent;
|
---|
34 | FOnRegisterForm: TRegisterFormEvent;
|
---|
35 | FOnRegisterMainMenuItem: TRegisterMainMenuItemEvent;
|
---|
36 | FOnUnregisterAction: TRegisterActionEvent;
|
---|
37 | FOnUnregisterFileTemplate: TRegisterFileTemplateEvent;
|
---|
38 | FOnUnregisterFileType: TRegisterFileTypeEvent;
|
---|
39 | FOnUnregisterForm: TRegisterFormEvent;
|
---|
40 | FOnUnregisterMainMenuItem: TUnregisterMainMenuItemEvent;
|
---|
41 | public
|
---|
42 | constructor Create;
|
---|
43 | destructor Destroy; override;
|
---|
44 |
|
---|
45 | // API client functions
|
---|
46 | procedure OpenFile(FileName: string);
|
---|
47 | procedure RegisterFileType(FileType: TSourceType);
|
---|
48 | procedure UnregisterFileType(FileType: TSourceType);
|
---|
49 | procedure RegisterFileTemplate(Template: TFileTemplate);
|
---|
50 | procedure UnregisterFileTemplate(Template: TFileTemplate);
|
---|
51 | procedure RegisterForm(Form: TForm);
|
---|
52 | procedure UnregisterForm(Form: TForm);
|
---|
53 | procedure RegisterAction(Action: TAction);
|
---|
54 | procedure UnregisterAction(Action: TAction);
|
---|
55 | procedure RegisterMainMenuItem(MenuItem: TMenuItem; ParentItem: TMenuItem;
|
---|
56 | Index: Integer);
|
---|
57 | procedure UnregisterMainMenuItem(MenuItem: TMenuItem);
|
---|
58 | procedure DockForm(Form: TForm; Target: TDockTarget);
|
---|
59 | function GetRegistryContext: TRegistryContext;
|
---|
60 | published
|
---|
61 | // API handling
|
---|
62 | property OnOpenFile: TOpenFileEvent read FOnOpenFile write FOnOpenFile;
|
---|
63 | property OnRegisterFileType: TRegisterFileTypeEvent
|
---|
64 | read FOnRegisterFileType write FOnRegisterFileType;
|
---|
65 | property OnUnregisterFileType: TRegisterFileTypeEvent
|
---|
66 | read FOnUnregisterFileType write FOnUnregisterFileType;
|
---|
67 | property OnRegisterForm: TRegisterFormEvent
|
---|
68 | read FOnRegisterForm write FOnRegisterForm;
|
---|
69 | property OnUnregisterForm: TRegisterFormEvent
|
---|
70 | read FOnUnregisterForm write FOnUnregisterForm;
|
---|
71 | property OnRegisterAction: TRegisterActionEvent
|
---|
72 | read FOnRegisterAction write FOnRegisterAction;
|
---|
73 | property OnUnregisterAction: TRegisterActionEvent
|
---|
74 | read FOnUnregisterAction write FOnUnregisterAction;
|
---|
75 | property OnRegisterMainMenuItem: TRegisterMainMenuItemEvent
|
---|
76 | read FOnRegisterMainMenuItem write FOnRegisterMainMenuItem;
|
---|
77 | property OnUnregisterMainMenuItem: TUnregisterMainMenuItemEvent
|
---|
78 | read FOnUnregisterMainMenuItem write FOnUnregisterMainMenuItem;
|
---|
79 | property OnDockForm: TDockFormEvent read FOnDockForm write FOnDockForm;
|
---|
80 | property OnGetRegistryContext: TGetRegistryContextEvent
|
---|
81 | read FOnGetRegistryContext write FOnGetRegistryContext;
|
---|
82 | property OnRegisterFileTemplate: TRegisterFileTemplateEvent
|
---|
83 | read FOnRegisterFileTemplate write FOnRegisterFileTemplate;
|
---|
84 | property OnUnregisterFileTemplate: TRegisterFileTemplateEvent
|
---|
85 | read FOnUnregisterFileTemplate write FOnUnregisterFileTemplate;
|
---|
86 | end;
|
---|
87 |
|
---|
88 | procedure Register;
|
---|
89 |
|
---|
90 |
|
---|
91 | implementation
|
---|
92 |
|
---|
93 | procedure Register;
|
---|
94 | begin
|
---|
95 | RegisterComponents('LibreDevelop', [TLDStudioAPI]);
|
---|
96 | end;
|
---|
97 |
|
---|
98 | { TLDStudioAPI }
|
---|
99 |
|
---|
100 | constructor TLDStudioAPI.Create;
|
---|
101 | begin
|
---|
102 | end;
|
---|
103 |
|
---|
104 | destructor TLDStudioAPI.Destroy;
|
---|
105 | begin
|
---|
106 | inherited Destroy;
|
---|
107 | end;
|
---|
108 |
|
---|
109 | procedure TLDStudioAPI.OpenFile(FileName: string);
|
---|
110 | begin
|
---|
111 | if Assigned(FOnOpenFile) then
|
---|
112 | FOnOpenFile(FileName);
|
---|
113 | end;
|
---|
114 |
|
---|
115 | procedure TLDStudioAPI.RegisterFileType(FileType: TSourceType);
|
---|
116 | begin
|
---|
117 | if Assigned(FOnRegisterFileType) then
|
---|
118 | FOnRegisterFileType(FileType);
|
---|
119 | end;
|
---|
120 |
|
---|
121 | procedure TLDStudioAPI.UnregisterFileType(FileType: TSourceType);
|
---|
122 | begin
|
---|
123 | if Assigned(FOnUnregisterFileType) then
|
---|
124 | FOnUnregisterFileType(FileType);
|
---|
125 | end;
|
---|
126 |
|
---|
127 | procedure TLDStudioAPI.RegisterFileTemplate(Template: TFileTemplate);
|
---|
128 | begin
|
---|
129 | if Assigned(FOnRegisterFileTemplate) then
|
---|
130 | FOnRegisterFileTemplate(Template);
|
---|
131 | end;
|
---|
132 |
|
---|
133 | procedure TLDStudioAPI.UnregisterFileTemplate(Template: TFileTemplate);
|
---|
134 | begin
|
---|
135 | if Assigned(FOnUnregisterFileTemplate) then
|
---|
136 | FOnUnregisterFileTemplate(Template);
|
---|
137 | end;
|
---|
138 |
|
---|
139 | procedure TLDStudioAPI.RegisterForm(Form: TForm);
|
---|
140 | begin
|
---|
141 | if Assigned(FOnRegisterForm) then
|
---|
142 | FOnRegisterForm(Form);
|
---|
143 | end;
|
---|
144 |
|
---|
145 | procedure TLDStudioAPI.UnregisterForm(Form: TForm);
|
---|
146 | begin
|
---|
147 | if Assigned(FOnUnregisterForm) then
|
---|
148 | FOnUnregisterForm(Form);
|
---|
149 | end;
|
---|
150 |
|
---|
151 | procedure TLDStudioAPI.RegisterAction(Action: TAction);
|
---|
152 | begin
|
---|
153 | if Assigned(FOnRegisterAction) then
|
---|
154 | FOnRegisterAction(Action);
|
---|
155 | end;
|
---|
156 |
|
---|
157 | procedure TLDStudioAPI.UnregisterAction(Action: TAction);
|
---|
158 | begin
|
---|
159 | if Assigned(FOnUnregisterAction) then
|
---|
160 | FOnUnregisterAction(Action);
|
---|
161 | end;
|
---|
162 |
|
---|
163 | procedure TLDStudioAPI.RegisterMainMenuItem(MenuItem: TMenuItem;
|
---|
164 | ParentItem: TMenuItem; Index: Integer);
|
---|
165 | begin
|
---|
166 | if Assigned(FOnRegisterMainMenuItem) then
|
---|
167 | FOnRegisterMainMenuItem(MenuItem, ParentItem, Index);
|
---|
168 | end;
|
---|
169 |
|
---|
170 | procedure TLDStudioAPI.UnregisterMainMenuItem(MenuItem: TMenuItem);
|
---|
171 | begin
|
---|
172 | if Assigned(FOnUnregisterMainMenuItem) then
|
---|
173 | FOnUnregisterMainMenuItem(MenuItem);
|
---|
174 | end;
|
---|
175 |
|
---|
176 | procedure TLDStudioAPI.DockForm(Form: TForm; Target: TDockTarget);
|
---|
177 | begin
|
---|
178 | if Assigned(FOnDockForm) then
|
---|
179 | FOnDockForm(Form, Target);
|
---|
180 | end;
|
---|
181 |
|
---|
182 | function TLDStudioAPI.GetRegistryContext: TRegistryContext;
|
---|
183 | begin
|
---|
184 | if Assigned(FOnGetRegistryContext) then
|
---|
185 | Result := FOnGetRegistryContext();
|
---|
186 | end;
|
---|
187 |
|
---|
188 | end.
|
---|
189 |
|
---|