mirror of https://gitlab.com/basile.b/dexed.git
display summary of unsaved content on exit
This commit is contained in:
parent
8ef75e82b0
commit
6d48342da0
|
@ -161,8 +161,8 @@ type
|
||||||
function getDocument(index: Integer): TCESynMemo;
|
function getDocument(index: Integer): TCESynMemo;
|
||||||
function findDocument(const fname: string): TCESynMemo;
|
function findDocument(const fname: string): TCESynMemo;
|
||||||
procedure openDocument(const fname: string);
|
procedure openDocument(const fname: string);
|
||||||
function closeDocument(index: Integer): boolean;
|
function closeDocument(index: Integer;promptOnChanged: boolean = true): boolean;
|
||||||
function closeDocument(doc: TCESynMemo): boolean;
|
function closeDocument(doc: TCESynMemo;promptOnChanged: boolean = true): boolean;
|
||||||
public
|
public
|
||||||
constructor create(aOwner: TComponent); override;
|
constructor create(aOwner: TComponent); override;
|
||||||
destructor destroy; override;
|
destructor destroy; override;
|
||||||
|
@ -509,14 +509,14 @@ begin
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TCEEditorWidget.closeDocument(index: Integer): boolean;
|
function TCEEditorWidget.closeDocument(index: Integer; promptOnChanged: boolean = true): boolean;
|
||||||
var
|
var
|
||||||
doc: TCESynMemo;
|
doc: TCESynMemo;
|
||||||
begin
|
begin
|
||||||
doc := getDocument(index);
|
doc := getDocument(index);
|
||||||
if doc.isNil then
|
if doc.isNil then
|
||||||
exit(false);
|
exit(false);
|
||||||
if (doc.modified or (doc.fileName = doc.tempFilename)) and
|
if promptOnChanged and (doc.modified or (doc.fileName = doc.tempFilename)) and
|
||||||
(dlgFileChangeClose(doc.fileName, UnsavedFile) = mrCancel) then
|
(dlgFileChangeClose(doc.fileName, UnsavedFile) = mrCancel) then
|
||||||
exit(false);
|
exit(false);
|
||||||
showWidget;
|
showWidget;
|
||||||
|
@ -526,14 +526,14 @@ begin
|
||||||
result := true;
|
result := true;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TCEEditorWidget.closeDocument(doc: TCESynMemo): boolean;
|
function TCEEditorWidget.closeDocument(doc: TCESynMemo;promptOnChanged: boolean = true): boolean;
|
||||||
var
|
var
|
||||||
page: TCEPage = nil;
|
page: TCEPage = nil;
|
||||||
begin
|
begin
|
||||||
page := TCEPage(doc.Parent);
|
page := TCEPage(doc.Parent);
|
||||||
if page.isNil then
|
if page.isNil then
|
||||||
exit(false);
|
exit(false);
|
||||||
exit(closeDocument(page.index));
|
exit(closeDocument(page.index, promptOnChanged));
|
||||||
end;
|
end;
|
||||||
{$ENDREGION}
|
{$ENDREGION}
|
||||||
|
|
||||||
|
|
|
@ -275,9 +275,9 @@ type
|
||||||
// opens or set the focus on the document matching aFilename.
|
// opens or set the focus on the document matching aFilename.
|
||||||
procedure openDocument(const fname: string);
|
procedure openDocument(const fname: string);
|
||||||
// closes the nth document.
|
// closes the nth document.
|
||||||
function closeDocument(index: Integer): boolean;
|
function closeDocument(index: Integer; promptOnChanged: boolean = true): boolean;
|
||||||
// closes a particular document.
|
// closes a particular document.
|
||||||
function closeDocument(doc: TCESynMemo): boolean;
|
function closeDocument(doc: TCESynMemo; promptOnChanged: boolean = true): boolean;
|
||||||
// conveniance property.
|
// conveniance property.
|
||||||
property document[index: integer]: TCESynMemo read getDocument;
|
property document[index: integer]: TCESynMemo read getDocument;
|
||||||
end;
|
end;
|
||||||
|
@ -306,6 +306,8 @@ type
|
||||||
function getProjectIndex: integer;
|
function getProjectIndex: integer;
|
||||||
// returns the nth project.
|
// returns the nth project.
|
||||||
function getProject(index: Integer): ICECommonProject;
|
function getProject(index: Integer): ICECommonProject;
|
||||||
|
// returns true if the nth project is modified
|
||||||
|
function projectModified(index: integer): boolean;
|
||||||
// tries to find the project named fname.
|
// tries to find the project named fname.
|
||||||
function findProject(const fname: string): ICECommonProject;
|
function findProject(const fname: string): ICECommonProject;
|
||||||
// selects the nth project of the group.
|
// selects the nth project of the group.
|
||||||
|
@ -336,8 +338,6 @@ type
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|
||||||
// TODO-cOptions: widgets that expose options can use ICEOptionsEditor in their ctxt menu
|
|
||||||
|
|
||||||
(**
|
(**
|
||||||
* Single service provided by the options editor.
|
* Single service provided by the options editor.
|
||||||
*)
|
*)
|
||||||
|
|
|
@ -1836,6 +1836,17 @@ 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 = '';
|
||||||
|
projs: string = '';
|
||||||
|
group: string = #9'no';
|
||||||
|
chang: boolean = false;
|
||||||
|
d: TCESynMemo;
|
||||||
|
const
|
||||||
|
s: string = 'The following content is modified and changes will be lost'#10#10 +
|
||||||
|
'- Modified files:'#10' %s '#10 +
|
||||||
|
'- Modified projects:'#10' %s '#10 +
|
||||||
|
'- Project group modified:'#10' %s'#10#10 +
|
||||||
|
'Close without saving ?';
|
||||||
begin
|
begin
|
||||||
canClose := false;
|
canClose := false;
|
||||||
SaveLastDocsAndProj;
|
SaveLastDocsAndProj;
|
||||||
|
@ -1844,22 +1855,54 @@ begin
|
||||||
(dlgOkCancel('A project is still being compiled, close anyway ?') <> mrOK) then
|
(dlgOkCancel('A project is still being compiled, close anyway ?') <> mrOK) then
|
||||||
exit;
|
exit;
|
||||||
|
|
||||||
if assigned(fFreeProj) then
|
if assigned(fFreeProj) and fFreeProj.modified then
|
||||||
begin
|
begin
|
||||||
if fFreeProj.modified and
|
projs += #9 + fFreeProj.filename + LineEnding;
|
||||||
(dlgFileChangeClose(fFreeProj.filename, UnsavedProj) = mrCancel) then
|
chang := true;
|
||||||
exit;
|
|
||||||
fFreeProj.getProject.Free;
|
|
||||||
fFreeProj := nil;
|
|
||||||
end;
|
end;
|
||||||
for i := fMultidoc.documentCount-1 downto 0 do
|
|
||||||
if not fMultidoc.closeDocument(i) then
|
for i := 0 to fMultidoc.documentCount-1 do
|
||||||
|
begin
|
||||||
|
d := fMultidoc.getDocument(i);
|
||||||
|
if d.modified then
|
||||||
|
begin
|
||||||
|
files += #9 + shortenPath(d.filename) + LineEnding;
|
||||||
|
chang := true;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
for i:= 0 to fProjectGroup.projectCount-1 do
|
||||||
|
begin
|
||||||
|
if not fProjectGroup.projectModified(i) then
|
||||||
|
continue;
|
||||||
|
projs += #9 + shortenPath(fProjectGroup.getProject(i).filename) + LineEnding;
|
||||||
|
chang := true;
|
||||||
|
end;
|
||||||
|
|
||||||
|
if fProjectGroup.groupModified then
|
||||||
|
begin
|
||||||
|
group := #9'yes';
|
||||||
|
chang := true;
|
||||||
|
end;
|
||||||
|
|
||||||
|
if chang then
|
||||||
|
begin
|
||||||
|
if projs.isEmpty then
|
||||||
|
projs := '(no modified projects)'#10;
|
||||||
|
if files.isEmpty then
|
||||||
|
files := '(no modified files)'#10;
|
||||||
|
|
||||||
|
if MessageDlg('Modified content', format(s, [files, projs, group]),
|
||||||
|
TMsgDlgType.mtConfirmation, [mbOk, mbCancel], '') <> mrOk then
|
||||||
exit;
|
exit;
|
||||||
if fProjectGroup.groupModified and
|
end;
|
||||||
(dlgFileChangeClose(fProjectGroup.groupFilename, UnsavedPGrp) = mrCancel) then
|
|
||||||
exit;
|
CanClose:= true;
|
||||||
canClose := true;
|
|
||||||
fProjectGroup.closeGroup;
|
fProjectGroup.closeGroup;
|
||||||
|
if assigned(fFreeProj) then
|
||||||
|
fFreeProj.getProject.Free;
|
||||||
|
for i:= fMultidoc.documentCount-1 downto 0 do
|
||||||
|
fMultidoc.closeDocument(i, false);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TCEMainForm.updateDocumentBasedAction(sender: TObject);
|
procedure TCEMainForm.updateDocumentBasedAction(sender: TObject);
|
||||||
|
|
|
@ -85,7 +85,8 @@ type
|
||||||
function getProject(ix: Integer): ICECommonProject;
|
function getProject(ix: Integer): ICECommonProject;
|
||||||
function findProject(const fname: string): ICECommonProject;
|
function findProject(const fname: string): ICECommonProject;
|
||||||
procedure setProjectIndex(value: Integer);
|
procedure setProjectIndex(value: Integer);
|
||||||
function projectIsAsync(index: integer): boolean;
|
function projectIsAsync(ix: integer): boolean;
|
||||||
|
function projectModified(ix: integer): boolean;
|
||||||
//
|
//
|
||||||
function addItem(const fname: string): TProjectGroupItem;
|
function addItem(const fname: string): TProjectGroupItem;
|
||||||
property item[ix: integer]: TProjectGroupItem read getItem; default;
|
property item[ix: integer]: TProjectGroupItem read getItem; default;
|
||||||
|
@ -245,9 +246,9 @@ begin
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TProjectGroup.projectIsAsync(index: integer): boolean;
|
function TProjectGroup.projectIsAsync(ix: integer): boolean;
|
||||||
begin
|
begin
|
||||||
exit(item[index].asyncMode = amParallel);
|
exit(item[ix].asyncMode = amParallel);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TProjectGroup.addItem(const fname: string): TProjectGroupItem;
|
function TProjectGroup.addItem(const fname: string): TProjectGroupItem;
|
||||||
|
@ -284,6 +285,16 @@ begin
|
||||||
result.setActiveConfigurationIndex(item[ix].configurationIndex);
|
result.setActiveConfigurationIndex(item[ix].configurationIndex);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TProjectGroup.projectModified(ix: integer): boolean;
|
||||||
|
var
|
||||||
|
p: ICECommonProject;
|
||||||
|
begin
|
||||||
|
result := false;
|
||||||
|
p := item[ix].project;
|
||||||
|
if assigned(p) and (p.modified) then
|
||||||
|
result := true
|
||||||
|
end;
|
||||||
|
|
||||||
function TProjectGroup.findProject(const fname: string): ICECommonProject;
|
function TProjectGroup.findProject(const fname: string): ICECommonProject;
|
||||||
var
|
var
|
||||||
i: integer;
|
i: integer;
|
||||||
|
@ -407,7 +418,7 @@ var
|
||||||
b: boolean = false;
|
b: boolean = false;
|
||||||
begin
|
begin
|
||||||
for i:= 0 to fItems.Count-1 do
|
for i:= 0 to fItems.Count-1 do
|
||||||
if (getItem(i).fProj <> nil) and getItem(i).fProj.modified then
|
if projectModified(i) then
|
||||||
begin
|
begin
|
||||||
b := true;
|
b := true;
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in New Issue