From fa4e2b3cf8261dc0747269b189989ae35739553f Mon Sep 17 00:00:00 2001 From: Basile Burg Date: Tue, 8 Sep 2015 00:13:40 +0200 Subject: [PATCH] work on #10, dub support - configs and built types are combined - widget split in two pages: editor and inspector - inspector displays the combined configs --- src/ce_dubproject.pas | 85 +++++++++++++++-- src/ce_dubprojeditor.lfm | 195 +++++++++++++++++++++++++++------------ src/ce_dubprojeditor.pas | 69 +++++++++++--- 3 files changed, 271 insertions(+), 78 deletions(-) diff --git a/src/ce_dubproject.pas b/src/ce_dubproject.pas index 78cb25ac..a8b99229 100644 --- a/src/ce_dubproject.pas +++ b/src/ce_dubproject.pas @@ -10,13 +10,23 @@ uses type + TUpdaterTarget = (configs, files); + TCEDubProject = class(TComponent, ICECommonProject) private fFilename: string; fModified: boolean; fJson: TJSONObject; fProjectSubject: TCEProjectSubject; + fConfigsCount: integer; + fBuildTypes: TStringList; + fConfigs: TStringList; + fBuiltTypeIx: integer; + fConfigIx: integer; // + procedure updateFields; + procedure udpateConfigsFromJson; + procedure updateSourcesFromJson; procedure dubProcOutput(proc: TProcess); // function getFormat: TCEProjectFormat; @@ -45,12 +55,23 @@ type property json: TJSONObject read fJson; end; + // these 9 built types alway exist + TDubBuildType = (plain, debug, release, unittest, docs, ddox, profile, cov, unittestcov); + +const + + DubBuiltTypeName: array[TDubBuildType] of string = ('plain', 'debug', 'release', + 'unittest', 'docs', 'ddox', 'profile', 'cov', 'unittest-cov' + ); + implementation constructor TCEDubProject.create(aOwner: TComponent); begin inherited; fProjectSubject := TCEProjectSubject.Create; + fBuildTypes := TStringList.Create; + fConfigs := TStringList.Create; // subjProjNew(fProjectSubject, self); subjProjChanged(fProjectSubject, self); @@ -62,6 +83,8 @@ begin fProjectSubject.free; // fJSon.Free; + fBuildTypes.Free; + fConfigs.Free; inherited; end; @@ -97,6 +120,52 @@ begin exit(fFilename); end; +procedure TCEDubProject.udpateConfigsFromJson; +var + i: integer; + builtTypes: TJSONArray = nil; + configs: TJSONArray = nil; + item: TJSONObject = nil; +begin + fBuildTypes.Clear; + fConfigs.Clear; + + // configs: builtype0 - config0, builtype0 - config1, ... , builtype0 - configN + // builtype1 - config0, builtype1 - config1, ... , builtype1 - configN, etc + fConfigs.Add('(dub default)'); // default + if fJson.Find('configurations') <> nil then + begin + configs := fJson.Arrays['configurations']; + for i:= 0 to configs.Count-1 do + begin + item := TJSONObject(configs.Items[i]); + fConfigs.Add(item.Strings['name']); + end; + end; + fBuildTypes.AddStrings(DubBuiltTypeName); + if fJson.Find('buildTypes') <> nil then + begin + builtTypes := fJson.Arrays['buildTypes']; + for i := 0 to builtTypes.Count-1 do + begin + item := TJSONObject(builtTypes.Items[i]); + fBuildTypes.Add(item.Strings['name']); + end; + end; + fConfigsCount := fConfigs.Count * fBuildTypes.Count; +end; + +procedure TCEDubProject.updateSourcesFromJson; +begin + //TODO-cDUB: update the source files for the current configuration +end; + +procedure TCEDubProject.updateFields; +begin + udpateConfigsFromJson; + updateSourcesFromJson; +end; + function TCEDubProject.getBinaryKind: TProjectBinaryKind; begin //TODO-cDUB: implement @@ -121,6 +190,7 @@ begin end; finally loader.Free; + updateFields; subjProjChanged(fProjectSubject, self); fModified := false; end; @@ -150,31 +220,32 @@ end; function TCEDubProject.getIfIsSource(const aFilename: string): boolean; begin - //TODO-cDUB: implement + //TODO-cDUB: implement getIfIsSource exit(false); end; function TCEDubProject.getOutputFilename: string; begin - //TODO-cDUB: implement + //TODO-cDUB: implement getOutputFilename exit(''); end; function TCEDubProject.getConfigurationCount: integer; begin - //TODO-cDUB: implement - exit(0); + exit(fConfigsCount); end; procedure TCEDubProject.setActiveConfiguration(index: integer); begin - //TODO-cDUB: implement + fBuiltTypeIx := index div fConfigs.Count; + fConfigIx := index mod fConfigs.Count; + updateSourcesFromJson; end; function TCEDubProject.getConfigurationName(index: integer): string; begin - //TODO-cDUB: implement - exit(''); + result := fBuildTypes.Strings[index div fConfigs.Count] + ' - ' + + fConfigs.Strings[index mod fConfigs.Count]; end; function TCEDubProject.compile: boolean; diff --git a/src/ce_dubprojeditor.lfm b/src/ce_dubprojeditor.lfm index aa5a0b67..ca7225b2 100644 --- a/src/ce_dubprojeditor.lfm +++ b/src/ce_dubprojeditor.lfm @@ -1,78 +1,153 @@ inherited CEDubProjectEditorWidget: TCEDubProjectEditorWidget Left = 816 - Height = 417 + Height = 557 Top = 191 Width = 411 - ClientHeight = 417 + Caption = 'Dub project editor' + ClientHeight = 557 ClientWidth = 411 inherited Back: TPanel - Height = 417 + Height = 557 Width = 411 - ClientHeight = 417 + ClientHeight = 557 ClientWidth = 411 inherited Content: TPanel - Height = 417 + Height = 557 Width = 411 - ClientHeight = 417 + ClientHeight = 557 ClientWidth = 411 - object pnlToolBar: TPanel[0] + object PageControl1: TPageControl[0] Left = 4 - Height = 26 - Top = 2 - Width = 403 - Align = alTop - BorderSpacing.Left = 2 - BorderSpacing.Right = 2 - BorderSpacing.Around = 2 - BevelOuter = bvNone - ClientHeight = 26 - ClientWidth = 403 - TabOrder = 0 - object btnAddProp: TSpeedButton - Left = 0 - Height = 26 - Hint = 'add an empty configuration' - Top = 0 - Width = 28 - Align = alLeft - Layout = blGlyphBottom - ShowCaption = False - end - object btnDelProp: TSpeedButton - Left = 28 - Height = 26 - Hint = 'remove selected configuration' - Top = 0 - Width = 28 - Align = alLeft - Layout = blGlyphBottom - ShowCaption = False - end - end - object propTree: TTreeView[1] - Left = 4 - Height = 284 - Top = 32 + Height = 549 + Top = 4 Width = 403 + ActivePage = TabSheet1 Align = alClient BorderSpacing.Around = 4 - DefaultItemHeight = 18 - HideSelection = False - ReadOnly = True - ScrollBars = ssAutoBoth - TabOrder = 1 - OnSelectionChanged = propTreeSelectionChanged - Options = [tvoAutoItemHeight, tvoKeepCollapsedNodes, tvoReadOnly, tvoShowButtons, tvoShowLines, tvoShowRoot, tvoToolTips, tvoThemedDraw] - end - object edValue: TMemo[2] - Left = 4 - Height = 93 - Top = 320 - Width = 403 - Align = alBottom - BorderSpacing.Around = 4 - ScrollBars = ssAutoVertical - TabOrder = 2 + TabIndex = 0 + TabOrder = 0 + object TabSheet1: TTabSheet + Caption = 'Inspector' + ClientHeight = 521 + ClientWidth = 395 + object pnlToolBar1: TPanel + Left = 4 + Height = 26 + Top = 2 + Width = 387 + Align = alTop + BorderSpacing.Left = 2 + BorderSpacing.Right = 2 + BorderSpacing.Around = 2 + BevelOuter = bvNone + ClientHeight = 26 + ClientWidth = 387 + TabOrder = 0 + object btnAddProp1: TSpeedButton + Left = 0 + Height = 26 + Hint = 'add an empty configuration' + Top = 0 + Width = 28 + Align = alLeft + Layout = blGlyphBottom + ShowCaption = False + end + object btnDelProp1: TSpeedButton + Left = 28 + Height = 26 + Hint = 'remove selected configuration' + Top = 0 + Width = 28 + Align = alLeft + Layout = blGlyphBottom + ShowCaption = False + end + end + object treeInspect: TTreeView + Left = 4 + Height = 485 + Top = 32 + Width = 387 + Align = alClient + BorderSpacing.Around = 4 + DefaultItemHeight = 18 + HideSelection = False + ReadOnly = True + ScrollBars = ssAutoBoth + TabOrder = 1 + Options = [tvoAutoItemHeight, tvoKeepCollapsedNodes, tvoReadOnly, tvoShowButtons, tvoShowLines, tvoShowRoot, tvoToolTips, tvoThemedDraw] + Items.Data = { + F9FFFFFF020002000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF000000000000 + 0000000C000000536F757263652066696C6573FFFFFFFFFFFFFFFFFFFFFFFFFF + FFFFFF0000000000000000000E000000436F6E66696775726174696F6E73 + } + end + end + object TabSheet2: TTabSheet + Caption = 'Editor' + ClientHeight = 521 + ClientWidth = 395 + object edValue: TMemo + Left = 4 + Height = 93 + Top = 424 + Width = 387 + Align = alBottom + BorderSpacing.Around = 4 + ScrollBars = ssAutoVertical + TabOrder = 0 + end + object propTree: TTreeView + Left = 4 + Height = 388 + Top = 32 + Width = 387 + Align = alClient + BorderSpacing.Around = 4 + DefaultItemHeight = 18 + HideSelection = False + ReadOnly = True + ScrollBars = ssAutoBoth + TabOrder = 1 + OnSelectionChanged = propTreeSelectionChanged + Options = [tvoAutoItemHeight, tvoKeepCollapsedNodes, tvoReadOnly, tvoShowButtons, tvoShowLines, tvoShowRoot, tvoToolTips, tvoThemedDraw] + end + object pnlToolBar: TPanel + Left = 4 + Height = 26 + Top = 2 + Width = 387 + Align = alTop + BorderSpacing.Left = 2 + BorderSpacing.Right = 2 + BorderSpacing.Around = 2 + BevelOuter = bvNone + ClientHeight = 26 + ClientWidth = 387 + TabOrder = 2 + object btnAddProp: TSpeedButton + Left = 0 + Height = 26 + Hint = 'add an empty configuration' + Top = 0 + Width = 28 + Align = alLeft + Layout = blGlyphBottom + ShowCaption = False + end + object btnDelProp: TSpeedButton + Left = 28 + Height = 26 + Hint = 'remove selected configuration' + Top = 0 + Width = 28 + Align = alLeft + Layout = blGlyphBottom + ShowCaption = False + end + end + end end end end diff --git a/src/ce_dubprojeditor.pas b/src/ce_dubprojeditor.pas index f8bf29b9..3b1f9be6 100644 --- a/src/ce_dubprojeditor.pas +++ b/src/ce_dubprojeditor.pas @@ -15,15 +15,25 @@ type TCEDubProjectEditorWidget = class(TCEWidget, ICEProjectObserver) btnAddProp: TSpeedButton; + btnAddProp1: TSpeedButton; btnDelProp: TSpeedButton; + btnDelProp1: TSpeedButton; edValue: TMemo; + PageControl1: TPageControl; pnlToolBar: TPanel; + pnlToolBar1: TPanel; propTree: TTreeView; + treeInspect: TTreeView; + TabSheet1: TTabSheet; + TabSheet2: TTabSheet; procedure propTreeSelectionChanged(Sender: TObject); private fSelectedNode: TTreeNode; fProj: TCEDubProject; - procedure updateGui; + fNodeSources: TTreeNode; + fNodeConfig: TTreeNode; + procedure updateEditor; + procedure updateInspector; procedure updateValueEditor; procedure setJsonValueFromEditor; // @@ -36,18 +46,26 @@ type protected procedure SetVisible(Value: boolean); override; public + constructor create(aOwner: TComponent); override; end; implementation {$R *.lfm} {$REGION Standard Comp/Obj ----------------------------------------------------} +constructor TCEDubProjectEditorWidget.create(aOwner: TComponent); +begin + inherited; + fNodeSources := treeInspect.Items[0]; + fNodeConfig := treeInspect.Items[1]; +end; + procedure TCEDubProjectEditorWidget.SetVisible(Value: boolean); begin inherited; if not Value then exit; // - updateGui; + updateEditor; end; {$ENDREGION} @@ -55,8 +73,10 @@ end; procedure TCEDubProjectEditorWidget.projNew(aProject: ICECommonProject); begin fProj := nil; + enabled := false; if aProject.getFormat <> pfDub then exit; + enabled := true; fProj := TCEDubProject(aProject.getProject); // end; @@ -67,9 +87,11 @@ begin exit; if aProject.getProject <> fProj then exit; - // - if Visible then - updateGui; + if not Visible then + exit; + + updateEditor; + updateInspector; end; procedure TCEDubProjectEditorWidget.projClosing(aProject: ICECommonProject); @@ -80,18 +102,24 @@ begin exit; fProj := nil; // - updateGui; + updateEditor; + updateInspector; + enabled := false; end; procedure TCEDubProjectEditorWidget.projFocused(aProject: ICECommonProject); begin fProj := nil; + enabled := false; if aProject.getFormat <> pfDub then exit; fProj := TCEDubProject(aProject.getProject); - // - if Visible then - updateGui; + enabled := true; + if not Visible then + exit; + + updateEditor; + updateInspector; end; procedure TCEDubProjectEditorWidget.projCompiling(aProject: ICECommonProject); @@ -99,7 +127,7 @@ begin end; {$ENDREGION} -{$REGION GUI -------------------------------------------------------------------} +{$REGION Editor ----------------------------------------------------------------} procedure TCEDubProjectEditorWidget.propTreeSelectionChanged(Sender: TObject); begin fSelectedNode := nil; @@ -168,7 +196,7 @@ begin end; end; -procedure TCEDubProjectEditorWidget.updateGui; +procedure TCEDubProjectEditorWidget.updateEditor; procedure addPropsFrom(node: TTreeNode; data: TJSONData); var @@ -205,5 +233,24 @@ begin end; {$ENDREGION} +{$REGION Inspector -------------------------------------------------------------} +procedure TCEDubProjectEditorWidget.updateInspector; +var + i: integer; +begin + if (fNodeConfig = nil) or (fNodeSources = nil) then + exit; + // + fNodeConfig.DeleteChildren; + fNodeSources.DeleteChildren; + // + if (fProj = nil) then + exit; + // + for i:= 0 to fProj.getConfigurationCount -1 do + treeInspect.Items.AddChild(fNodeConfig, fProj.getConfigurationName(i)); +end; +{$ENDREGION} + end.