fixes for the widgets that replace the "free project"

This commit is contained in:
Basile Burg 2016-06-13 05:30:49 +02:00
parent ed15c31b57
commit 9a1f542253
4 changed files with 52 additions and 36 deletions

View File

@ -133,6 +133,11 @@ type
(** (**
* An implementer is informed about the current project(s). * An implementer is informed about the current project(s).
* Usually observer should keep track of two ICECOmmonProject:
* - the free project: the project that's not in a group and that has to
* be freed manualy in order to be replaced.
* - the current project which can be either the free project or one of the
* project in the group
*) *)
ICEProjectObserver = interface(ISubjectType) ICEProjectObserver = interface(ISubjectType)
['ICEProjectObserver'] ['ICEProjectObserver']

View File

@ -14,6 +14,7 @@ type
TDDHandler = class(TObject, ICEProjectObserver) TDDHandler = class(TObject, ICEProjectObserver)
private private
fProj: ICECommonProject; fProj: ICECommonProject;
fFreeProj: ICECommonProject;
procedure projNew(aProject: ICECommonProject); procedure projNew(aProject: ICECommonProject);
procedure projChanged(aProject: ICECommonProject); procedure projChanged(aProject: ICECommonProject);
procedure projClosing(aProject: ICECommonProject); procedure projClosing(aProject: ICECommonProject);
@ -52,6 +53,8 @@ end;
procedure TDDHandler.projNew(aProject: ICECommonProject); procedure TDDHandler.projNew(aProject: ICECommonProject);
begin begin
fProj := aProject; fProj := aProject;
if not fProj.inGroup then
fFreeProj := fProj;
end; end;
procedure TDDHandler.projChanged(aProject: ICECommonProject); procedure TDDHandler.projChanged(aProject: ICECommonProject);
@ -60,13 +63,16 @@ end;
procedure TDDHandler.projClosing(aProject: ICECommonProject); procedure TDDHandler.projClosing(aProject: ICECommonProject);
begin begin
if (fProj <> nil) and (fProj = aProject) then fProj := nil;
fProj := nil; if aProject = fFreeProj then
fFreeProj := nil;
end; end;
procedure TDDHandler.projFocused(aProject: ICECommonProject); procedure TDDHandler.projFocused(aProject: ICECommonProject);
begin begin
fProj := aProject; fProj := aProject;
if not fProj.inGroup then
fFreeProj := fProj;
end; end;
procedure TDDHandler.projCompiling(aProject: ICECommonProject); procedure TDDHandler.projCompiling(aProject: ICECommonProject);
@ -128,24 +134,22 @@ begin
if isValidNativeProject(fname) then if isValidNativeProject(fname) then
begin begin
if assigned(fProj) then if assigned(fFreeProj) then
begin begin
if fProj.modified and not fProj.inGroup and if fFreeProj.modified and (dlgFileChangeClose(fFreeProj.filename) = mrCancel) then
(dlgFileChangeClose(fProj.filename) = mrCancel) then exit;
exit; fFreeProj.getProject.Free;
fProj.getProject.Free;
end; 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 if assigned(fFreeProj) and not fFreeProj.inGroup then
begin begin
if fProj.modified and not fProj.inGroup and if fProj.modified and (dlgFileChangeClose(fFreeProj.filename) = mrCancel) then
(dlgFileChangeClose(fProj.filename) = mrCancel) then exit;
exit; fFreeProj.getProject.Free;
fProj.getProject.Free;
end; end;
TCEDubProject.create(nil); TCEDubProject.create(nil);
proj := true; proj := true;

View File

