lock project-related actions when compiling + add title to dialogs

This commit is contained in:
Basile Burg 2016-07-07 07:42:45 +02:00
parent 29f264cb18
commit a6997859f0
8 changed files with 95 additions and 39 deletions

View File

@ -11,67 +11,80 @@ uses
(** (**
* Ok/Cancel modal dialog * Ok/Cancel modal dialog
*) *)
function dlgOkCancel(const message: string): TModalResult; function dlgOkCancel(const message: string; title: string = ''): TModalResult;
(** (**
* Yes/No modal dialog * Yes/No modal dialog
*) *)
function dlgYesNo(const message: string): TModalResult; function dlgYesNo(const message: string; title: string = ''): TModalResult;
(** (**
* Info message * Info message
*) *)
function dlgOkInfo(const message: string): TModalResult; function dlgOkInfo(const message: string; title: string = ''): TModalResult;
(** (**
* Error message * Error message
*) *)
function dlgOkError(const message: string): TModalResult; function dlgOkError(const message: string; title: string = ''): TModalResult;
(** (**
* close aFilename Ok/Cancel. * close aFilename Ok/Cancel.
*) *)
function dlgFileChangeClose(const fname: string): TModalResult; function dlgFileChangeClose(fname: string; title: string = ''): TModalResult;
const const
DdiagFilter = 'D source|*.d|D interface|*.di|All files|*.*'; DdiagFilter = 'D source|*.d|D interface|*.di|All files|*.*';
UnsavedFile = 'Modified file';
UnsavedProj = 'Modified project';
UnsavedPGrp = 'Modified project group';
implementation implementation
function dlgOkCancel(const message: string): TModalResult; function dlgOkCancel(const message: string; title: string = ''): TModalResult;
const const
Btns = [mbOK,mbCancel]; Btns = [mbOK,mbCancel];
begin begin
exit( MessageDlg('Coedit', message, mtConfirmation, Btns, '')); if title = '' then
title := 'Coedit';
exit( MessageDlg(title, message, mtConfirmation, Btns, ''));
end; end;
function dlgYesNo(const message: string): TModalResult; function dlgYesNo(const message: string; title: string = ''): TModalResult;
const const
Btns = [mbYes,mbNo]; Btns = [mbYes,mbNo];
begin begin
exit( MessageDlg('Coedit', message, mtConfirmation, Btns, '')); if title = '' then
title := 'Coedit';
exit( MessageDlg(title, message, mtConfirmation, Btns, ''));
end; end;
function dlgOkInfo(const message: string): TModalResult; function dlgOkInfo(const message: string; title: string = ''): TModalResult;
const const
Btns = [mbOK]; Btns = [mbOK];
begin begin
exit( MessageDlg('Coedit', message, mtInformation, Btns, '')); if title = '' then
title := 'Coedit';
exit( MessageDlg(title, message, mtInformation, Btns, ''));
end; end;
function dlgOkError(const message: string): TModalResult; function dlgOkError(const message: string; title: string = ''): TModalResult;
const const
Btns = [mbOK]; Btns = [mbOK];
begin begin
exit( MessageDlg('Coedit', message, mtError, Btns, '')); if title = '' then
title := 'Coedit';
exit(MessageDlg(title, message, mtError, Btns, ''));
end; end;
function dlgFileChangeClose(const fname: string): TModalResult; function dlgFileChangeClose(fname: string; title: string = ''): TModalResult;
const const
fmt = '"%s" latest modifications are not saved.'#13#10#13#10'Close it without saving ?'; fmt = '"%s" latest modifications are not saved.'#13#10#13#10'Close it without saving ?';
begin begin
exit(dlgOkCancel(format(fmt, [fname]))); if fname = '' then
fname := '<not saved yet>';
exit(dlgOkCancel(format(fmt, [fname]), title));
end; end;
end. end.

View File

