forked from DelphiPackageManager/DPM
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DPM.IDE.Wizard.pas
234 lines (193 loc) · 7.38 KB
/
DPM.IDE.Wizard.pas
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
{***************************************************************************}
{ }
{ Delphi Package Manager - DPM }
{ }
{ Copyright © 2019 Vincent Parrett and contributors }
{ }
{ https://www.finalbuilder.com }
{ }
{ }
{***************************************************************************}
{ }
{ Licensed under the Apache License, Version 2.0 (the "License"); }
{ you may not use this file except in compliance with the License. }
{ You may obtain a copy of the License at }
{ }
{ http://www.apache.org/licenses/LICENSE-2.0 }
{ }
{ Unless required by applicable law or agreed to in writing, software }
{ distributed under the License is distributed on an "AS IS" BASIS, }
{ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. }
{ See the License for the specific language governing permissions and }
{ limitations under the License. }
{ }
{***************************************************************************}
unit DPM.IDE.Wizard;
interface
uses
ToolsApi,
Vcl.ActnList,
Vcl.ImgList,
Vcl.Controls,
Spring.Container,
DPM.IDE.Logger,
DPM.IDE.MessageService,
DPM.IDE.ProjectTreeManager,
DPM.IDE.EditorViewManager;
type
TDPMWizard = class(TInterfacedObject, IOTANotifier, IOTAWizard)
private
FStorageNotifierID : integer;
FIDENotifier : integer;
FProjectMenuNoftifierId : integer;
FThemeChangeNotifierId : integer;
FEditorViewManager : IDPMEditorViewManager;
FDPMIDEMessageService : IDPMIDEMessageService;
FLogger : IDPMIDELogger;
FContainer : TContainer;
procedure InitContainer;
protected
//IOTAWizard
procedure Execute;
function GetIDString : string;
function GetName : string;
function GetState : TWizardState;
//IOTANotifier
procedure AfterSave;
procedure BeforeSave;
procedure Destroyed;
procedure Modified;
public
constructor Create;
destructor Destroy; override;
end;
implementation
uses
System.TypInfo,
System.SysUtils,
VCL.Dialogs,
Spring.Container.Registration,
DPM.Core.Types,
DPM.Core.Logging,
DPM.Core.Init,
DPM.Core.Utils.Config,
DPM.Core.Package.Interfaces,
DPM.Core.Package.Installer.Interfaces,
DPM.IDE.ProjectController,
DPM.IDE.ProjectStorageNotifier,
DPM.IDE.IDENotifier,
DPM.IDE.ProjectMenu,
DPM.IDE.AddInOptions,
DPM.IDE.Options,
DPM.IDE.InstallerContext,
DPM.IDE.PathManager;
{$R DPM.IDE.Resources.res}
{ TDPMWizard }
procedure TDPMWizard.InitContainer;
begin
try
FContainer := TContainer.Create;
FContainer.RegisterType<IDPMIDEOptions, TDPMIDEOptions>.AsSingleton();
FContainer.RegisterType<IDPMIDEMessageService,TDPMIDEMessageService>.AsSingleton();
FContainer.RegisterType<TDPMIDELogger>.Implements<IDPMIDELogger>.Implements<ILogger>.AsSingleton();
FContainer.RegisterType<IDPMProjectTreeManager, TDPMProjectTreeManager>.AsSingleton();
FContainer.RegisterType<IDPMEditorViewManager, TDPMEditorViewManager>.AsSingleton();
FContainer.RegisterType<IDPMIDEProjectController,TDPMIDEProjectController>.AsSingleton();
FContainer.RegisterType<IDPMIDEPathManager,TDPMIDEPathManager>.AsSingleton();
DPM.Core.Init.InitCore(FContainer,
//replaces core registration of the IPackageInstallerContext implementation
procedure(const container : TContainer)
begin
container.RegisterType<IPackageInstallerContext, TDPMIDEPackageInstallerContext>().AsSingleton();
end);
FContainer.Build;
except
on e : Exception do
begin
FLogger.Error('Error setting up the container : ' + e.Message);
end;
end;
end;
procedure TDPMWizard.AfterSave;
begin
end;
procedure TDPMWizard.BeforeSave;
begin
end;
constructor TDPMWizard.Create;
var
storageNotifier : IOTAProjectFileStorageNotifier;
ideNotifier : IOTAIDENotifier;
projMenuNotifier : IOTAProjectMenuItemCreatorNotifier;
options : INTAAddInOptions;
projectController : IDPMIDEProjectController;
dpmIDEOptions : IDPMIDEOptions;
begin
InitContainer;
FLogger := FContainer.Resolve<IDPMIDELogger>;
dpmIDEOptions := FContainer.Resolve<IDPMIDEOptions>;
if FileExists(dpmIDEOptions.FileName) then
dpmIDEOptions.LoadFromFile()
else
begin
TConfigUtils.EnsureDefaultConfigDir;
dpmIDEOptions.SaveToFile(); //create the file
end;
FLogger.Verbosity := dpmIDEOptions.LogVerbosity;
FEditorViewManager := FContainer.Resolve<IDPMEditorViewManager>;
FDPMIDEMessageService := FContainer.Resolve<IDPMIDEMessageService>;
{$IF CompilerVersion >= 32.0}
FThemeChangeNotifierId := (BorlandIDEServices as IOTAIDEThemingServices).AddNotifier(FEditorViewManager as INTAIDEThemingServicesNotifier);
{$ELSE}
FThemeChangeNotifierId := -1;
{$IFEND}
projectController := FContainer.Resolve<IDPMIDEProjectController>;
ideNotifier := TDPMIDENotifier.Create(FLogger, projectController);
FIDENotifier := (BorlandIDEServices as IOTAServices).AddNotifier(ideNotifier);
projMenuNotifier := TDPMProjectMenuNotifier.Create(FEditorViewManager);
FProjectMenuNoftifierId := (BorlandIDEServices as IOTAProjectManager).AddMenuItemCreatorNotifier(projMenuNotifier);
options := TDPMAddinOptions.Create(FContainer);
(BorlandIDEServices as INTAEnvironmentOptionsServices).RegisterAddInOptions(options);
storageNotifier := TDPMProjectStorageNotifier.Create(FLogger, projectController);
FStorageNotifierID := (BorlandIDEServices as IOTAProjectFileStorage).AddNotifier(storageNotifier);
end;
destructor TDPMWizard.Destroy;
begin
inherited;
end;
procedure TDPMWizard.Destroyed;
begin
if FStorageNotifierId > -1 then
(BorlandIDEServices as IOTAProjectFileStorage).RemoveNotifier(FStorageNotifierId);
if FIDENotifier > -1 then
(BorlandIDEServices as IOTAServices).RemoveNotifier(FIDENotifier);
if FProjectMenuNoftifierId > -1 then
(BorlandIDEServices as IOTAServices).RemoveNotifier(FProjectMenuNoftifierId);
{$IF CompilerVersion >= 32.0}
if FThemeChangeNotifierId > -1 then
(BorlandIDEServices as IOTAIDEThemingServices).RemoveNotifier(FThemeChangeNotifierId);
{$IFEND}
FDPMIDEMessageService.ShutDown;
FEditorViewManager.Destroyed; //don't try to resolve this here, errors in the rtl on 10.2
FEditorViewManager := nil;
end;
procedure TDPMWizard.Execute;
begin
end;
function TDPMWizard.GetIDString : string;
begin
result := 'DPM.IDE';
end;
function TDPMWizard.GetName : string;
begin
result := 'DPM';
end;
function TDPMWizard.GetState : TWizardState;
begin
result := [wsEnabled];
end;
procedure TDPMWizard.Modified;
begin
end;
end.