From 837589b2c181efffd1663458b81df110f0a052c1 Mon Sep 17 00:00:00 2001 From: Basile Burg Date: Sat, 14 May 2022 15:40:07 +0200 Subject: [PATCH] fix, LastDocAndProjs, ProjGroups, problem with config indexes --- src/u_main.pas | 43 +++++++++++++++++++++++++++++-------------- src/u_projgroup.pas | 29 ++++++++++++++++++----------- 2 files changed, 47 insertions(+), 25 deletions(-) diff --git a/src/u_main.pas b/src/u_main.pas index 8e0ef773..77c7d9d0 100644 --- a/src/u_main.pas +++ b/src/u_main.pas @@ -1058,25 +1058,33 @@ end; procedure TLastDocsAndProjs.Assign(source: TPersistent); var - grp: IProjectGroup; prj: ICommonProject = nil; - pix: integer; + grp: IProjectGroup; begin if source = MainForm then begin - grp := getProjectGroup; - pix := grp.reloadedProjectIndex; + // freestanding project prj := MainForm.fFreeProj; if prj.isAssigned then begin fProjName := prj.filename; - fProjectConfigIndex := prj.getActiveConfigurationIndex; + // freestanding has the focus + if MainForm.fProj = prj then + begin + fProjectIndex := -1; + fProjectConfigIndex := prj.getActiveConfigurationIndex(); + end; end; - fProjectGroup := getProjectGroup.groupFilename; - if prj = MainForm.fProj then - fProjectIndex := -1 - else - fProjectIndex := pix; + + // group, group item has the focus + grp := getProjectGroup(); + fProjectGroup := grp.groupFilename(); + if fProjectGroup.isNotEmpty() and MainForm.fProj.inGroup() then + begin + fProjectIndex := grp.getProjectIndex(); + fProjectConfigIndex := MainForm.fProj.getActiveConfigurationIndex(); + end; + end else inherited; end; @@ -1093,17 +1101,19 @@ begin dst := TMainForm(target); if dst.fProjFromCommandLine then exit; - - if fProjName.isNotEmpty and fProjName.fileExists then + // reload freestanding + if fProjName.isNotEmpty and fProjName.fileExists() then begin dst.openProj(fProjName); if dst.fProj.isNotAssigned then exit; - hdl := getMultiDocHandler; + // set the highlighter in case one of the reloaded file is a project description + hdl := getMultiDocHandler(); if hdl.isAssigned then mem := hdl.findDocument(dst.fProj.filename); if mem.isAssigned then begin + mem.isProjectDescription:=true; case dst.fProj.getFormat of pfDEXED : mem.Highlighter := LfmSyn; pfDUB : mem.Highlighter := JsSyn; @@ -1112,17 +1122,22 @@ begin end; end; + // reload group grp := getProjectGroup; if fProjectGroup.isNotEmpty and fProjectGroup.fileExists then grp.openGroup(fProjectGroup); + + // activate either freestanding or group item if fProjectIndex.equals(-1) and dst.fFreeProj.isAssigned then - dst.fFreeProj.activate + dst.fFreeProj.activate() else if (fProjectIndex >= 0) and (grp.projectCount > 0) and (fProjectIndex < grp.projectCount) then begin grp.setProjectIndex(fProjectIndex); grp.getProject(grp.getProjectIndex).activate; end; + + // now the right proj should have the focus if assigned(dst.fProj) then dst.fProj.setActiveConfigurationIndex(fProjectConfigIndex); end diff --git a/src/u_projgroup.pas b/src/u_projgroup.pas index 6fbd0e56..38ed4eda 100644 --- a/src/u_projgroup.pas +++ b/src/u_projgroup.pas @@ -31,11 +31,10 @@ type fProj: ICommonProject; fGroup: TProjectGroup; fAsyncMode: TProjectAsyncMode; - function storeConfigIndex: boolean; published property filename: string read fFilename write fFilename; property asyncMode: TProjectAsyncMode read fAsyncMode write fAsyncMode; - property configurationIndex: integer read fConfigIndex write fConfigIndex stored storeConfigIndex; + property configurationIndex: integer read fConfigIndex write fConfigIndex; public property project: ICommonProject read fProj; procedure lazyLoad; @@ -71,6 +70,7 @@ type protected procedure afterLoad; override; procedure afterSave; override; + procedure beforeSave; override; public constructor create(aOwner: TComponent); override; destructor destroy; override; @@ -358,6 +358,20 @@ begin end; end; +procedure TProjectGroup.beforeSave; +var + it: TCollectionItem; + gi: TProjectGroupItem; +begin + inherited; + for it in fItems do + begin + gi := TProjectGroupItem(it); + if assigned(gi.fProj) then + gi.fConfigIndex:= gi.fProj.getActiveConfigurationIndex(); + end; +end; + procedure TProjectGroup.afterSave; begin inherited; @@ -494,14 +508,12 @@ begin if fProj.isAssigned then exit; - //setActiveConfigurationIndex changes the project - //modified flag + //setActiveConfigurationIndex changes the project modified flag projectGroup.saveModified; fProj := loadProject(absoluteFilename, true); fProj.inGroup(true); - if fProj.getFormat = pfDUB then - fProj.setActiveConfigurationIndex(fConfigIndex); + fProj.setActiveConfigurationIndex(fConfigIndex); projectGroup.restoreModified; end; @@ -514,11 +526,6 @@ begin inherited; end; -function TProjectGroupItem.storeConfigIndex: boolean; -begin - exit(fProj.getFormat = pfDUB); -end; - function TProjectGroupItem.absoluteFilename: string; begin if fGroup.fBasePath = '' then