use a nicer dialog to notify about modified content

This commit is contained in:
Basile Burg 2018-01-16 09:25:09 +01:00
parent 147b1da629
commit 4611fc1a4d
1 changed files with 44 additions and 27 deletions

View File

@ -1903,17 +1903,18 @@ end;
procedure TCEMainForm.FormCloseQuery(Sender: TObject; var CanClose: boolean); procedure TCEMainForm.FormCloseQuery(Sender: TObject; var CanClose: boolean);
var var
i: Integer; i: Integer;
files: string = ''; f: string = '';
projs: string = ''; p: string = '';
group: string = #9'no'; g: string = #9'no';
chang: boolean = false; c: boolean = false;
d: TCESynMemo; d: TCESynMemo = nil;
b: TTaskDialogBaseButtonItem = nil;
const const
s: string = 'The following content is modified and changes will be lost'#10#10 + s: string = 'The following content is modified and changes will be lost'#10#10 +
'- Modified files:'#10' %s '#10 + '- Modified files:'#10' %s '#10 +
'- Modified projects:'#10' %s '#10 + '- Modified projects:'#10' %s '#10 +
'- Project group modified:'#10' %s'#10#10 + '- Project group modified:'#10' %s';
'Close without saving ?';
begin begin
canClose := false; canClose := false;
SaveLastDocsAndProj; SaveLastDocsAndProj;
@ -1924,8 +1925,8 @@ begin
if assigned(fFreeProj) and fFreeProj.modified then if assigned(fFreeProj) and fFreeProj.modified then
begin begin
projs += #9 + fFreeProj.filename + LineEnding; p += #9 + fFreeProj.filename + LineEnding;
chang := true; c := true;
end; end;
for i := 0 to fMultidoc.documentCount-1 do for i := 0 to fMultidoc.documentCount-1 do
@ -1934,8 +1935,8 @@ begin
d.disableFileDateCheck := true; d.disableFileDateCheck := true;
if d.modified or (d.fileName = d.tempFilename) then if d.modified or (d.fileName = d.tempFilename) then
begin begin
files += #9 + shortenPath(d.filename) + LineEnding; f += #9 + shortenPath(d.filename) + LineEnding;
chang := true; c := true;
end; end;
end; end;
@ -1943,33 +1944,49 @@ begin
begin begin
if not fProjectGroup.projectModified(i) then if not fProjectGroup.projectModified(i) then
continue; continue;
projs += #9 + shortenPath(fProjectGroup.getProject(i).filename) + LineEnding; p += #9 + shortenPath(fProjectGroup.getProject(i).filename) + LineEnding;
chang := true; c := true;
end; end;
if fProjectGroup.groupModified then if fProjectGroup.groupModified then
begin begin
group := #9'yes'; g := #9'yes';
chang := true; c := true;
end; end;
if chang then if c then
begin begin
BringToFront; BringToFront;
if projs.isEmpty then if p.isEmpty then
projs := '(no modified projects)'#10; p := '(no modified projects)'#10;
if files.isEmpty then if f.isEmpty then
files := '(no modified files)'#10; f := '(no modified files)'#10;
if MessageDlg('Modified content', format(s, [files, projs, group]), with TTaskDialog.Create(nil) do
TMsgDlgType.mtConfirmation, [mbOk, mbCancel], '') <> mrOk then try
begin MainIcon := TTaskDialogIcon.tdiWarning;
for i := 0 to fMultidoc.documentCount-1 do CommonButtons := [];
Text := format(s, [f, p, g]);
b := Buttons.Add;
b.Caption := 'Quit and loose modifications';
b.ModalResult := mrOK;
b := Buttons.Add;
b.Caption := 'Do not quit for now';
b.ModalResult := mrCancel;
if Execute(self.WindowHandle) then
begin begin
d := fMultidoc.getDocument(i); if ModalResult <> mrOk then
d.disableFileDateCheck := false; begin
for i := 0 to fMultidoc.documentCount-1 do
begin
d := fMultidoc.getDocument(i);
d.disableFileDateCheck := false;
end;
exit;
end;
end; end;
exit; finally
free;
end; end;
end; end;