33 * v. 2.0. If a copy of the MPL was not distributed with this file, You can
44 * obtain one at https://mozilla.org/MPL/2.0/
55 *
6- * Copyright (C) 2009-2021 , Peter Johnson (gravatar.com/delphidabbler).
6+ * Copyright (C) 2009-2022 , Peter Johnson (gravatar.com/delphidabbler).
77 *
88 * Provides objects that manage test compilation and assoicated UI, display of
99 * compilation results via a callback and and compiler configuration.
@@ -91,7 +91,8 @@ TCompileMgr = class(TComponent)
9191 {
9292 TMainCompileMgr:
9393 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.
9596 }
9697 TMainCompileMgr = class (TCompileMgr)
9798 public
@@ -112,6 +113,15 @@ TMainCompileMgr = class(TCompileMgr)
112113 properties.
113114 @return True if user accepts changes, False if not.
114115 }
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 ;
115125 end ;
116126
117127
@@ -121,8 +131,18 @@ implementation
121131uses
122132 // Delphi
123133 SysUtils,
134+ Generics.Collections,
124135 // 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,
126146 UTestCompileUI;
127147
128148
@@ -244,6 +264,98 @@ function TMainCompileMgr.CanCompile(View: IView): Boolean;
244264 and SnippetView.Snippet.CanCompile;
245265end ;
246266
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+
247359function TMainCompileMgr.ConfigCompilers : Boolean;
248360 { Displays Configure Compilers dialog to permit user to update compiler
249361 properties.
0 commit comments