3
3
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
4
4
* obtain one at https://mozilla.org/MPL/2.0/
5
5
*
6
- * Copyright (C) 2009-2021 , Peter Johnson (gravatar.com/delphidabbler).
6
+ * Copyright (C) 2009-2022 , Peter Johnson (gravatar.com/delphidabbler).
7
7
*
8
8
* Provides objects that manage test compilation and assoicated UI, display of
9
9
* compilation results via a callback and and compiler configuration.
@@ -91,7 +91,8 @@ TCompileMgr = class(TComponent)
91
91
{
92
92
TMainCompileMgr:
93
93
Extended compilation manager for use with main form. Checks if a view item
94
- can be compiled and also permits user to configure compilers.
94
+ can be compiled, permits user to configure compilers and checks for newly
95
+ installed compilers.
95
96
}
96
97
TMainCompileMgr = class (TCompileMgr)
97
98
public
@@ -112,6 +113,15 @@ TMainCompileMgr = class(TCompileMgr)
112
113
properties.
113
114
@return True if user accepts changes, False if not.
114
115
}
116
+ // / <summary>Check for new compiler installations, get user permission to
117
+ // / install any that are found and register any compilers that user
118
+ // / selects.</summary>
119
+ // / <remarks>
120
+ // / <para>Does nothing if compiler detection is disabled or if there are
121
+ // / no installed but unregistered compilers.</para>
122
+ // / <para>Should be called at program startup.</para>
123
+ // / </remarks>
124
+ procedure CheckForNewCompilerInstalls ;
115
125
end ;
116
126
117
127
@@ -121,8 +131,18 @@ implementation
121
131
uses
122
132
// Delphi
123
133
SysUtils,
134
+ Generics.Collections,
124
135
// Project
125
- Compilers.UCompilers, DB.UMain, FmCompErrorDlg, FmCompilersDlg,
136
+ Compilers.UAutoDetect,
137
+ Compilers.UCompilers,
138
+ Compilers.USettings,
139
+ DB.UMain,
140
+ FmCompErrorDlg,
141
+ FmCompilersDlg,
142
+ FmRegisterCompilersDlg,
143
+ UConsts,
144
+ UMessageBox,
145
+ UStrUtils,
126
146
UTestCompileUI;
127
147
128
148
@@ -244,6 +264,98 @@ function TMainCompileMgr.CanCompile(View: IView): Boolean;
244
264
and SnippetView.Snippet.CanCompile;
245
265
end ;
246
266
267
+ procedure TMainCompileMgr.CheckForNewCompilerInstalls ;
268
+ var
269
+ CandidateCompilers: TCompilerList; // compilers available for registration
270
+ SelectedCompilers: TCompilerList; // compilers chosen for registration
271
+ Persister: IPersistCompilers; // object to store compiler data in config
272
+
273
+ // Display message box informing user of which compilers were registered
274
+ // MUST be called with non zero number of registered compilers
275
+ procedure NotifyResults ;
276
+ var
277
+ CompList: string; // string containing list of compilers registered
278
+ Compiler: ICompiler; // each compiler
279
+ RegCount: Integer; // count of compilers registered
280
+ resourcestring
281
+ sPrefixS = ' The following compiler was registered:' ;
282
+ sPrefixP = ' The following compilers were registered:' ;
283
+ sNoRegistrations = ' Unexpected error. None of the requested compilers were '
284
+ + ' registered.' ;
285
+ begin
286
+ CompList := ' ' ;
287
+ RegCount := 0 ;
288
+ for Compiler in Compilers do
289
+ begin
290
+ if (SelectedCompilers.IndexOf(Compiler) >= 0 )
291
+ and Compiler.IsAvailable then
292
+ begin
293
+ CompList := CompList + ' ' + Compiler.GetName + EOL;
294
+ Inc(RegCount);
295
+ end ;
296
+ end ;
297
+ if RegCount > 0 then
298
+ begin
299
+ CompList := StrIf(RegCount = 1 , sPrefixS, sPrefixP) + EOL2 + CompList;
300
+ TMessageBox.Information(Owner, CompList);
301
+ end
302
+ else
303
+ TMessageBox.Error(Owner, sNoRegistrations);
304
+ end ;
305
+
306
+ // Display message to user informing that no compilers were registred
307
+ // MUST be called only with a zero number of registered compilers
308
+ procedure NotifyNoRegistrations ;
309
+ resourcestring
310
+ sNothingRegistered = ' No compilers were selected for registration' ;
311
+ begin
312
+ TMessageBox.Information(Owner, sNothingRegistered);
313
+ end ;
314
+
315
+ begin
316
+ if not TCompilerSettings.PermitStartupDetection then
317
+ Exit;
318
+ SelectedCompilers := nil ;
319
+ CandidateCompilers := TCompilerList.Create;
320
+ try
321
+ SelectedCompilers := TCompilerList.Create;
322
+ // Build list of compilers that are installed but not registered
323
+ TCompilerAutoDetect.ListRegisterableCompilers(
324
+ Self.Compilers, CandidateCompilers
325
+ );
326
+ if CandidateCompilers.Count = 0 then
327
+ Exit; // no compilers to register
328
+
329
+ // We have candidate compilers: get user to select
330
+ if TRegisterCompilersDlg.Execute(
331
+ Owner,
332
+ CandidateCompilers,
333
+ SelectedCompilers
334
+ ) then
335
+ begin
336
+ if SelectedCompilers.Count > 0 then
337
+ begin
338
+ // User selected one or more compilers to register
339
+ // register compiler(s)
340
+ TCompilerAutoDetect.RegisterSpecificCompilers(
341
+ Compilers, SelectedCompilers
342
+ );
343
+ // update config file with changes
344
+ Persister := TPersistCompilers.Create;
345
+ Persister.Save(Compilers);
346
+ // tell user what got registered
347
+ NotifyResults;
348
+ end
349
+ else
350
+ // User didn't select a file: tell them
351
+ NotifyNoRegistrations;
352
+ end ;
353
+ finally
354
+ SelectedCompilers.Free;
355
+ CandidateCompilers.Free;
356
+ end ;
357
+ end ;
358
+
247
359
function TMainCompileMgr.ConfigCompilers : Boolean;
248
360
{ Displays Configure Compilers dialog to permit user to update compiler
249
361
properties.
0 commit comments