use a common dialog to warn about unsaved changes, + use this in miniexplorer which didnt warn when opening a proj

This commit is contained in:
Basile Burg 2015-11-05 02:27:55 +01:00
parent 89675d2c57
commit 6c90ec9a6c
4 changed files with 41 additions and 28 deletions

View File

@ -23,6 +23,10 @@ function dlgOkInfo(const aMsg: string): TModalResult;
*) *)
function dlgOkError(const aMsg: string): TModalResult; function dlgOkError(const aMsg: string): TModalResult;
(**
* close aFilename Ok/Cancel.
*)
function dlgFileChangeClose(const aFilename: string): TModalResult;
const const
DdiagFilter = 'D source|*.d|D interface|*.di|All files|*.*'; DdiagFilter = 'D source|*.d|D interface|*.di|All files|*.*';
@ -51,5 +55,12 @@ begin
exit( MessageDlg('Coedit', aMsg, mtError, Btns, '')); exit( MessageDlg('Coedit', aMsg, mtError, Btns, ''));
end; 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. end.

View File

@ -249,9 +249,8 @@ var
doc: TCESynMemo; doc: TCESynMemo;
begin begin
doc := getDocument(index); doc := getDocument(index);
if doc.modified then if dlgOkCancel(format( if doc.modified and (dlgFileChangeClose(fDoc.fileName) = mrCancel) then
'The latest "%s" modifications are not saved, close without saving ?', exit(false);
[shortenPath(doc.fileName,25)])) = mrCancel then exit(false);
doc.Free; doc.Free;
result := true; result := true;
end; end;

View File

@ -1065,10 +1065,8 @@ var
begin begin
canClose := false; canClose := false;
SaveLastDocsAndProj; SaveLastDocsAndProj;
if fProjectInterface <> nil then if fProjectInterface.modified then if (fProjectInterface <> nil) and fProjectInterface.modified and
if dlgOkCancel( (dlgFileChangeClose(fProjectInterface.filename) = mrCancel) then exit;
'The project modifications are not saved, close without saving ?') <> mrOK then
exit;
for i := fMultidoc.documentCount-1 downto 0 do for i := fMultidoc.documentCount-1 downto 0 do
if not fMultidoc.closeDocument(i) then exit; if not fMultidoc.closeDocument(i) then exit;
canClose := true; canClose := true;
@ -1493,10 +1491,7 @@ end;
procedure TCEMainForm.actFileCloseExecute(Sender: TObject); procedure TCEMainForm.actFileCloseExecute(Sender: TObject);
begin begin
if fDoc = nil then exit; if fDoc = nil then exit;
if fDoc.modified then if dlgOkCancel( if fDoc.modified and (dlgFileChangeClose(fDoc.fileName) = mrCancel) then exit;
'The file modifications are not saved, close without saving ?') = mrCancel
then exit;
//
fDoc.Free; fDoc.Free;
end; end;
@ -2060,16 +2055,16 @@ end;
procedure TCEMainForm.actProjNewDubJsonExecute(Sender: TObject); procedure TCEMainForm.actProjNewDubJsonExecute(Sender: TObject);
begin begin
if (fProjectInterface <> nil) and fProjectInterface.modified and (dlgOkCancel( if (fProjectInterface <> nil) and fProjectInterface.modified and
'The project modifications are not saved, close without saving ?') = mrCancel) then exit; (dlgFileChangeClose(fProjectInterface.filename) = mrCancel) then exit;
closeProj; closeProj;
newDubProj; newDubProj;
end; end;
procedure TCEMainForm.actProjNewNativeExecute(Sender: TObject); procedure TCEMainForm.actProjNewNativeExecute(Sender: TObject);
begin begin
if (fProjectInterface <> nil) and fProjectInterface.modified and (dlgOkCancel( if (fProjectInterface <> nil) and fProjectInterface.modified and
'The project modifications are not saved, close without saving ?') = mrCancel) then exit; (dlgFileChangeClose(fProjectInterface.filename) = mrCancel) then exit;
closeProj; closeProj;
newNativeProj; newNativeProj;
end; end;
@ -2117,16 +2112,15 @@ end;
procedure TCEMainForm.mruProjItemClick(Sender: TObject); procedure TCEMainForm.mruProjItemClick(Sender: TObject);
begin begin
if (fProjectInterface <> nil) and fProjectInterface.modified and (dlgOkCancel( if (fProjectInterface <> nil) and fProjectInterface.modified and
'The project modifications are not saved, close without saving ?') = mrCancel) then exit; (dlgFileChangeClose(fProjectInterface.filename) = mrCancel) then exit;
openProj(TMenuItem(Sender).Hint); openProj(TMenuItem(Sender).Hint);
end; end;
procedure TCEMainForm.actProjCloseExecute(Sender: TObject); procedure TCEMainForm.actProjCloseExecute(Sender: TObject);
begin begin
if fProjectInterface = nil then exit; if (fProjectInterface <> nil) and fProjectInterface.modified and
if fProjectInterface.modified and (dlgOkCancel( (dlgFileChangeClose(fProjectInterface.filename) = mrCancel) then exit;
'The project modifications are not saved, clsoe without saving ?') = mrCancel) then exit;
closeProj; closeProj;
end; end;
@ -2149,9 +2143,8 @@ end;
procedure TCEMainForm.actProjOpenExecute(Sender: TObject); procedure TCEMainForm.actProjOpenExecute(Sender: TObject);
begin begin
if fProjectInterface <> nil then if fProjectInterface.modified then if dlgOkCancel( if (fProjectInterface <> nil) and fProjectInterface.modified and
'The project modifications are not saved, close without saving ?') (dlgFileChangeClose(fProjectInterface.filename) = mrCancel) then exit;
= mrCancel then exit;
with TOpenDialog.Create(nil) do with TOpenDialog.Create(nil) do
try try
if execute then openProj(filename); if execute then openProj(filename);

View File

@ -8,7 +8,7 @@ uses
Classes, SysUtils, FileUtil, ListFilterEdit, Forms, Controls, Graphics, Classes, SysUtils, FileUtil, ListFilterEdit, Forms, Controls, Graphics,
ExtCtrls, Menus, ComCtrls, Buttons, lcltype, strutils, ce_widget, ce_sharedres, ExtCtrls, Menus, ComCtrls, Buttons, lcltype, strutils, ce_widget, ce_sharedres,
ce_common, ce_interfaces, ce_observer, ce_writableComponent, ce_dubproject, ce_common, ce_interfaces, ce_observer, ce_writableComponent, ce_dubproject,
ce_nativeproject, EditBtn; ce_nativeproject, EditBtn, ce_dialogs;
type type
@ -351,13 +351,23 @@ begin
{$ENDIF} {$ENDIF}
if isValidNativeProject(fname) then if isValidNativeProject(fname) then
begin 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); TCENativeProject.create(nil);
proj := true; proj := true;
end end
else if isValidDubProject(fname) then else if isValidDubProject(fname) then
begin 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); TCEDubProject.create(nil);
proj := true; proj := true;
end; end;