diff --git a/ide/compileroptions.pp b/ide/compileroptions.pp index 83653111fb..7276db739e 100644 --- a/ide/compileroptions.pp +++ b/ide/compileroptions.pp @@ -47,6 +47,8 @@ - edit them in the compiler options - edit name - edit value + - add value + - delete value - Every package and project can define a list of build macros. - load/save to xmlconfig - Every package and project can define a list of build macros. @@ -59,10 +61,6 @@ - edit default value ToDo: - - project can define values for build macros - - edit them in the compiler options - - add value - - delete value - every package/project needs a function to compute all values of its build macros - build macros depend on used packages and project build macro values - add a changestamp for this diff --git a/ide/frames/buildmodeseditor.lfm b/ide/frames/buildmodeseditor.lfm index 4d7459ce1b..7f74e6b75a 100644 --- a/ide/frames/buildmodeseditor.lfm +++ b/ide/frames/buildmodeseditor.lfm @@ -14,14 +14,14 @@ inherited BuildModesEditorFrame: TBuildModesEditorFrame Align = alClient BorderSpacing.Around = 6 Caption = 'BuildMacroValuesGroupBox' - ClientHeight = 213 - ClientWidth = 530 + ClientHeight = 215 + ClientWidth = 534 TabOrder = 0 object BuildMacroValuesStringGrid: TStringGrid Left = 0 - Height = 213 + Height = 215 Top = 0 - Width = 530 + Width = 534 Align = alClient AutoFillColumns = True ColCount = 2 @@ -30,14 +30,12 @@ inherited BuildModesEditorFrame: TBuildModesEditorFrame Options = [goFixedVertLine, goFixedHorzLine, goVertLine, goHorzLine, goRangeSelect, goEditing, goAlwaysShowEditor, goSmoothScroll] RowCount = 2 TabOrder = 0 - OnEditButtonClick = BuildMacroValuesStringGridEditButtonClick - OnMouseUp = BuildMacroValuesStringGridMouseUp - OnPickListSelect = BuildMacroValuesStringGridPickListSelect OnSelectEditor = BuildMacroValuesStringGridSelectEditor + OnSelection = BuildMacroValuesStringGridSelection OnSelectCell = BuildMacroValuesStringGridSelectCell ColWidths = ( - 264 - 264 + 266 + 266 ) end end diff --git a/ide/frames/buildmodeseditor.pas b/ide/frames/buildmodeseditor.pas index f7549a0856..274a255e92 100644 --- a/ide/frames/buildmodeseditor.pas +++ b/ide/frames/buildmodeseditor.pas @@ -40,7 +40,6 @@ uses type - { TBuildModesEditorFrame } TBuildModesEditorFrame = class(TAbstractIDEOptionsEditor) @@ -49,20 +48,22 @@ type BuildModesGroupBox: TGroupBox; BuildModesPopupMenu: TPopupMenu; Splitter1: TSplitter; - procedure BuildMacroValuesStringGridEditButtonClick(Sender: TObject); - procedure BuildMacroValuesStringGridMouseUp(Sender: TObject; - Button: TMouseButton; Shift: TShiftState; X, Y: Integer); - procedure BuildMacroValuesStringGridPickListSelect(Sender: TObject); procedure BuildMacroValuesStringGridSelectCell(Sender: TObject; aCol, aRow: Integer; var CanSelect: Boolean); procedure BuildMacroValuesStringGridSelectEditor(Sender: TObject; aCol, aRow: Integer; var Editor: TWinControl); + procedure BuildMacroValuesStringGridSelection(Sender: TObject; aCol, + aRow: Integer); private FMacroValues: TProjectBuildMacros; FProject: TProject; procedure UpdateMacrosControls; function GetAllBuildMacros: TStrings; + procedure CleanMacrosGrid; + procedure Save; public + constructor Create(TheOwner: TComponent); override; + destructor Destroy; override; function GetTitle: String; override; procedure Setup(ADialog: TAbstractOptionsEditorDialog); override; procedure ReadSettings(AOptions: TAbstractIDEOptions); override; @@ -78,51 +79,6 @@ implementation { TBuildModesEditorFrame } -procedure TBuildModesEditorFrame.BuildMacroValuesStringGridEditButtonClick( - Sender: TObject); -var - Grid: TStringGrid; -begin - Grid:=BuildMacroValuesStringGrid; - //debugln(['TBuildModesEditorFrame.BuildMacroValuesStringGridEditButtonClick Col=',Grid.Col,' Row=',Grid.Row]); - if Grid.Col=0 then begin - if Grid.Row=MacroValues.Count+1 then begin - // add new row - - end else if Grid.Row>0 then begin - // delete row - - end; - end; -end; - -procedure TBuildModesEditorFrame.BuildMacroValuesStringGridMouseUp( - Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer); -var - Grid: TStringGrid; - ACol: Longint; - ARow: Longint; -begin - Grid:=BuildMacroValuesStringGrid; - Grid.MouseToCell(X,Y,ACol,ARow); - //debugln(['TBuildModesEditorFrame.BuildMacroValuesStringGridMouseUp ',ACol,',',ARow]); - if ARow=MacroValues.Count+1 then begin - - end; -end; - -procedure TBuildModesEditorFrame.BuildMacroValuesStringGridPickListSelect( - Sender: TObject); -begin - //debugln(['TBuildModesEditorFrame.BuildMacroValuesStringGridPickListSelect ',Grid.Col,',',Grid.Row]); -end; - -procedure TBuildModesEditorFrame.BuildMacroValuesStringGridSelectCell( - Sender: TObject; aCol, aRow: Integer; var CanSelect: Boolean); -begin - //debugln(['TBuildModesEditorFrame.BuildMacroValuesStringGridSelectCell ',Grid.Col,',',Grid.Row,' ',aCol,',',aRow]); -end; - procedure TBuildModesEditorFrame.BuildMacroValuesStringGridSelectEditor( Sender: TObject; aCol, aRow: Integer; var Editor: TWinControl); var @@ -144,7 +100,7 @@ begin sl:=TStringList.Create; Macros:=nil; try - if aRow=MacroValues.Count+1 then + if aRow=Grid.RowCount-1 then sl.Add('(none)') else sl.Add('(delete)'); @@ -183,6 +139,18 @@ begin end; end; +procedure TBuildModesEditorFrame.BuildMacroValuesStringGridSelection( + Sender: TObject; aCol, aRow: Integer); +begin + CleanMacrosGrid; +end; + +procedure TBuildModesEditorFrame.BuildMacroValuesStringGridSelectCell( + Sender: TObject; aCol, aRow: Integer; var CanSelect: Boolean); +begin + +end; + procedure TBuildModesEditorFrame.UpdateMacrosControls; var Grid: TStringGrid; @@ -222,6 +190,7 @@ var i: Integer; begin Result:=TStringList.Create; + if AProject=nil then exit; Add(AProject.CompilerOptions); PkgList:=nil; try @@ -241,6 +210,62 @@ begin TStringList(Result).Sort; end; +procedure TBuildModesEditorFrame.CleanMacrosGrid; +var + Grid: TStringGrid; + aRow: Integer; + MacroName: string; + NeedNewRow: Boolean; +begin + Grid:=BuildMacroValuesStringGrid; + // delete rows + for aRow:=Grid.RowCount-2 downto 1 do begin + if aRow=Grid.Row then continue; // row is selected + MacroName:=Grid.Cells[0,aRow]; + if (MacroName<>'') and IsValidIdent(MacroName) then continue; // valid macro name + // delete row + Grid.DeleteColRow(false,aRow); + end; + NeedNewRow:=Grid.RowCount<2; + if (not NeedNewRow) then begin + MacroName:=Grid.Cells[0,Grid.RowCount-1]; + if (MacroName<>'') and IsValidIdent(MacroName) then + NeedNewRow:=true; + end; + if NeedNewRow then begin + Grid.RowCount:=Grid.RowCount+1; + Grid.Cells[0,Grid.RowCount-1]:='(new)'; + Grid.Cells[1,Grid.RowCount-1]:=''; + end; +end; + +procedure TBuildModesEditorFrame.Save; +var + Grid: TStringGrid; + aRow: Integer; + MacroName: string; +begin + Grid:=BuildMacroValuesStringGrid; + MacroValues.Clear; + for aRow:=1 to Grid.RowCount-1 do begin + MacroName:=Grid.Cells[0,aRow]; + if (MacroName='') or (not IsValidIdent(MacroName)) then continue; + MacroValues.Values[MacroName]:=Grid.Cells[1,aRow]; + end; +end; + +constructor TBuildModesEditorFrame.Create(TheOwner: TComponent); +begin + inherited Create(TheOwner); + FMacroValues:=TProjectBuildMacros.Create; +end; + +destructor TBuildModesEditorFrame.Destroy; +begin + FreeAndNil(FMacroValues); + inherited Destroy; +end; + function TBuildModesEditorFrame.GetTitle: String; begin Result := 'Build modes'; @@ -270,14 +295,20 @@ begin if AOptions is TProjectCompilerOptions then begin PCOptions:=TProjectCompilerOptions(AOptions); FProject:=PCOptions.Project; - FMacroValues:=FProject.MacroValues; + MacroValues.Assign(FProject.MacroValues); UpdateMacrosControls; end; end; procedure TBuildModesEditorFrame.WriteSettings(AOptions: TAbstractIDEOptions); +var + PCOptions: TProjectCompilerOptions; begin - + if AOptions is TProjectCompilerOptions then begin + PCOptions:=TProjectCompilerOptions(AOptions); + Save; + PCOptions.Project.MacroValues.Assign(MacroValues); + end; end; class function TBuildModesEditorFrame.SupportedOptionsClass: TAbstractIDEOptionsClass; diff --git a/ide/project.pp b/ide/project.pp index c46fa7076e..96e6916433 100644 --- a/ide/project.pp +++ b/ide/project.pp @@ -617,7 +617,7 @@ type property ChangeStamp: integer read FChangeStamp; procedure IncreaseChangeStamp; procedure LoadFromXMLConfig(XMLConfig: TXMLConfig; const Path: string); - procedure SaveToXMLConfig(XMLConfig: TXMLConfig; const Path: string); + procedure SaveToXMLConfig(XMLConfig: TXMLConfig; const Path: string; ClearModified: boolean = true); property Modified: boolean read GetModified write SetModified; end; @@ -727,6 +727,7 @@ type procedure SetMainFileID(const AValue: Integer); override; function GetFiles(Index: integer): TLazProjectFile; override; procedure SetFlags(const AValue: TProjectFlags); override; + function GetModified: boolean; override; function GetProjectInfoFile: string; override; procedure SetProjectInfoFile(const NewFilename: string); override; procedure SetSessionStorage(const AValue: TProjectSessionStorage); override; @@ -3082,7 +3083,7 @@ begin //DebugLn('TProject.ReadProject SessionStorage=',dbgs(ord(SessionStorage)),' ProjectSessionFile=',ProjectSessionFile); // load MacroValues - MacroValues.SaveToXMLConfig(xmlconfig,Path+'MacroValues/'); + MacroValues.LoadFromXMLConfig(xmlconfig,Path+'MacroValues/'); // load properties if FileVersion<9 then NewMainUnitID:=-1 else NewMainUnitID:=0; @@ -3500,6 +3501,13 @@ begin inherited SetFlags(AValue); end; +function TProject.GetModified: boolean; +begin + Result:=inherited GetModified; + if (not Result) and (MacroValues<>nil) then + Result:=MacroValues.Modified; +end; + procedure TProject.SetMainUnitID(const AValue: Integer); begin if AValue>=UnitCount then @@ -6242,7 +6250,7 @@ begin end; procedure TProjectBuildMacros.SaveToXMLConfig(XMLConfig: TXMLConfig; - const Path: string); + const Path: string; ClearModified: boolean); var i: Integer; SubPath: String; @@ -6253,6 +6261,8 @@ begin XMLConfig.SetDeleteValue(SubPath+'Name',Names[i],''); XMLConfig.SetDeleteValue(SubPath+'Value',ValueFromIndex(i),''); end; + if ClearModified then + Modified:=false; end; initialization diff --git a/ideintf/projectintf.pas b/ideintf/projectintf.pas index e0446ab67b..6237f0c90f 100644 --- a/ideintf/projectintf.pas +++ b/ideintf/projectintf.pas @@ -744,6 +744,7 @@ type function GetFiles(Index: integer): TLazProjectFile; virtual; abstract; procedure SetTitle(const AValue: String); virtual; procedure SetFlags(const AValue: TProjectFlags); virtual; + function GetModified: boolean; virtual; function GetProjectInfoFile: string; virtual; abstract; procedure SetProjectInfoFile(const NewFilename: string); virtual; abstract; procedure SetProjectSessionFile(const AValue: string); virtual; @@ -786,7 +787,7 @@ type read FProjectSessionFile write SetProjectSessionFile; property SessionStorage: TProjectSessionStorage read FSessionStorage write SetSessionStorage; - property Modified: boolean read fModified + property Modified: boolean read GetModified write SetModified; // project data (not units, session), // units have their own Modified property SessionModified: boolean read FSessionModified @@ -1565,6 +1566,11 @@ begin Modified:=true; end; +function TLazProject.GetModified: boolean; +begin + Result:=fModified; +end; + procedure TLazProject.SetExecutableType(const AValue: TProjectExecutableType); begin if FExecutableType=AValue then exit;