From 5a061233708c4dfb4253af8f20a08ff14acce825 Mon Sep 17 00:00:00 2001 From: mattias Date: Sat, 12 Dec 2009 17:52:35 +0000 Subject: [PATCH] IDE: build modes: new setting git-svn-id: trunk@23107 - --- ide/compileroptions.pp | 12 +++ ide/frames/buildmodeseditor.lfm | 8 ++ ide/frames/buildmodeseditor.lrs | 6 +- ide/frames/buildmodeseditor.pas | 144 +++++++++++++++++++++++++------- ide/lazarusidestrconsts.pas | 7 ++ 5 files changed, 143 insertions(+), 34 deletions(-) diff --git a/ide/compileroptions.pp b/ide/compileroptions.pp index 852cec8cbb..d8fb97f67a 100644 --- a/ide/compileroptions.pp +++ b/ide/compileroptions.pp @@ -183,6 +183,8 @@ type procedure Exclude(aMode: TBuildMode); function AddFlag(FlagType: TBuildModeFlagType; Value: string; Variable: string = ''): TBuildModeFlag; + function InsertFlag(InsertPos: integer; FlagType: TBuildModeFlagType; + Value: string; Variable: string = ''): TBuildModeFlag; procedure DeleteFlag(Index: integer); procedure Assign(Source: TPersistent); override; // copy without Name function IsEqual(aMode: TBuildMode): boolean; @@ -5010,10 +5012,20 @@ end; function TBuildMode.AddFlag(FlagType: TBuildModeFlagType; Value: string; Variable: string): TBuildModeFlag; begin + Result:=InsertFlag(FlagCount,FlagType,Value,Variable); +end; + +function TBuildMode.InsertFlag(InsertPos: integer; + FlagType: TBuildModeFlagType; Value: string; Variable: string + ): TBuildModeFlag; +begin + if (InsertPos<0) or (InsertPos>FlagCount) then + RaiseGDBException(''); Result:=TBuildModeFlag.Create; Result.FlagType:=FlagType; Result.Value:=Value; Result.Variable:=Variable; + FFlags.Insert(InsertPos,Result); end; procedure TBuildMode.DeleteFlag(Index: integer); diff --git a/ide/frames/buildmodeseditor.lfm b/ide/frames/buildmodeseditor.lfm index 47259887a2..35ff9026f1 100644 --- a/ide/frames/buildmodeseditor.lfm +++ b/ide/frames/buildmodeseditor.lfm @@ -23,6 +23,14 @@ object BuildModesEditorFrame: TBuildModesEditorFrame ShowHint = True OnClick = NewBuildModeToolButtonClick end + object NewBuildFlagToolButton: TToolButton + Left = 24 + Top = 2 + Caption = 'NewBuildFlagToolButton' + ParentShowHint = False + ShowHint = True + OnClick = NewBuildFlagToolButtonClick + end end object BuildModesPopupMenu: TPopupMenu left = 83 diff --git a/ide/frames/buildmodeseditor.lrs b/ide/frames/buildmodeseditor.lrs index c177dd8800..c86629fd21 100644 --- a/ide/frames/buildmodeseditor.lrs +++ b/ide/frames/buildmodeseditor.lrs @@ -8,6 +8,8 @@ LazarusResources.Add('TBuildModesEditorFrame','FORMDATA',[ +'th'#3#144#1#7'Caption'#6#17'BuildModesToolBar'#8'TabOrder'#2#0#0#11'TToolBu' +'tton'#22'NewBuildModeToolButton'#4'Left'#2#1#3'Top'#2#2#7'Caption'#6#3'New' +#14'ParentShowHint'#8#8'ShowHint'#9#7'OnClick'#7#27'NewBuildModeToolButtonCl' - +'ick'#0#0#0#10'TPopupMenu'#19'BuildModesPopupMenu'#4'left'#2'S'#3'top'#2's'#0 - +#0#0 + +'ick'#0#0#11'TToolButton'#22'NewBuildFlagToolButton'#4'Left'#2#24#3'Top'#2#2 + +#7'Caption'#6#22'NewBuildFlagToolButton'#14'ParentShowHint'#8#8'ShowHint'#9#7 + +'OnClick'#7#27'NewBuildFlagToolButtonClick'#0#0#0#10'TPopupMenu'#19'BuildMod' + +'esPopupMenu'#4'left'#2'S'#3'top'#2's'#0#0#0 ]); diff --git a/ide/frames/buildmodeseditor.pas b/ide/frames/buildmodeseditor.pas index 1969a509df..ebf77c600b 100644 --- a/ide/frames/buildmodeseditor.pas +++ b/ide/frames/buildmodeseditor.pas @@ -26,9 +26,9 @@ interface uses Classes, SysUtils, LCLProc, Controls, FileUtil, LResources, Forms, Grids, - Menus, ComCtrls, + Menus, ComCtrls, Dialogs, IDEImagesIntf, - CompilerOptions, IDEProcs; + LazarusIDEStrConsts, CompilerOptions, IDEProcs; type @@ -63,10 +63,12 @@ type var NewValue:string): boolean; override; function ValidateCell(const ACol, ARow: Integer; var NewValue:string): boolean; + procedure UpdateIndexInGroup(aRow: integer); public constructor Create(TheOwner: TComponent); override; destructor Destroy; override; function AddNewBuildMode: TBuildMode; + function InsertNewBuildFlagBehind: TBuildModeFlag; property Graph: TBuildModeGraph read FGraph; procedure RebuildGrid; // call this after Graph changed property ModeRowCount: integer read GetModeRowCount; @@ -80,6 +82,8 @@ type BuildModesPopupMenu: TPopupMenu; BuildModesToolBar: TToolBar; NewBuildModeToolButton: TToolButton; + NewBuildFlagToolButton: TToolButton; + procedure NewBuildFlagToolButtonClick(Sender: TObject); procedure NewBuildModeToolButtonClick(Sender: TObject); private FGrid: TBuildModesGrid; @@ -149,10 +153,10 @@ begin TypeCol:=GroupModeCount+1; ValueCol:=TypeCol+1; if i=0 then begin - Cells[0,0]:='Build mode'; + Cells[0, 0]:=lisBuildMode; for i:=1 to GroupModeCount do Cells[i,0]:=''; - Cells[TypeCol,0]:='Type'; - Cells[ValueCol,0]:='Value'; + Cells[TypeCol, 0]:=dlgEnvType; + Cells[ValueCol, 0]:=dlgValueColor; end else begin CurRow:=ModeRows[i-1]; // name @@ -192,48 +196,83 @@ end; function TBuildModesGrid.ValidateCell(const ACol, ARow: Integer; var NewValue: string): boolean; var - CurMode: TBuildModeGridRow; + CurModeRow: TBuildModeGridRow; TypeCol: Integer; ValueCol: Integer; FlagType: TBuildModeFlagType; begin Result:=true; if (aRow>=1) and (aRow<=ModeRowCount) then begin - CurMode:=ModeRows[aRow-1]; + CurModeRow:=ModeRows[aRow-1]; TypeCol:=GroupModeCount+1; ValueCol:=TypeCol+1; //DebugLn(['TBuildModesGrid.ValidateCell aCol=',acol,' aRow=',arow,' ValueCol=',ValueCol]); if aCol=0 then begin - // set new mode name - NewValue:=Graph.FixModeName(NewValue,CurMode.Mode); - CurMode.Mode.Name:=NewValue; + if CurModeRow.IndexInGroup=0 then + begin + // set new mode name + NewValue:=Graph.FixModeName(NewValue,CurModeRow.Mode); + CurModeRow.Mode.Name:=NewValue; + end else begin + // this is a sub flag => should be empty + NewValue:=''; + end; end else if ACol=TypeCol then begin - NewValue:=SpecialCharsToSpaces(NewValue,true); - FlagType:=CaptionToBuildModeFlagType(NewValue); - if (CurMode.Flag=nil) and (FlagType<>bmftNone) then begin - // create flag - CurMode.FFlag:=CurMode.Mode.AddFlag(FlagType,'',''); - end else if CurMode.Flag<>nil then - // set new FlagType - CurMode.Flag.FlagType:=FlagType; - if FlagType=bmftSetVariable then - // set variable name - CurMode.Flag.Variable:=NewValue - else - // clean up variable name - CurMode.Flag.Variable:=''; + if CurModeRow.Mode.ShowIncludes then begin + // this is a group mode => no flags allowed + NewValue:=''; + end else begin + NewValue:=SpecialCharsToSpaces(NewValue,true); + FlagType:=CaptionToBuildModeFlagType(NewValue); + if (CurModeRow.Flag=nil) and (FlagType<>bmftNone) then begin + // create flag + CurModeRow.FFlag:=CurModeRow.Mode.AddFlag(FlagType,'',''); + end else if CurModeRow.Flag<>nil then + // set new FlagType + CurModeRow.Flag.FlagType:=FlagType; + if FlagType=bmftSetVariable then + // set variable name + CurModeRow.Flag.Variable:=NewValue + else + // clean up variable name + CurModeRow.Flag.Variable:=''; + end; end else if ACol=ValueCol then begin - NewValue:=SpecialCharsToSpaces(NewValue,true); - if (CurMode.Flag=nil) or (CurMode.Flag.FlagType=bmftNone) then - // no flag => no value - NewValue:='' - else - // set new value - CurMode.Flag.Value:=NewValue; + if CurModeRow.Mode.ShowIncludes then begin + // this is a group mode => no flags allowed + NewValue:=''; + end else begin + NewValue:=SpecialCharsToSpaces(NewValue,true); + if (CurModeRow.Flag=nil) or (CurModeRow.Flag.FlagType=bmftNone) then + // no flag => no value + NewValue:='' + else + // set new value + CurModeRow.Flag.Value:=NewValue; + end; end; end; end; +procedure TBuildModesGrid.UpdateIndexInGroup(aRow: integer); +var + IndexInGroup: Integer; + Mode: TBuildMode; + Index: LongInt; +begin + Index:=aRow-1; + Mode:=ModeRows[Index].Mode; + while (Index>0) and (Mode=ModeRows[Index-1].Mode) do + dec(Index); + IndexInGroup:=0; + while (IndexModeRowCount) then + begin + MessageDlg(lisUnableToAddSetting, + lisPleaseSelectABuildModeFirst, mtError, [mbCancel], 0); + exit; + end; + DebugLn(['TBuildModesGrid.InsertNewBuildFlagBehind ',Row]); + CurModeRow:=ModeRows[Row-1]; + if CurModeRow.Mode.ShowIncludes then + begin + MessageDlg(lisUnableToAddSetting, + Format(lisIsAGroupASettingCanOnlyBeAddedToNormalBuildModes, [ + CurModeRow.Mode.Name]), + mtError, [mbCancel], 0); + exit; + end; + DebugLn(['TBuildModesGrid.InsertNewBuildFlagBehind AAA1']); + Result:=CurModeRow.Mode.InsertFlag(CurModeRow.IndexInGroup+1,bmftNone,'',''); + InsertPos:=Row+1; + GridRow:=TBuildModeGridRow.Create(CurModeRow.Mode,Result); + FModeRows.Insert(InsertPos-1,GridRow); + UpdateIndexInGroup(InsertPos); + InsertColRow(false,InsertPos); + FillGridRow(InsertPos); + Row:=InsertPos; +end; + procedure TBuildModesGrid.RebuildGrid; var GroupInsertPos: Integer; @@ -351,6 +423,11 @@ begin Grid.AddNewBuildMode; end; +procedure TBuildModesEditorFrame.NewBuildFlagToolButtonClick(Sender: TObject); +begin + Grid.InsertNewBuildFlagBehind; +end; + constructor TBuildModesEditorFrame.Create(TheOwner: TComponent); begin inherited Create(TheOwner); @@ -362,8 +439,11 @@ begin end; BuildModesToolBar.Images := IDEImages.Images_16; - NewBuildModeToolButton.Hint:='New build mode'; + NewBuildModeToolButton.Hint:=lisNewBuildMode; NewBuildModeToolButton.ImageIndex := IDEImages.LoadImage(16, 'laz_add'); + NewBuildFlagToolButton.Hint:=lisNewSetting; + NewBuildFlagToolButton.ImageIndex := IDEImages.LoadImage(16, 'laz_edit'); + // laz_delete, laz_edit, arrow_up, arrow_down end; diff --git a/ide/lazarusidestrconsts.pas b/ide/lazarusidestrconsts.pas index dba65a1f7d..8053d68942 100644 --- a/ide/lazarusidestrconsts.pas +++ b/ide/lazarusidestrconsts.pas @@ -1069,6 +1069,12 @@ resourcestring dlgSubPropColor = 'SubProperties'; dlgReferenceColor = 'Reference'; dlgValueColor = 'Value'; + lisUnableToAddSetting = 'Unable to add setting'; + lisIsAGroupASettingCanOnlyBeAddedToNormalBuildModes = '%s is a group. A ' + +'setting can only be added to normal build modes.'; + lisPleaseSelectABuildModeFirst = 'Please select a build mode first.'; + lisNewBuildMode = 'New build mode'; + lisNewSetting = 'New setting'; dlfReadOnlyColor = 'Read Only'; dlgHighlightColor = 'Highlight Color'; dlgHighlightFontColor = 'Highlight Font Color'; @@ -4575,6 +4581,7 @@ resourcestring lisIDEBuildOptions = 'IDE build options'; lisUnableToWriteTheProjectInfoFileError = 'Unable to write the project info ' +'file%s%s%s%s.%sError: %s'; + lisBuildMode = 'Build mode'; implementation