@ -489,7 +489,7 @@ begin
doc := getDocument(index); doc := getDocument(index);
if doc.isNil then exit(false); if doc.isNil then exit(false);
if (doc.modified or (doc.fileName = doc.tempFilename)) and if (doc.modified or (doc.fileName = doc.tempFilename)) and
(dlgFileChangeClose(doc.fileName) = mrCancel) then exit(false); (dlgFileChangeClose(doc.fileName, UnsavedFile) = mrCancel) then exit(false);
doc.disableFileDateCheck:=true; doc.disableFileDateCheck:=true;
pageControl.pageIndex:=index; pageControl.pageIndex:=index;
doc.Free; doc.Free;

View File

@ -137,7 +137,7 @@ begin
begin begin
if assigned(fFreeProj) then if assigned(fFreeProj) then
begin begin
if fFreeProj.modified and (dlgFileChangeClose(fFreeProj.filename) = mrCancel) then if fFreeProj.modified and (dlgFileChangeClose(fFreeProj.filename, UnsavedProj) = mrCancel) then
exit; exit;
fFreeProj.getProject.Free; fFreeProj.getProject.Free;
end; end;

View File

@ -62,7 +62,7 @@ type
property libFile: string read fLibFile write setLibFile; property libFile: string read fLibFile write setLibFile;
property libProject: string read fLibProject write setLibProject; property libProject: string read fLibProject write setLibProject;
property enabled: boolean read fEnabled write fEnabled default true; property enabled: boolean read fEnabled write fEnabled default true;
// TODO-cmaintenace: remove this property from 3 update 1 // TODO-cmaintenance: remove this property from 3 update 1
property projectFile: string read fLibProject write fLibProject stored false; property projectFile: string read fLibProject write fLibProject stored false;
public public
constructor Create(ACollection: TCollection); override; constructor Create(ACollection: TCollection); override;

View File

@ -569,7 +569,7 @@ begin
begin begin
if assigned(fFreeProj) then if assigned(fFreeProj) then
begin begin
if fFreeProj.modified and (dlgFileChangeClose(fFreeProj.filename) = mrCancel) then if fFreeProj.modified and (dlgFileChangeClose(fFreeProj.filename, UnsavedProj) = mrCancel) then
exit; exit;
fFreeProj.getProject.Free; fFreeProj.getProject.Free;
end; end;

View File

