diff --git a/src/ce_dialogs.pas b/src/ce_dialogs.pas index cf317fdb..10e1214b 100644 --- a/src/ce_dialogs.pas +++ b/src/ce_dialogs.pas @@ -23,6 +23,10 @@ function dlgOkInfo(const aMsg: string): TModalResult; *) function dlgOkError(const aMsg: string): TModalResult; +(** + * close aFilename Ok/Cancel. + *) +function dlgFileChangeClose(const aFilename: string): TModalResult; const DdiagFilter = 'D source|*.d|D interface|*.di|All files|*.*'; @@ -51,5 +55,12 @@ begin exit( MessageDlg('Coedit', aMsg, mtError, Btns, '')); end; +function dlgFileChangeClose(const aFilename: string): TModalResult; +const + fmt = '"%s" latest modifications are not saved.'#13#10#13#10'Close it without saving ?'; +begin + exit(dlgOkCancel(format(fmt, [aFilename]))); +end; + end. diff --git a/src/ce_editor.pas b/src/ce_editor.pas index c06cdd89..69c898cb 100644 --- a/src/ce_editor.pas +++ b/src/ce_editor.pas @@ -249,9 +249,8 @@ var doc: TCESynMemo; begin doc := getDocument(index); - if doc.modified then if dlgOkCancel(format( - 'The latest "%s" modifications are not saved, close without saving ?', - [shortenPath(doc.fileName,25)])) = mrCancel then exit(false); + if doc.modified and (dlgFileChangeClose(fDoc.fileName) = mrCancel) then + exit(false); doc.Free; result := true; end; diff --git a/src/ce_main.pas b/src/ce_main.pas index ff518ad9..e882bb36 100644 --- a/src/ce_main.pas +++ b/src/ce_main.pas @@ -1065,10 +1065,8 @@ var begin canClose := false; SaveLastDocsAndProj; - if fProjectInterface <> nil then if fProjectInterface.modified then - if dlgOkCancel( - 'The project modifications are not saved, close without saving ?') <> mrOK then - exit; + if (fProjectInterface <> nil) and fProjectInterface.modified and + (dlgFileChangeClose(fProjectInterface.filename) = mrCancel) then exit; for i := fMultidoc.documentCount-1 downto 0 do if not fMultidoc.closeDocument(i) then exit; canClose := true; @@ -1493,10 +1491,7 @@ end; procedure TCEMainForm.actFileCloseExecute(Sender: TObject); begin if fDoc = nil then exit; - if fDoc.modified then if dlgOkCancel( - 'The file modifications are not saved, close without saving ?') = mrCancel - then exit; - // + if fDoc.modified and (dlgFileChangeClose(fDoc.fileName) = mrCancel) then exit; fDoc.Free; end; @@ -2060,18 +2055,18 @@ end; procedure TCEMainForm.actProjNewDubJsonExecute(Sender: TObject); begin - if (fProjectInterface <> nil) and fProjectInterface.modified and (dlgOkCancel( - 'The project modifications are not saved, close without saving ?') = mrCancel) then exit; + if (fProjectInterface <> nil) and fProjectInterface.modified and + (dlgFileChangeClose(fProjectInterface.filename) = mrCancel) then exit; closeProj; newDubProj; end; procedure TCEMainForm.actProjNewNativeExecute(Sender: TObject); begin - if (fProjectInterface <> nil) and fProjectInterface.modified and (dlgOkCancel( - 'The project modifications are not saved, close without saving ?') = mrCancel) then exit; - closeProj; - newNativeProj; + if (fProjectInterface <> nil) and fProjectInterface.modified and + (dlgFileChangeClose(fProjectInterface.filename) = mrCancel) then exit; + closeProj; + newNativeProj; end; procedure TCEMainForm.newNativeProj; @@ -2117,16 +2112,15 @@ end; procedure TCEMainForm.mruProjItemClick(Sender: TObject); begin - if (fProjectInterface <> nil) and fProjectInterface.modified and (dlgOkCancel( - 'The project modifications are not saved, close without saving ?') = mrCancel) then exit; + if (fProjectInterface <> nil) and fProjectInterface.modified and + (dlgFileChangeClose(fProjectInterface.filename) = mrCancel) then exit; openProj(TMenuItem(Sender).Hint); end; procedure TCEMainForm.actProjCloseExecute(Sender: TObject); begin - if fProjectInterface = nil then exit; - if fProjectInterface.modified and (dlgOkCancel( - 'The project modifications are not saved, clsoe without saving ?') = mrCancel) then exit; + if (fProjectInterface <> nil) and fProjectInterface.modified and + (dlgFileChangeClose(fProjectInterface.filename) = mrCancel) then exit; closeProj; end; @@ -2149,9 +2143,8 @@ end; procedure TCEMainForm.actProjOpenExecute(Sender: TObject); begin - if fProjectInterface <> nil then if fProjectInterface.modified then if dlgOkCancel( - 'The project modifications are not saved, close without saving ?') - = mrCancel then exit; + if (fProjectInterface <> nil) and fProjectInterface.modified and + (dlgFileChangeClose(fProjectInterface.filename) = mrCancel) then exit; with TOpenDialog.Create(nil) do try if execute then openProj(filename); diff --git a/src/ce_miniexplorer.pas b/src/ce_miniexplorer.pas index f2f76957..e2d04803 100644 --- a/src/ce_miniexplorer.pas +++ b/src/ce_miniexplorer.pas @@ -8,7 +8,7 @@ uses Classes, SysUtils, FileUtil, ListFilterEdit, Forms, Controls, Graphics, ExtCtrls, Menus, ComCtrls, Buttons, lcltype, strutils, ce_widget, ce_sharedres, ce_common, ce_interfaces, ce_observer, ce_writableComponent, ce_dubproject, - ce_nativeproject, EditBtn; + ce_nativeproject, EditBtn, ce_dialogs; type @@ -351,13 +351,23 @@ begin {$ENDIF} if isValidNativeProject(fname) then begin - if assigned(fProj) then fProj.getProject.Free; + if assigned(fProj) then + begin + if fProj.modified and (dlgFileChangeClose(fname) = mrCancel) then + exit; + fProj.getProject.Free; + end; TCENativeProject.create(nil); proj := true; end else if isValidDubProject(fname) then begin - if assigned(fProj) then fProj.getProject.Free; + if assigned(fProj) then + begin + if fProj.modified and (dlgFileChangeClose(fname) = mrCancel) then + exit; + fProj.getProject.Free; + end; TCEDubProject.create(nil); proj := true; end;