source: trunk/StudioCommon/ULDStudioAPI.pas

Last change on this file was 15, checked in by chronos, 12 years ago
  • Added: Registration of new file templates for modules.
  • Added: Program stores last opened file list in registry.
File size: 6.2 KB
Line 
1unit ULDStudioAPI;
2
3{$mode delphi}{$H+}
4
5interface
6
7uses
8 Classes, SysUtils, UModularSystem, ActnList, Menus, Forms, USource,
9 SpecializedList, URegistry;
10
11type
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
88procedure Register;
89
90
91implementation
92
93procedure Register;
94begin
95 RegisterComponents('LibreDevelop', [TLDStudioAPI]);
96end;
97
98{ TLDStudioAPI }
99
100constructor TLDStudioAPI.Create;
101begin
102end;
103
104destructor TLDStudioAPI.Destroy;
105begin
106 inherited Destroy;
107end;
108
109procedure TLDStudioAPI.OpenFile(FileName: string);
110begin
111 if Assigned(FOnOpenFile) then
112 FOnOpenFile(FileName);
113end;
114
115procedure TLDStudioAPI.RegisterFileType(FileType: TSourceType);
116begin
117 if Assigned(FOnRegisterFileType) then
118 FOnRegisterFileType(FileType);
119end;
120
121procedure TLDStudioAPI.UnregisterFileType(FileType: TSourceType);
122begin
123 if Assigned(FOnUnregisterFileType) then
124 FOnUnregisterFileType(FileType);
125end;
126
127procedure TLDStudioAPI.RegisterFileTemplate(Template: TFileTemplate);
128begin
129 if Assigned(FOnRegisterFileTemplate) then
130 FOnRegisterFileTemplate(Template);
131end;
132
133procedure TLDStudioAPI.UnregisterFileTemplate(Template: TFileTemplate);
134begin
135 if Assigned(FOnUnregisterFileTemplate) then
136 FOnUnregisterFileTemplate(Template);
137end;
138
139procedure TLDStudioAPI.RegisterForm(Form: TForm);
140begin
141 if Assigned(FOnRegisterForm) then
142 FOnRegisterForm(Form);
143end;
144
145procedure TLDStudioAPI.UnregisterForm(Form: TForm);
146begin
147 if Assigned(FOnUnregisterForm) then
148 FOnUnregisterForm(Form);
149end;
150
151procedure TLDStudioAPI.RegisterAction(Action: TAction);
152begin
153 if Assigned(FOnRegisterAction) then
154 FOnRegisterAction(Action);
155end;
156
157procedure TLDStudioAPI.UnregisterAction(Action: TAction);
158begin
159 if Assigned(FOnUnregisterAction) then
160 FOnUnregisterAction(Action);
161end;
162
163procedure TLDStudioAPI.RegisterMainMenuItem(MenuItem: TMenuItem;
164 ParentItem: TMenuItem; Index: Integer);
165begin
166 if Assigned(FOnRegisterMainMenuItem) then
167 FOnRegisterMainMenuItem(MenuItem, ParentItem, Index);
168end;
169
170procedure TLDStudioAPI.UnregisterMainMenuItem(MenuItem: TMenuItem);
171begin
172 if Assigned(FOnUnregisterMainMenuItem) then
173 FOnUnregisterMainMenuItem(MenuItem);
174end;
175
176procedure TLDStudioAPI.DockForm(Form: TForm; Target: TDockTarget);
177begin
178 if Assigned(FOnDockForm) then
179 FOnDockForm(Form, Target);
180end;
181
182function TLDStudioAPI.GetRegistryContext: TRegistryContext;
183begin
184 if Assigned(FOnGetRegistryContext) then
185 Result := FOnGetRegistryContext();
186end;
187
188end.
189
Note: See TracBrowser for help on using the repository browser.