forked from marcocantu/cantools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCtwManager.pas
More file actions
261 lines (212 loc) · 5.97 KB
/
Copy pathCtwManager.pas
File metadata and controls
261 lines (212 loc) · 5.97 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
unit CtwManager;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Buttons, ToolsApi, Menus, TypInfo, Contnrs, Registry, ExtCtrls, ComCtrls,
ActnList;
type
TCanWiz = class
public
function MenuText: string; virtual; abstract;
procedure Execute (Sender: TObject); virtual; abstract;
end;
TCantoolsManager = class (TInterfacedObject,
IOTANotifier, IOTAWizard)
private
BaseRegKey: string;
CantoolsMenu: TMenuItem;
FPlugInInfoCode: Integer;
fProductBitmap: HBITMAP;
MessageGroup: IOTAMessageGroup;
procedure AddMenu(CanWiz: TCanWiz);
public
WizardsList: TObjectList;
// specific methods
constructor Create;
destructor Destroy; override;
procedure Add (CanWiz: TCanWiz);
procedure CreateMenu;
procedure AddToAboutBox;
procedure RemoveFromAboutBox;
procedure RefreshMenu;
class procedure ShowSplash;
function ReadSetting (const KeyName: string): string;
procedure WriteSetting (const KeyName, KeyValue: string);
procedure ShowMessage (const strMessage: string);
// event handler
procedure AboutExecute (Sender: TObject);
// IOTANotifier interface
procedure AfterSave;
procedure BeforeSave;
procedure Destroyed;
procedure Modified;
// IOTAWizard interface
function GetIDString: string;
function GetName: string;
function GetState: TWizardState;
procedure Execute;
end;
var
// gobal variable for the wizards manager
CantoolsManager: TCantoolsManager;
procedure Register;
implementation
uses
ImgList;
{$R Objects.res}
procedure Register;
begin
RegisterPackageWizard(CantoolsManager);
end;
procedure TCantoolsManager.AboutExecute(Sender: TObject);
begin
// ShowMessage ('About...');
end;
procedure TCantoolsManager.Add(CanWiz: TCanWiz);
begin
// add to the internal list (accounts for destruction)
WizardsList.Add(CanWiz);
if Assigned (CantoolsMenu) then
AddMenu (CanWiz);
end;
procedure TCantoolsManager.AddMenu(CanWiz: TCanWiz);
begin
// add a menu for the wizard
CantoolsMenu.Add (NewItem (
CanWiz.MenuText, 0, False, True,
CanWiz.Execute, 0, CanWiz.ClassName));
end;
procedure TCantoolsManager.AddToAboutBox;
begin
fProductBitmap := LoadBitmap(HInstance, 'OBJECTS');
FPlugInInfoCode :=
(BorlandIDEServices as IOTAAboutBoxServices).
AddPluginInfo(
'Cantools', 'Marco Cantù''s Wizards Collection', fProductBitmap, False,
'Copyright 2020 www.marcocantu.com', 'Version 10.4');
end;
procedure TCantoolsManager.AfterSave;
begin
end;
procedure TCantoolsManager.BeforeSave;
begin
end;
constructor TCantoolsManager.Create;
begin
inherited Create;
// create the list
WizardsList := TObjectList.Create; // owns objects
// registry
BaseRegKey := (BorlandIDEServices as IOTAServices).
GetBaseRegistryKey + '\CanTools';
CreateMenu;
AddToAboutBox;
end;
procedure TCantoolsManager.CreateMenu;
var
DMenu: TMainMenu;
I: Integer;
begin
// create a secondary menu for the set of wizards
DMenu := (BorlandIDEServices as INTAServices).MainMenu;
if not Assigned (CantoolsMenu) then
begin
CantoolsMenu := NewItem ('Cantools', 0, False,
True, nil, 0, 'Cantoolsmenu');
// add items for the current wizards
for I := 0 to WizardsList.Count - 1 do
AddMenu (WizardsList[i] as TCanWiz);
end;
if ReadSetting ('MainMenuItem') <> '' then
DMenu.Items.Insert(DMenu.Items.Count-2, CanToolsMenu)
else
for I := 0 to DMenu.Items.Count - 1 do
begin
if DMenu.Items[I].Name = 'ToolsMenu' then
DMenu.Items[I].Insert (0, CantoolsMenu);
end;
end;
destructor TCantoolsManager.Destroy;
begin
FreeAndNil (CantoolsMenu);
FreeAndNil (WizardsList); // owns objects
RemoveFromAboutBox;
CantoolsManager := nil;
inherited;
end;
procedure TCantoolsManager.Destroyed;
begin
end;
procedure TCantoolsManager.Execute;
begin
end;
function TCantoolsManager.GetIDString: string;
begin
Result := 'marcocantu-com-CantoolsManager-idstring';
end;
function TCantoolsManager.GetName: string;
begin
Result := 'marcocantu-com-CantoolsManager-name';
end;
function TCantoolsManager.GetState: TWizardState;
begin
Result := [wsEnabled]; // useless
end;
procedure TCantoolsManager.Modified;
begin
end;
function TCantoolsManager.ReadSetting(const KeyName: string): string;
var
Reg: TRegistry;
begin
Result := '';
Reg := TRegistry.Create;
try
Reg.OpenKey(BaseRegKey, True);
Result := Reg.ReadString(KeyName);
finally
Reg.Free;
end;
end;
procedure TCantoolsManager.RefreshMenu;
begin
// delete and re-create the menu
CantoolsMenu.Parent.Remove (CantoolsMenu);
CreateMenu;
end;
procedure TCantoolsManager.RemoveFromAboutBox;
begin
if FPlugInInfoCode <> 0 then
(BorlandIDEServices as IOTAAboutBoxServices).RemovePluginInfo(FPlugInInfoCode);
end;
procedure TCantoolsManager.ShowMessage(const strMessage: string);
begin
if MessageGroup = nil then
MessageGroup := (BorlandIDEServices as IOTAMessageServices).AddMessageGroup('Cantools');
(BorlandIDEServices as IOTAMessageServices).ShowMessageView(MessageGroup);
(BorlandIDEServices as IOTAMessageServices).AddTitleMessage(strMEssage, MessageGroup);
end;
class procedure TCantoolsManager.ShowSplash;
var
Bitmap: HBITMAP;
begin
Bitmap := LoadBitmap(HInstance, 'OBJECTS');
SplashScreenServices.StatusMessage('Cantools installed');
SplashScreenServices.AddPluginBitmap('Cantools', Bitmap);
end;
procedure TCantoolsManager.WriteSetting(const KeyName, KeyValue: string);
var
Reg: TRegistry;
begin
Reg := TRegistry.Create;
try
Reg.OpenKey(BaseRegKey, True);
Reg.WriteString(KeyName, KeyValue);
finally
Reg.Free;
end;
end;
initialization
TCanToolsManager.ShowSplash;
CantoolsManager := TCantoolsManager.Create;
end.