@ -313,6 +313,7 @@ type
fMsgs: ICEMessagesDisplay; fMsgs: ICEMessagesDisplay;
fMainMenuSubj: TCEMainMenuSubject; fMainMenuSubj: TCEMainMenuSubject;
fAppliOpts: TCEApplicationOptions; fAppliOpts: TCEApplicationOptions;
fProjActionsLock: boolean;
procedure updateMainMenuProviders; procedure updateMainMenuProviders;
procedure updateFloatingWidgetOnTop(onTop: boolean); procedure updateFloatingWidgetOnTop(onTop: boolean);
@ -380,8 +381,9 @@ type
procedure saveProj; procedure saveProj;
procedure saveProjAs(const aFilename: string); procedure saveProjAs(const aFilename: string);
procedure openProj(const aFilename: string); procedure openProj(const aFilename: string);
procedure closeProj; function closeProj: boolean;
procedure showProjTitle; procedure showProjTitle;
function checkProjectLock(message: boolean = true): boolean;
// mru // mru
procedure mruChange(Sender: TObject); procedure mruChange(Sender: TObject);
@ -1459,7 +1461,7 @@ begin
if (fFreeProj <> nil) then if (fFreeProj <> nil) then
begin begin
if fFreeProj.modified and if fFreeProj.modified and
(dlgFileChangeClose(fFreeProj.filename) = mrCancel) then (dlgFileChangeClose(fFreeProj.filename, UnsavedProj) = mrCancel) then
exit; exit;
fFreeProj.getProject.Free; fFreeProj.getProject.Free;
fFreeProj := nil; fFreeProj := nil;
@ -1467,7 +1469,7 @@ begin
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;
if fProjectGroup.groupModified then if if fProjectGroup.groupModified then if
(dlgFileChangeClose(fProjectGroup.groupFilename) = mrCancel) then exit; (dlgFileChangeClose(fProjectGroup.groupFilename, UnsavedPGrp) = mrCancel) then exit;
canClose := true; canClose := true;
fProjectGroup.closeGroup; fProjectGroup.closeGroup;
end; end;
@ -1479,7 +1481,7 @@ end;
procedure TCEMainForm.updateProjectBasedAction(sender: TObject); procedure TCEMainForm.updateProjectBasedAction(sender: TObject);
begin begin
TAction(sender).Enabled := fProject <> nil; TAction(sender).Enabled := (fProject <> nil) {and not fProjActionsLock};
end; end;
procedure TCEMainForm.updateDocEditBasedAction(sender: TObject); procedure TCEMainForm.updateDocEditBasedAction(sender: TObject);
@ -1660,6 +1662,7 @@ end;
procedure TCEMainForm.projCompiling(aProject: ICECommonProject); procedure TCEMainForm.projCompiling(aProject: ICECommonProject);
begin begin
fProjActionsLock := true;
end; end;
procedure TCEMainForm.projCompiled(aProject: ICECommonProject; success: boolean); procedure TCEMainForm.projCompiled(aProject: ICECommonProject; success: boolean);
@ -1668,6 +1671,7 @@ var
runprev: boolean = true; runprev: boolean = true;
i: integer; i: integer;
begin begin
fProjActionsLock := false;
if not fIsCompilingGroup then if not fIsCompilingGroup then
begin begin
if fRunProjAfterCompile and assigned(fProject) then if fRunProjAfterCompile and assigned(fProject) then
@ -2807,6 +2811,18 @@ end;
{$ENDREGION} {$ENDREGION}
{$REGION project ---------------------------------------------------------------} {$REGION project ---------------------------------------------------------------}
function TCEMainForm.checkProjectLock(message: boolean = true): boolean;
begin
result := false;
if fProjActionsLock then
begin
result := true;
if message then
dlgOkInfo('This action is disabled while a project compiles',
'Project lock warning');
end
end;
procedure TCEMainForm.showProjTitle; procedure TCEMainForm.showProjTitle;
begin begin
if (fProject <> nil) and fProject.filename.fileExists then if (fProject <> nil) and fProject.filename.fileExists then
@ -2821,6 +2837,7 @@ var
begin begin
if fProject = nil then exit; if fProject = nil then exit;
if fProject.filename <> aEditor.fileName then exit; if fProject.filename <> aEditor.fileName then exit;
if checkProjectLock then exit;
// //
fname := fProject.filename; fname := fProject.filename;
fProject.getProject.Free; fProject.getProject.Free;
@ -2828,12 +2845,15 @@ begin
openProj(fname); openProj(fname);
end; end;
procedure TCEMainForm.closeProj; function TCEMainForm.closeProj: boolean;
begin begin
result := true;
if fProject = nil then exit; if fProject = nil then exit;
result := false;
// //
if fProject = fFreeProj then if fProject = fFreeProj then
begin begin
if checkProjectLock then exit;
fProject.getProject.Free; fProject.getProject.Free;
fFreeProj := nil; fFreeProj := nil;
end; end;
@ -2841,14 +2861,16 @@ begin
fNativeProject := nil; fNativeProject := nil;
fDubProject := nil; fDubProject := nil;
showProjTitle; showProjTitle;
result := true;
end; end;
procedure TCEMainForm.actProjNewDubJsonExecute(Sender: TObject); procedure TCEMainForm.actProjNewDubJsonExecute(Sender: TObject);
begin begin
if (fProject <> nil) and not fProject.inGroup if (fProject <> nil) and not fProject.inGroup
and fProject.modified and and fProject.modified and
(dlgFileChangeClose(fProject.filename) = mrCancel) then exit; (dlgFileChangeClose(fProject.filename, UnsavedProj) = mrCancel) then exit;
closeProj; if not closeProj then
exit;
newDubProj; newDubProj;
end; end;
@ -2856,8 +2878,9 @@ procedure TCEMainForm.actProjNewNativeExecute(Sender: TObject);
begin begin
if (fProject <> nil) and not fProject.inGroup if (fProject <> nil) and not fProject.inGroup
and fProject.modified and and fProject.modified and
(dlgFileChangeClose(fProject.filename) = mrCancel) then exit; (dlgFileChangeClose(fProject.filename, UnsavedProj) = mrCancel) then exit;
closeProj; if not closeProj then
exit;
newNativeProj; newNativeProj;
end; end;
@ -2892,7 +2915,8 @@ end;
procedure TCEMainForm.openProj(const aFilename: string); procedure TCEMainForm.openProj(const aFilename: string);
begin begin
closeProj; if not closeProj then
exit;
if aFilename.extractFileExt.upperCase = '.JSON' then if aFilename.extractFileExt.upperCase = '.JSON' then
newDubProj newDubProj
else else
@ -2904,21 +2928,25 @@ end;
procedure TCEMainForm.mruProjItemClick(Sender: TObject); procedure TCEMainForm.mruProjItemClick(Sender: TObject);
begin begin
if checkProjectLock then
exit;
if (fProject <> nil) and not fProject.inGroup and if (fProject <> nil) and not fProject.inGroup and
fProject.modified and fProject.modified and
(dlgFileChangeClose(fProject.filename) = mrCancel) then exit; (dlgFileChangeClose(fProject.filename, UnsavedProj) = 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 (fProject <> nil) and not fProject.inGroup and fProject.modified and if (fProject <> nil) and not fProject.inGroup and fProject.modified and
(dlgFileChangeClose(fProject.filename) = mrCancel) then exit; (dlgFileChangeClose(fProject.filename, UnsavedProj) = mrCancel) then exit;
closeProj; closeProj;
end; end;
procedure TCEMainForm.actProjSaveAsExecute(Sender: TObject); procedure TCEMainForm.actProjSaveAsExecute(Sender: TObject);
begin begin
if checkProjectLock then
exit;
with TSaveDialog.Create(nil) do with TSaveDialog.Create(nil) do
try try
if execute then saveProjAs(filename); if execute then saveProjAs(filename);
@ -2930,14 +2958,18 @@ end;
procedure TCEMainForm.actProjSaveExecute(Sender: TObject); procedure TCEMainForm.actProjSaveExecute(Sender: TObject);
begin begin
if fProject = nil then exit; if fProject = nil then exit;
if checkProjectLock then
exit;
if fProject.filename.isNotEmpty then saveProj if fProject.filename.isNotEmpty then saveProj
else actProjSaveAs.Execute; else actProjSaveAs.Execute;
end; end;
procedure TCEMainForm.actProjOpenExecute(Sender: TObject); procedure TCEMainForm.actProjOpenExecute(Sender: TObject);
begin begin
if checkProjectLock then
exit;
if (fProject <> nil) and fProject.modified and if (fProject <> nil) and fProject.modified and
(dlgFileChangeClose(fProject.filename) = mrCancel) then exit; (dlgFileChangeClose(fProject.filename, UnsavedProj) = 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);
@ -2978,14 +3010,14 @@ end;
procedure TCEMainForm.actProjOptViewExecute(Sender: TObject); procedure TCEMainForm.actProjOptViewExecute(Sender: TObject);
begin begin
if fProject = nil then exit; if fProject = nil then exit;
dlgOkInfo(fProject.getCommandLine); dlgOkInfo(fProject.getCommandLine, 'Compilation command line');
end; end;
procedure TCEMainForm.actProjOpenGroupExecute(Sender: TObject); procedure TCEMainForm.actProjOpenGroupExecute(Sender: TObject);
begin begin
if fProjectGroup.groupModified then if fProjectGroup.groupModified then
begin begin
if dlgFileChangeClose(fProjectGroup.groupFilename) = mrCancel then if dlgFileChangeClose(fProjectGroup.groupFilename, UnsavedPGrp) = mrCancel then
exit; exit;
end; end;
fProjectGroup.closeGroup; fProjectGroup.closeGroup;
@ -3027,7 +3059,7 @@ procedure TCEMainForm.actNewGroupExecute(Sender: TObject);
begin begin
if fProjectGroup.groupModified then if fProjectGroup.groupModified then
begin begin
if dlgFileChangeClose(fProjectGroup.groupFilename) = mrCancel then if dlgFileChangeClose(fProjectGroup.groupFilename, UnsavedPGrp) = mrCancel then
exit; exit;
end; end;
fProjectGroup.closeGroup; fProjectGroup.closeGroup;
@ -3043,10 +3075,17 @@ begin
fFreeProj := nil; fFreeProj := nil;
end; end;
// TODO-cFIleOpenDialog: allow multi selection when possible
//(open file, add file to project, ...)
// TODO-cprojectgroup: handle invalid projects filename when reloading a group
procedure TCEMainForm.actProjGroupCompileExecute(Sender: TObject); procedure TCEMainForm.actProjGroupCompileExecute(Sender: TObject);
var var
i: integer; i: integer;
begin begin
if checkProjectLock then
exit;
if fProjectGroup.projectCount = 0 then if fProjectGroup.projectCount = 0 then
exit; exit;
fGroupCompilationCnt := 0; fGroupCompilationCnt := 0;
@ -3064,7 +3103,7 @@ procedure TCEMainForm.actProjNewGroupExecute(Sender: TObject);
begin begin
if fProjectGroup.groupModified then if fProjectGroup.groupModified then
begin begin
if dlgFileChangeClose(fProjectGroup.groupFilename) = mrCancel then if dlgFileChangeClose(fProjectGroup.groupFilename, UnsavedPGrp) = mrCancel then
exit; exit;
end; end;
fProjectGroup.closeGroup; fProjectGroup.closeGroup;

View File

@ -486,7 +486,7 @@ begin
begin begin
if assigned(fFreeProj) then if assigned(fFreeProj) then
begin begin
if fFreeProj.modified and (dlgFileChangeClose(fFreeProj.filename) = mrCancel) then if fFreeProj.modified and (dlgFileChangeClose(fFreeProj.filename, UnsavedProj) = mrCancel) then
exit; exit;
fFreeProj.getProject.Free; fFreeProj.getProject.Free;
end; end;

View File

@ -1175,6 +1175,10 @@ begin
end; end;
procedure TCESynMemo.ShowPhobosDoc; procedure TCESynMemo.ShowPhobosDoc;
procedure errorMessage;
begin
dlgOkError('html documentation cannot be found for "' + Identifier + '"');
end;
var var
str: string; str: string;
pth: string; pth: string;
@ -1190,7 +1194,7 @@ begin
DcdWrapper.getDeclFromCursor(str, pos); DcdWrapper.getDeclFromCursor(str, pos);
if not str.fileExists then if not str.fileExists then
begin begin
dlgOkInfo('html documentation cannot be found for "' + Identifier + '"'); errorMessage;
exit; exit;
end; end;
// verify that the decl is in phobos // verify that the decl is in phobos
@ -1199,7 +1203,7 @@ begin
begin begin
if pth.extractFilePath = pth then if pth.extractFilePath = pth then
begin begin
dlgOkInfo('html documentation cannot be found for "' + Identifier + '"'); errorMessage;
exit; exit;
end; end;
pth := pth.extractFilePath; pth := pth.extractFilePath;