@ -59,6 +59,7 @@ type
); );
private private
fProj: ICECommonProject; fProj: ICECommonProject;
fFreeProj: ICECommonProject;
procedure updateButtonsState; procedure updateButtonsState;
procedure projNew(aProject: ICECommonProject); procedure projNew(aProject: ICECommonProject);
procedure projChanged(aProject: ICECommonProject); procedure projChanged(aProject: ICECommonProject);
@ -121,6 +122,8 @@ end;
procedure TCELibManEditorWidget.projNew(aProject: ICECommonProject); procedure TCELibManEditorWidget.projNew(aProject: ICECommonProject);
begin begin
fProj := aProject; fProj := aProject;
if not aProject.inGroup then
fFreeProj := aProject;
end; end;
procedure TCELibManEditorWidget.projChanged(aProject: ICECommonProject); procedure TCELibManEditorWidget.projChanged(aProject: ICECommonProject);
@ -134,15 +137,17 @@ end;
procedure TCELibManEditorWidget.projClosing(aProject: ICECommonProject); procedure TCELibManEditorWidget.projClosing(aProject: ICECommonProject);
begin begin
if fProj <> aProject then
exit;
fProj := nil; fProj := nil;
if aProject = fFreeProj then
fFreeProj := nil;
updateButtonsState; updateButtonsState;
end; end;
procedure TCELibManEditorWidget.projFocused(aProject: ICECommonProject); procedure TCELibManEditorWidget.projFocused(aProject: ICECommonProject);
begin begin
fProj := aProject; fProj := aProject;
if not aProject.inGroup then
fFreeProj := aProject;
updateButtonsState; updateButtonsState;
end; end;
@ -511,24 +516,22 @@ begin
// //
if isValidNativeProject(fname) then if isValidNativeProject(fname) then
begin begin
if assigned(fProj) then if assigned(fFreeProj) then
begin begin
if fProj.modified and not fProj.inGroup and if fFreeProj.modified and (dlgFileChangeClose(fFreeProj.filename) = mrCancel) then
(dlgFileChangeClose(fProj.filename) = mrCancel) then exit;
exit; fFreeProj.getProject.Free;
fProj.getProject.Free;
end; end;
TCENativeProject.create(nil); TCENativeProject.create(nil);
fProj.loadFromFile(fname); fProj.loadFromFile(fname);
end end
else if isValidDubProject(fname) then else if isValidDubProject(fname) then
begin begin
if assigned(fProj) then if assigned(fFreeProj) then
begin begin
if fProj.modified and not fProj.inGroup and if fFreeProj.modified and (dlgFileChangeClose(fFreeProj.filename) = mrCancel) then
(dlgFileChangeClose(fProj.filename) = mrCancel) then exit;
exit; fFreeProj.getProject.Free;
fProj.getProject.Free;
end; end;
TCEDubProject.create(nil); TCEDubProject.create(nil);
fProj.loadFromFile(fname); fProj.loadFromFile(fname);

View File

@ -85,6 +85,7 @@ type
procedure TreeEnter(Sender: TObject); procedure TreeEnter(Sender: TObject);
private private
fProj: ICECommonProject; fProj: ICECommonProject;
fFreeProj: ICECommonProject;
fFavorites: TStringList; fFavorites: TStringList;
fLastFold: string; fLastFold: string;
fLastListOrTree: TControl; fLastListOrTree: TControl;
@ -307,6 +308,8 @@ end;
procedure TCEMiniExplorerWidget.projNew(aProject: ICECommonProject); procedure TCEMiniExplorerWidget.projNew(aProject: ICECommonProject);
begin begin
fProj := aProject; fProj := aProject;
if not aProject.inGroup then
fFreeProj := aProject;
end; end;
procedure TCEMiniExplorerWidget.projChanged(aProject: ICECommonProject); procedure TCEMiniExplorerWidget.projChanged(aProject: ICECommonProject);
@ -315,13 +318,16 @@ end;
procedure TCEMiniExplorerWidget.projClosing(aProject: ICECommonProject); procedure TCEMiniExplorerWidget.projClosing(aProject: ICECommonProject);
begin begin
if fProj = aProject then fProj := nil;
fProj := nil; if aProject = fFreeProj then
fFreeProj := nil;
end; end;
procedure TCEMiniExplorerWidget.projFocused(aProject: ICECommonProject); procedure TCEMiniExplorerWidget.projFocused(aProject: ICECommonProject);
begin begin
fProj := aProject; fProj := aProject;
if not aProject.inGroup then
fFreeProj := aProject;
if visible and aProject.fileName.fileExists and fContextExpand then if visible and aProject.fileName.fileExists and fContextExpand then
expandPath(aProject.fileName.extractFilePath); expandPath(aProject.fileName.extractFilePath);
end; end;
@ -470,24 +476,22 @@ begin
{$ENDIF} {$ENDIF}
if isValidNativeProject(fname) then if isValidNativeProject(fname) then
begin begin
if assigned(fProj) then if assigned(fFreeProj) then
begin begin
if not fProj.inGroup and fProj.modified and if fFreeProj.modified and (dlgFileChangeClose(fFreeProj.filename) = mrCancel) then
(dlgFileChangeClose(fProj.filename) = mrCancel) then exit;
exit; fFreeProj.getProject.Free;
fProj.getProject.Free;
end; 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 if assigned(fFreeProj) then
begin begin
if not fProj.inGroup and fProj.modified and if fFreeProj.modified and (dlgFileChangeClose(fFreeProj.filename) = mrCancel) then
(dlgFileChangeClose(fProj.filename) = mrCancel) then exit;
exit; fFreeProj.getProject.Free;
fProj.getProject.Free;
end; end;
TCEDubProject.create(nil); TCEDubProject.create(nil);
proj := true; proj := true;