mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-14 01:39:20 +02:00
IDE: initial setup dialog: use SimpleFormat, resourcestrings cannot be trusted during boot
git-svn-id: trunk@47017 -
This commit is contained in:
parent
b20ca2c1af
commit
05a395046c
@ -40,11 +40,12 @@ unit InitialSetupDlgs;
|
|||||||
interface
|
interface
|
||||||
|
|
||||||
uses
|
uses
|
||||||
Classes, SysUtils, strutils, contnrs, LCLProc, Forms, Controls, Buttons, Dialogs, FileUtil,
|
Classes, SysUtils, strutils, contnrs, LCLProc, Forms, Controls, Buttons,
|
||||||
Laz2_XMLCfg, lazutf8classes, LazFileUtils, LazFileCache, Graphics, ComCtrls, ExtCtrls,
|
Dialogs, FileUtil, Laz2_XMLCfg, lazutf8classes, LazFileUtils, LazFileCache,
|
||||||
StdCtrls, DefineTemplates, CodeToolManager, TransferMacros, MacroDefIntf, GDBMIDebugger,
|
LazLogger, Graphics, ComCtrls, ExtCtrls, StdCtrls, DefineTemplates,
|
||||||
DbgIntfDebuggerBase, LazarusIDEStrConsts, LazConf, EnvironmentOpts, IDEProcs, AboutFrm,
|
CodeToolManager, TransferMacros, MacroDefIntf, GDBMIDebugger,
|
||||||
IDETranslations, InitialSetupProc;
|
DbgIntfDebuggerBase, LazarusIDEStrConsts, LazConf, EnvironmentOpts, IDEProcs,
|
||||||
|
AboutFrm, IDETranslations, InitialSetupProc;
|
||||||
|
|
||||||
type
|
type
|
||||||
TInitialSetupDialog = class;
|
TInitialSetupDialog = class;
|
||||||
@ -189,8 +190,6 @@ function CheckDebuggerQuality(AFilename: string; out Note: string): TSDFilenameQ
|
|||||||
// Search debugger candidates and add them to list, including quality level
|
// Search debugger candidates and add them to list, including quality level
|
||||||
function SearchDebuggerCandidates(StopIfFits: boolean): TSDFileInfoList;
|
function SearchDebuggerCandidates(StopIfFits: boolean): TSDFileInfoList;
|
||||||
|
|
||||||
function SafeFormat(const Fmt: String; const Args: Array of const): String;
|
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
const
|
const
|
||||||
@ -321,22 +320,6 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function SafeFormat(const Fmt: String; const Args: array of const): String;
|
|
||||||
begin
|
|
||||||
// try with translated resourcestring
|
|
||||||
try
|
|
||||||
Result:=Format(Fmt,Args);
|
|
||||||
exit;
|
|
||||||
except
|
|
||||||
end;
|
|
||||||
// translation didn't work
|
|
||||||
// => get the default value (English)
|
|
||||||
// there is no official way to get the default value of a resourcestring
|
|
||||||
// => reset all resourcestrings
|
|
||||||
ResetResourceTables;
|
|
||||||
Result:=Format(Fmt,Args);
|
|
||||||
end;
|
|
||||||
|
|
||||||
function ShowInitialSetupDialog: TModalResult;
|
function ShowInitialSetupDialog: TModalResult;
|
||||||
var
|
var
|
||||||
InitialSetupDialog: TInitialSetupDialog;
|
InitialSetupDialog: TInitialSetupDialog;
|
||||||
@ -523,7 +506,7 @@ begin
|
|||||||
Dlg:=TOpenDialog.Create(nil);
|
Dlg:=TOpenDialog.Create(nil);
|
||||||
try
|
try
|
||||||
Filename:='gdb'+GetExecutableExt;
|
Filename:='gdb'+GetExecutableExt;
|
||||||
Dlg.Title:=SafeFormat(lisSelectPathTo, [Filename]);
|
Dlg.Title:=SimpleFormat(lisSelectPathTo, [Filename]);
|
||||||
Dlg.Options:=Dlg.Options+[ofFileMustExist];
|
Dlg.Options:=Dlg.Options+[ofFileMustExist];
|
||||||
Filter:=dlgAllFiles+'|'+GetAllFilesMask;
|
Filter:=dlgAllFiles+'|'+GetAllFilesMask;
|
||||||
if ExtractFileExt(Filename)<>'' then
|
if ExtractFileExt(Filename)<>'' then
|
||||||
@ -552,7 +535,7 @@ begin
|
|||||||
Dlg:=TOpenDialog.Create(nil);
|
Dlg:=TOpenDialog.Create(nil);
|
||||||
try
|
try
|
||||||
Filename:='fpc'+GetExecutableExt;
|
Filename:='fpc'+GetExecutableExt;
|
||||||
Dlg.Title:=SafeFormat(lisSelectPathTo, [Filename]);
|
Dlg.Title:=SimpleFormat(lisSelectPathTo, [Filename]);
|
||||||
Dlg.Options:=Dlg.Options+[ofFileMustExist];
|
Dlg.Options:=Dlg.Options+[ofFileMustExist];
|
||||||
Filter:=dlgAllFiles+'|'+GetAllFilesMask;
|
Filter:=dlgAllFiles+'|'+GetAllFilesMask;
|
||||||
if ExtractFileExt(Filename)<>'' then
|
if ExtractFileExt(Filename)<>'' then
|
||||||
@ -620,7 +603,7 @@ begin
|
|||||||
Dlg:=TOpenDialog.Create(nil);
|
Dlg:=TOpenDialog.Create(nil);
|
||||||
try
|
try
|
||||||
Filename:='make'+GetExecutableExt;
|
Filename:='make'+GetExecutableExt;
|
||||||
Dlg.Title:=SafeFormat(lisSelectPathTo, [Filename]);
|
Dlg.Title:=SimpleFormat(lisSelectPathTo, [Filename]);
|
||||||
Dlg.Options:=Dlg.Options+[ofFileMustExist];
|
Dlg.Options:=Dlg.Options+[ofFileMustExist];
|
||||||
Filter:=dlgAllFiles+'|'+GetAllFilesMask;
|
Filter:=dlgAllFiles+'|'+GetAllFilesMask;
|
||||||
if ExtractFileExt(Filename)<>'' then
|
if ExtractFileExt(Filename)<>'' then
|
||||||
@ -751,7 +734,7 @@ procedure TInitialSetupDialog.UpdateCaptions;
|
|||||||
var
|
var
|
||||||
s: String;
|
s: String;
|
||||||
begin
|
begin
|
||||||
Caption:=SafeFormat(lisWelcomeToLazarusIDE, [GetLazarusVersionString]);
|
Caption:=SimpleFormat(lisWelcomeToLazarusIDE, [GetLazarusVersionString]);
|
||||||
|
|
||||||
StartIDEBitBtn.Caption:=lisStartIDE;
|
StartIDEBitBtn.Caption:=lisStartIDE;
|
||||||
|
|
||||||
@ -768,26 +751,26 @@ begin
|
|||||||
TVNodeDebugger.Text:=DebuggerTabSheet.Caption;
|
TVNodeDebugger.Text:=DebuggerTabSheet.Caption;
|
||||||
|
|
||||||
LazDirBrowseButton.Caption:=lisPathEditBrowse;
|
LazDirBrowseButton.Caption:=lisPathEditBrowse;
|
||||||
LazDirLabel.Caption:=SafeFormat(
|
LazDirLabel.Caption:=SimpleFormat(
|
||||||
lisTheLazarusDirectoryContainsTheSourcesOfTheIDEAndTh, [PathDelim]);
|
lisTheLazarusDirectoryContainsTheSourcesOfTheIDEAndTh, [PathDelim]);
|
||||||
|
|
||||||
CompilerBrowseButton.Caption:=lisPathEditBrowse;
|
CompilerBrowseButton.Caption:=lisPathEditBrowse;
|
||||||
CompilerLabel.Caption:=SafeFormat(lisTheFreePascalCompilerExecutableTypicallyHasTheName,
|
CompilerLabel.Caption:=SimpleFormat(lisTheFreePascalCompilerExecutableTypicallyHasTheName,
|
||||||
[DefineTemplates.GetDefaultCompilerFilename,
|
[DefineTemplates.GetDefaultCompilerFilename,
|
||||||
DefineTemplates.GetDefaultCompilerFilename(GetCompiledTargetCPU)]);
|
DefineTemplates.GetDefaultCompilerFilename(GetCompiledTargetCPU)]);
|
||||||
|
|
||||||
FPCSrcDirBrowseButton.Caption:=lisPathEditBrowse;
|
FPCSrcDirBrowseButton.Caption:=lisPathEditBrowse;
|
||||||
FPCSrcDirLabel.Caption:=SafeFormat(lisTheSourcesOfTheFreePascalPackagesAreRequiredForBro,
|
FPCSrcDirLabel.Caption:=SimpleFormat(lisTheSourcesOfTheFreePascalPackagesAreRequiredForBro,
|
||||||
[SetDirSeparators('rtl/linux/system.pp')]);
|
[SetDirSeparators('rtl/linux/system.pp')]);
|
||||||
ScanLabel.Caption := lisScanning;
|
ScanLabel.Caption := lisScanning;
|
||||||
StopScanButton.Caption:=lisStop;
|
StopScanButton.Caption:=lisStop;
|
||||||
|
|
||||||
MakeExeBrowseButton.Caption:=lisPathEditBrowse;
|
MakeExeBrowseButton.Caption:=lisPathEditBrowse;
|
||||||
MakeExeLabel.Caption:=SafeFormat(
|
MakeExeLabel.Caption:=SimpleFormat(
|
||||||
lisTheMakeExecutableTypicallyHasTheName, ['make'+GetExecutableExt('')]);
|
lisTheMakeExecutableTypicallyHasTheName, ['make'+GetExecutableExt('')]);
|
||||||
|
|
||||||
DebuggerBrowseButton.Caption:=lisPathEditBrowse;
|
DebuggerBrowseButton.Caption:=lisPathEditBrowse;
|
||||||
s:=SafeFormat(lisTheDebuggerExecutableTypicallyHasTheNamePleaseGive, [
|
s:=SimpleFormat(lisTheDebuggerExecutableTypicallyHasTheNamePleaseGive, [
|
||||||
'gdb'+GetExecutableExt]);
|
'gdb'+GetExecutableExt]);
|
||||||
{$IFDEF Windows}
|
{$IFDEF Windows}
|
||||||
s+=' '+lisAUsefulSettingOnWindowsSystemsIsLazarusDirMingwBin;
|
s+=' '+lisAUsefulSettingOnWindowsSystemsIsLazarusDirMingwBin;
|
||||||
|
@ -33,8 +33,9 @@ interface
|
|||||||
|
|
||||||
uses
|
uses
|
||||||
Classes, SysUtils, strutils, LazFileCache, LazUTF8Classes, LazFileUtils,
|
Classes, SysUtils, strutils, LazFileCache, LazUTF8Classes, LazFileUtils,
|
||||||
LazLoggerBase, LazUTF8, Laz2_XMLCfg, DefineTemplates, CodeToolManager,
|
LazLoggerBase, LazUTF8, Laz2_XMLCfg, LazLogger, DefineTemplates,
|
||||||
LazarusIDEStrConsts, LazConf, EnvironmentOpts, IDEProcs, contnrs;
|
CodeToolManager, LazarusIDEStrConsts, LazConf, EnvironmentOpts, IDEProcs,
|
||||||
|
contnrs;
|
||||||
|
|
||||||
type
|
type
|
||||||
TSDFilenameQuality = (
|
TSDFilenameQuality = (
|
||||||
@ -104,6 +105,8 @@ function GetValueFromPrimaryConfig(OptionFilename, Path: string): string;
|
|||||||
function GetValueFromSecondaryConfig(OptionFilename, Path: string): string;
|
function GetValueFromSecondaryConfig(OptionFilename, Path: string): string;
|
||||||
function GetValueFromIDEConfig(OptionFilename, Path: string): string;
|
function GetValueFromIDEConfig(OptionFilename, Path: string): string;
|
||||||
|
|
||||||
|
function SafeFormat(const Fmt: String; const Args: Array of const): String;
|
||||||
|
function SimpleFormat(const Fmt: String; const Args: Array of const): String;
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
@ -891,6 +894,62 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function SafeFormat(const Fmt: String; const Args: array of const): String;
|
||||||
|
begin
|
||||||
|
// try with translated resourcestring
|
||||||
|
try
|
||||||
|
Result:=Format(Fmt,Args);
|
||||||
|
exit;
|
||||||
|
except
|
||||||
|
on E: Exception do
|
||||||
|
debugln(['ERROR: SafeFormat: ',E.Message]);
|
||||||
|
end;
|
||||||
|
// translation didn't work
|
||||||
|
// ToDo: find out how to get the resourcestring default value
|
||||||
|
//ResetResourceTables;
|
||||||
|
|
||||||
|
// use a safe fallback
|
||||||
|
Result:=SimpleFormat(Fmt,Args);
|
||||||
|
end;
|
||||||
|
|
||||||
|
function SimpleFormat(const Fmt: String; const Args: array of const): String;
|
||||||
|
var
|
||||||
|
p: Integer;
|
||||||
|
i: Integer;
|
||||||
|
s: String;
|
||||||
|
begin
|
||||||
|
Result:=Fmt;
|
||||||
|
p:=1;
|
||||||
|
for i:=Low(Args) to High(Args) do
|
||||||
|
begin
|
||||||
|
case Args[i].VType of
|
||||||
|
vtString: s:=Args[i].VString^;
|
||||||
|
vtAnsiString: s:=AnsiString(Args[i].VAnsiString);
|
||||||
|
vtChar: s:=Args[i].VChar;
|
||||||
|
else continue;
|
||||||
|
end;
|
||||||
|
while (p<length(Result)) do begin
|
||||||
|
if (Result[p]='%') then
|
||||||
|
begin
|
||||||
|
if (Result[p+1]='s') then
|
||||||
|
break
|
||||||
|
else
|
||||||
|
inc(p,2);
|
||||||
|
end else
|
||||||
|
inc(p);
|
||||||
|
end;
|
||||||
|
if p<length(Result) then begin
|
||||||
|
// found %s => replace
|
||||||
|
ReplaceSubstring(Result,p,2,s);
|
||||||
|
inc(p,length(s));
|
||||||
|
end else begin
|
||||||
|
// missing %s => append
|
||||||
|
Result+=', '+s;
|
||||||
|
p:=length(s)+1;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
{ TSDFileInfoList }
|
{ TSDFileInfoList }
|
||||||
|
|
||||||
function TSDFileInfoList.AddNewItem(aFilename, aCaption: string): TSDFileInfo;
|
function TSDFileInfoList.AddNewItem(aFilename, aCaption: string): TSDFileInfo;
|
||||||
|
@ -1132,7 +1132,7 @@ procedure TMainIDE.LoadGlobalOptions;
|
|||||||
var
|
var
|
||||||
StartFile: String;
|
StartFile: String;
|
||||||
begin
|
begin
|
||||||
Result:=SafeFormat(lisIfYouWantToUseTwoDifferentLazarusVersionsYouMustSt,
|
Result:=SimpleFormat(lisIfYouWantToUseTwoDifferentLazarusVersionsYouMustSt,
|
||||||
[LineEnding+LineEnding]) + LineEnding;
|
[LineEnding+LineEnding]) + LineEnding;
|
||||||
StartFile:=Application.ExeName;
|
StartFile:=Application.ExeName;
|
||||||
if StartedByStartLazarus then
|
if StartedByStartLazarus then
|
||||||
@ -1236,7 +1236,7 @@ begin
|
|||||||
debugln([' CurPrgName="',CurPrgName,'"']);
|
debugln([' CurPrgName="',CurPrgName,'"']);
|
||||||
debugln([' AltPrgName="',AltPrgName,'"']);
|
debugln([' AltPrgName="',AltPrgName,'"']);
|
||||||
MsgResult := IDEQuestionDialog(lisIncorrectConfigurationDirectoryFound,
|
MsgResult := IDEQuestionDialog(lisIncorrectConfigurationDirectoryFound,
|
||||||
SafeFormat(lisIDEConficurationFoundMayBelongToOtherLazarus,
|
SimpleFormat(lisIDEConficurationFoundMayBelongToOtherLazarus,
|
||||||
[LineEnding, GetSecondConfDirWarning, GetPrimaryConfigPath,
|
[LineEnding, GetSecondConfDirWarning, GetPrimaryConfigPath,
|
||||||
EnvironmentOptions.LastCalledByLazarusFullPath, CurPrgName]),
|
EnvironmentOptions.LastCalledByLazarusFullPath, CurPrgName]),
|
||||||
mtWarning, [mrOK, lisUpdateInfo, mrIgnore, mrAbort]);
|
mtWarning, [mrOK, lisUpdateInfo, mrIgnore, mrAbort]);
|
||||||
@ -1265,8 +1265,8 @@ begin
|
|||||||
begin
|
begin
|
||||||
IsUpgrade:=CompareLazarusVersion(NowVer,OldVer)>0;
|
IsUpgrade:=CompareLazarusVersion(NowVer,OldVer)>0;
|
||||||
if OldVer='' then
|
if OldVer='' then
|
||||||
OldVer:=SafeFormat(lisPrior, [GetLazarusVersionString]);
|
OldVer:=SimpleFormat(lisPrior, [GetLazarusVersionString]);
|
||||||
s:=SafeFormat(lisWelcomeToLazarusThereIsAlreadyAConfigurationFromVe,
|
s:=SimpleFormat(lisWelcomeToLazarusThereIsAlreadyAConfigurationFromVe,
|
||||||
[GetLazarusVersionString, LineEnding+LineEnding, OldVer, LineEnding, GetPrimaryConfigPath] );
|
[GetLazarusVersionString, LineEnding+LineEnding, OldVer, LineEnding, GetPrimaryConfigPath] );
|
||||||
if IsUpgrade then
|
if IsUpgrade then
|
||||||
s+=lisTheOldConfigurationWillBeUpgraded
|
s+=lisTheOldConfigurationWillBeUpgraded
|
||||||
|
Loading…
Reference in New Issue
Block a user