diff --git a/components/buildintf/lazmsgworker.pas b/components/buildintf/lazmsgworker.pas index cec45dad72..e5f052d905 100644 --- a/components/buildintf/lazmsgworker.pas +++ b/components/buildintf/lazmsgworker.pas @@ -20,7 +20,57 @@ var // set by the IDE LazMessageWorker: TLazMessageWorker = nil; LazQuestionWorker: TLazQuestionWorker = nil; +function LazMessageDialogAb(const aCaption, aMsg: string; + DlgType: TMsgDlgType; Buttons: TMsgDlgButtons; + ShowAbort: boolean; const HelpKeyword: string = ''): Integer; +function LazQuestionDialogAb(const aCaption, aMsg: string; + DlgType: TMsgDlgType; Buttons: array of const; + HideAbort: boolean; const HelpKeyword: string = ''): Integer; + implementation +function LazMessageDialogAb(const aCaption, aMsg: string; DlgType: TMsgDlgType; + Buttons: TMsgDlgButtons; ShowAbort: boolean; const HelpKeyword: string): Integer; +begin + if ShowAbort then begin + // add an abort button for 'Cancel all' and replace a Cancel with Ignore + Buttons:=Buttons+[mbAbort]; + if mbCancel in Buttons then + Buttons:=Buttons-[mbCancel]+[mbIgnore]; + end; + Result:=LazMessageWorker(aCaption,aMsg,DlgType,Buttons,HelpKeyword); +end; + +function LazQuestionDialogAb(const aCaption, aMsg: string; + DlgType: TMsgDlgType; Buttons: array of const; + HideAbort: boolean; const HelpKeyword: string): Integer; +var + NewButtons: array of TVarRec; + i: Integer; + j: Integer; +begin + SetLength(NewButtons{%H-},High(Buttons)-Low(Buttons)+1); + i:=low(Buttons); + j:=0; + while i<=High(Buttons) do begin + if HideAbort + and (Buttons[i].VType=vtInteger) + and (Buttons[i].VInteger=mrAbort) then begin + // skip abort button + inc(i); + // and skip abort caption + if Buttons[i].VType<>vtInteger then + inc(i); + end else begin + NewButtons[j]:=Buttons[i]; + inc(i); + inc(j); + end; + end; + SetLength(NewButtons,j); + Result:=LazQuestionWorker(aCaption,aMsg,DlgType,NewButtons,HelpKeyword); +end; + + end. diff --git a/components/ideintf/idedialogs.pas b/components/ideintf/idedialogs.pas index 8b5d8a1327..5cc17ae827 100644 --- a/components/ideintf/idedialogs.pas +++ b/components/ideintf/idedialogs.pas @@ -134,43 +134,16 @@ end; function IDEMessageDialogAb(const aCaption, aMsg: string; DlgType: TMsgDlgType; Buttons: TMsgDlgButtons; ShowAbort: boolean; const HelpKeyword: string): Integer; begin - if ShowAbort then begin - // add an abort button for 'Cancel all' and replace a Cancel with Ignore - Buttons:=Buttons+[mbAbort]; - if mbCancel in Buttons then - Buttons:=Buttons-[mbCancel]+[mbIgnore]; - end; - Result:=IDEMessageDialog(aCaption,aMsg,DlgType,Buttons,HelpKeyword); + Result := LazMsgWorker.LazMessageDialogAb(aCaption, aMsg, DlgType, Buttons, + ShowAbort, HelpKeyword); end; function IDEQuestionDialogAb(const aCaption, aMsg: string; DlgType: TMsgDlgType; Buttons: array of const; HideAbort: boolean; const HelpKeyword: string): Integer; -var - NewButtons: array of TVarRec; - i: Integer; - j: Integer; begin - SetLength(NewButtons{%H-},High(Buttons)-Low(Buttons)+1); - i:=low(Buttons); - j:=0; - while i<=High(Buttons) do begin - if HideAbort - and (Buttons[i].VType=vtInteger) - and (Buttons[i].VInteger=mrAbort) then begin - // skip abort button - inc(i); - // and skip abort caption - if Buttons[i].VType<>vtInteger then - inc(i); - end else begin - NewButtons[j]:=Buttons[i]; - inc(i); - inc(j); - end; - end; - SetLength(NewButtons,j); - Result:=IDEQuestionDialog(aCaption,aMsg,DlgType,NewButtons,HelpKeyword); + Result := LazMsgWorker.LazQuestionDialogAb(aCaption, aMsg, DlgType, Buttons, + HideAbort, HelpKeyword); end; { TIDESaveDialog } diff --git a/ide/packages/ideutils/dialogprocs.pas b/ide/packages/ideutils/dialogprocs.pas index 5cbc4fca22..031da1a353 100644 --- a/ide/packages/ideutils/dialogprocs.pas +++ b/ide/packages/ideutils/dialogprocs.pas @@ -43,8 +43,10 @@ uses FileUtil, LazFileUtils, LazFileCache, Laz2_XMLCfg, LazLoggerBase, // CodeTools CodeToolsConfig, CodeCache, CodeToolManager, + // BuildIntf + LazMsgWorker, // IdeUtils - IDEDialogs, IdeUtilsPkgStrConsts; + IdeUtilsPkgStrConsts; type // load buffer flags @@ -148,7 +150,7 @@ begin break; end else begin DlgButtons:=[mbRetry]+ExtraButtons; - Result:=IDEMessageDialog(lisUnableToRenameFile, + Result:=LazMessageWorker(lisUnableToRenameFile, Format(lisUnableToRenameFileTo2, [SrcFilename, LineEnding, DestFilename]), mtError,DlgButtons); if (Result<>mrRetry) then exit; @@ -164,7 +166,7 @@ var begin if CompareFilenames(SrcFilename,DestFilename)=0 then begin Result:=mrAbort; - IDEMessageDialog(lisUnableToCopyFile, + LazMessageWorker(lisUnableToCopyFile, Format(lisSourceAndDestinationAreTheSame, [LineEnding, SrcFilename]), mtError, [mbAbort]); exit; @@ -175,7 +177,7 @@ begin break; end else begin DlgButtons:=[mbCancel,mbRetry]+ExtraButtons; - Result:=IDEMessageDialog(lisUnableToCopyFile, + Result:=LazMessageWorker(lisUnableToCopyFile, Format(lisUnableToCopyFileTo, [SrcFilename, LineEnding, DestFilename]), mtError,DlgButtons); if (Result<>mrRetry) then exit; @@ -215,7 +217,7 @@ begin end else begin ACaption:=lisFileNotText; AText:=Format(lisFileDoesNotLookLikeATextFileOpenItAnyway,[AFilename,LineEnding,LineEnding]); - Result:=IDEMessageDialogAb(ACaption, AText, mtConfirmation, + Result:=LazMessageDialogAb(ACaption, AText, mtConfirmation, [mbOk, mbIgnore],ShowAbort); end; if Result<>mrOk then break; @@ -240,7 +242,7 @@ begin else begin ACaption:=lisReadError; AText:=Format(lisUnableToReadFile2, [AFilename]); - Result:=IDEMessageDialogAb(ACaption,AText,mtError,[mbRetry,mbIgnore],ShowAbort); + Result:=LazMessageDialogAb(ACaption,AText,mtError,[mbRetry,mbIgnore],ShowAbort); if Result=mrAbort then exit; end; end; @@ -258,7 +260,7 @@ begin if ACodeBuffer.Save then begin Result:=mrOk; end else begin - Result:=IDEMessageDialog(lisCodeToolsDefsWriteError, + Result:=LazMessageWorker(lisCodeToolsDefsWriteError, Format(lisUnableToWrite2, [ACodeBuffer.Filename]), mtError,[mbAbort,mbRetry,mbIgnore]); end; @@ -284,7 +286,7 @@ begin end else begin ACaption:=lisWriteError; AText:=Format(lisUnableToWriteToFile2, [Filename]); - Result:=IDEMessageDialog(ACaption,AText,mtError,[mbAbort, mbRetry, mbIgnore]); + Result:=LazMessageWorker(ACaption,AText,mtError,[mbAbort, mbRetry, mbIgnore]); if Result=mrAbort then exit; if Result=mrIgnore then Result:=mrOk; end; @@ -302,7 +304,7 @@ begin Result:=mrOk; except on E: Exception do begin - IDEMessageDialog(lisCCOErrorCaption, + LazMessageWorker(lisCCOErrorCaption, Format(lisErrorLoadingFrom, [ListTitle, LineEnding, Filename, LineEnding+LineEnding, E.Message]), mtError, [mbOk]); @@ -321,7 +323,7 @@ begin Result:=mrOk; except on E: Exception do begin - IDEMessageDialog(lisCCOErrorCaption, Format(lisErrorSavingTo, [ListTitle, + LazMessageWorker(lisCCOErrorCaption, Format(lisErrorSavingTo, [ListTitle, LineEnding, Filename, LineEnding+LineEnding, E.Message]), mtError, [mbOk]); end; end; @@ -351,7 +353,7 @@ begin if (lbfQuiet in Flags) then begin Result:=mrCancel; end else begin - Result:=IDEMessageDialog(lisXMLError, + Result:=LazMessageWorker(lisXMLError, Format(lisXMLParserErrorInFileError, [Filename, LineEnding, E.Message]), mtError, [mbCancel]); end; @@ -382,7 +384,7 @@ begin Config.WriteToStream(ms); except on E: Exception do begin - Result:=IDEMessageDialog(lisXMLError, + Result:=LazMessageWorker(lisXMLError, Format(lisUnableToWriteXmlStreamToError, [Filename, LineEnding, E.Message]), mtError, [mbCancel]); end; @@ -409,7 +411,7 @@ begin fs:=TFileStream.Create(AFilename,fmCreate); fs.Free; except - Result:=IDEMessageDialog(lisUnableToCreateFile, + Result:=LazMessageWorker(lisUnableToCreateFile, Format(lisUnableToCreateFile2, [AFilename]), mtError, [mbCancel, mbAbort]); exit; @@ -417,7 +419,7 @@ begin end else begin // file already exists if WarnOverwrite then begin - Result:=IDEQuestionDialog(lisOverwriteFile, + Result:=LazQuestionWorker(lisOverwriteFile, Format(lisAFileAlreadyExistsReplaceIt, [AFilename, LineEnding]), mtConfirmation, [mrYes, lisOverwriteFileOnDisk, mrCancel]); @@ -445,7 +447,7 @@ begin fs.Free; end; except - Result:=IDEMessageDialog(lisUnableToWriteFile, + Result:=LazMessageWorker(lisUnableToWriteFile, Format(lisUnableToWriteToFile2, [AFilename]), mtError, [mbCancel, mbAbort]); exit; end; @@ -460,7 +462,7 @@ begin fs.Free; end; except - Result:=IDEMessageDialog(lisUnableToReadFile, + Result:=LazMessageWorker(lisUnableToReadFile, Format(lisUnableToReadFile2, [AFilename]), mtError, [mbCancel, mbAbort]); exit; @@ -472,7 +474,7 @@ function CheckFileIsWritable(const Filename: string; ErrorButtons: TMsgDlgButtons): TModalResult; begin while not FileIsWritable(Filename) do begin - Result:=IDEMessageDialog(lisFileIsNotWritable, + Result:=LazMessageWorker(lisFileIsNotWritable, Format(lisUnableToWriteToFile2, [Filename]), mtError, ErrorButtons+[mbCancel,mbRetry]); if Result<>mrRetry then exit; @@ -483,7 +485,7 @@ end; function ChooseSymlink(var Filename: string; const TargetFilename: string): TModalResult; begin // ask which filename to use - case IDEQuestionDialog(lisFileIsSymlink, + case LazQuestionWorker(lisFileIsSymlink, Format(lisTheFileIsASymlinkOpenInstead,[Filename,LineEnding+LineEnding,TargetFilename]), mtConfirmation, [mrYes, lisOpenTarget, mrNo, lisOpenSymlink, @@ -502,7 +504,7 @@ begin {$IFDEF Unix} if FpReadLink(LinkFilename)=TargetFilename then exit(mrOk); while FPSymLink(PChar(TargetFilename),PChar(LinkFilename)) <> 0 do begin - Result:=IDEMessageDialog(lisCodeToolsDefsWriteError, + Result:=LazMessageWorker(lisCodeToolsDefsWriteError, Format(lisUnableToCreateLinkWithTarget, [LinkFilename, TargetFilename]), mtError,ErrorButtons+[mbCancel,mbRetry],''); if Result<>mrRetry then exit; @@ -530,7 +532,7 @@ begin Dir:=copy(Directory,1,i-1); if not DirPathExists(Dir) then begin while not CreateDirUTF8(Dir) do begin - Result:=IDEMessageDialog(lisPkgMangUnableToCreateDirectory, + Result:=LazMessageWorker(lisPkgMangUnableToCreateDirectory, Format(lisUnableToCreateDirectory, [Dir]), mtError,ErrorButtons+[mbCancel]); if Result<>mrRetry then exit; @@ -547,7 +549,7 @@ function CheckDirectoryIsWritable(const Filename: string; ErrorButtons: TMsgDlgButtons): TModalResult; begin while not DirectoryIsWritable(Filename) do begin - Result:=IDEMessageDialog(lisDirectoryNotWritable, + Result:=LazMessageWorker(lisDirectoryNotWritable, Format(lisTheDirectoryIsNotWritable, [Filename]), mtError,ErrorButtons+[mbCancel,mbRetry]); if Result<>mrRetry then exit; @@ -571,7 +573,7 @@ begin end; if (not FileIsExecutable(Filename)) then begin - if IDEMessageDialog(ErrorCaption,Format(ErrorMsg,[Filename]), + if LazMessageWorker(ErrorCaption,Format(ErrorMsg,[Filename]), mtWarning,[mbIgnore,mbCancel])=mrCancel then begin Result:=false; @@ -582,7 +584,7 @@ end; function CheckDirPathExists(const Dir, ErrorCaption, ErrorMsg: string): TModalResult; begin if not DirPathExists(Dir) then begin - Result:=IDEMessageDialog(ErrorCaption,Format(ErrorMsg,[Dir]),mtWarning, + Result:=LazMessageWorker(ErrorCaption,Format(ErrorMsg,[Dir]),mtWarning, [mbIgnore,mbCancel]); end else Result:=mrOk; @@ -595,7 +597,7 @@ begin Result:=mrOk; if not FileExistsUTF8(Filename) then exit; if not DeleteFileUTF8(Filename) then begin - Result:=IDEMessageDialogAb(lisDeleteFileFailed, + Result:=LazMessageDialogAb(lisDeleteFileFailed, Format(lisPkgMangUnableToDeleteFile, [Filename]), mtError,[mbCancel,mbRetry]+ErrorButtons-[mbAbort],mbAbort in ErrorButtons); if Result<>mrRetry then exit; @@ -620,7 +622,7 @@ begin Result:=mrOk; except on E: Exception do begin - Result:=IDEMessageDialog(lisCodeToolsDefsWriteError, + Result:=LazMessageWorker(lisCodeToolsDefsWriteError, Format(lisWriteErrorFile, [E.Message, LineEnding, Filename, LineEnding, Context]), mtError,[mbAbort]+ErrorButtons); end; @@ -665,7 +667,7 @@ begin {$ENDIF} debugln(['Error: (lazarus) [ConvertLFMToLRSFileInteractive] unable to convert '+LFMFilename+' to '+LRSFilename+':'+LineEnding +E.Message]); - Result:=IDEMessageDialogAb('Error', + Result:=LazMessageDialogAb('Error', 'Error while converting '+LFMFilename+' to '+LRSFilename+':'+LineEnding +E.Message,mtError,[mbCancel,mbIgnore],ShowAbort); exit; @@ -689,7 +691,7 @@ end; procedure NotImplementedDialog(const Feature: string); begin - IDEMessageDialog(lisNotImplemented, + LazMessageWorker(lisNotImplemented, Format(lisNotImplementedYet, [LineEnding, Feature]), mtError, [mbCancel]); end;