IDE: load/save build macro values

git-svn-id: trunk@27009 -
This commit is contained in:
mattias 2010-08-04 11:58:54 +00:00
parent 24003c4e73
commit 9b4deffe0f
5 changed files with 113 additions and 70 deletions

View File

@ -47,6 +47,8 @@
- edit them in the compiler options - edit them in the compiler options
- edit name - edit name
- edit value - edit value
- add value
- delete value
- Every package and project can define a list of build macros. - Every package and project can define a list of build macros.
- load/save to xmlconfig - load/save to xmlconfig
- Every package and project can define a list of build macros. - Every package and project can define a list of build macros.
@ -59,10 +61,6 @@
- edit default value - edit default value
ToDo: 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 - 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 - build macros depend on used packages and project build macro values
- add a changestamp for this - add a changestamp for this

View File

@ -14,14 +14,14 @@ inherited BuildModesEditorFrame: TBuildModesEditorFrame
Align = alClient Align = alClient
BorderSpacing.Around = 6 BorderSpacing.Around = 6
Caption = 'BuildMacroValuesGroupBox' Caption = 'BuildMacroValuesGroupBox'
ClientHeight = 213 ClientHeight = 215
ClientWidth = 530 ClientWidth = 534
TabOrder = 0 TabOrder = 0
object BuildMacroValuesStringGrid: TStringGrid object BuildMacroValuesStringGrid: TStringGrid
Left = 0 Left = 0
Height = 213 Height = 215
Top = 0 Top = 0
Width = 530 Width = 534
Align = alClient Align = alClient
AutoFillColumns = True AutoFillColumns = True
ColCount = 2 ColCount = 2
@ -30,14 +30,12 @@ inherited BuildModesEditorFrame: TBuildModesEditorFrame
Options = [goFixedVertLine, goFixedHorzLine, goVertLine, goHorzLine, goRangeSelect, goEditing, goAlwaysShowEditor, goSmoothScroll] Options = [goFixedVertLine, goFixedHorzLine, goVertLine, goHorzLine, goRangeSelect, goEditing, goAlwaysShowEditor, goSmoothScroll]
RowCount = 2 RowCount = 2
TabOrder = 0 TabOrder = 0
OnEditButtonClick = BuildMacroValuesStringGridEditButtonClick
OnMouseUp = BuildMacroValuesStringGridMouseUp
OnPickListSelect = BuildMacroValuesStringGridPickListSelect
OnSelectEditor = BuildMacroValuesStringGridSelectEditor OnSelectEditor = BuildMacroValuesStringGridSelectEditor
OnSelection = BuildMacroValuesStringGridSelection
OnSelectCell = BuildMacroValuesStringGridSelectCell OnSelectCell = BuildMacroValuesStringGridSelectCell
ColWidths = ( ColWidths = (
264 266
264 266
) )
end end
end end

View File

@ -40,7 +40,6 @@ uses
type type
{ TBuildModesEditorFrame } { TBuildModesEditorFrame }
TBuildModesEditorFrame = class(TAbstractIDEOptionsEditor) TBuildModesEditorFrame = class(TAbstractIDEOptionsEditor)
@ -49,20 +48,22 @@ type
BuildModesGroupBox: TGroupBox; BuildModesGroupBox: TGroupBox;
BuildModesPopupMenu: TPopupMenu; BuildModesPopupMenu: TPopupMenu;
Splitter1: TSplitter; 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, procedure BuildMacroValuesStringGridSelectCell(Sender: TObject; aCol,
aRow: Integer; var CanSelect: Boolean); aRow: Integer; var CanSelect: Boolean);
procedure BuildMacroValuesStringGridSelectEditor(Sender: TObject; aCol, procedure BuildMacroValuesStringGridSelectEditor(Sender: TObject; aCol,
aRow: Integer; var Editor: TWinControl); aRow: Integer; var Editor: TWinControl);
procedure BuildMacroValuesStringGridSelection(Sender: TObject; aCol,
aRow: Integer);
private private
FMacroValues: TProjectBuildMacros; FMacroValues: TProjectBuildMacros;
FProject: TProject; FProject: TProject;
procedure UpdateMacrosControls; procedure UpdateMacrosControls;
function GetAllBuildMacros: TStrings; function GetAllBuildMacros: TStrings;
procedure CleanMacrosGrid;
procedure Save;
public public
constructor Create(TheOwner: TComponent); override;
destructor Destroy; override;
function GetTitle: String; override; function GetTitle: String; override;
procedure Setup(ADialog: TAbstractOptionsEditorDialog); override; procedure Setup(ADialog: TAbstractOptionsEditorDialog); override;
procedure ReadSettings(AOptions: TAbstractIDEOptions); override; procedure ReadSettings(AOptions: TAbstractIDEOptions); override;
@ -78,51 +79,6 @@ implementation
{ TBuildModesEditorFrame } { 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( procedure TBuildModesEditorFrame.BuildMacroValuesStringGridSelectEditor(
Sender: TObject; aCol, aRow: Integer; var Editor: TWinControl); Sender: TObject; aCol, aRow: Integer; var Editor: TWinControl);
var var
@ -144,7 +100,7 @@ begin
sl:=TStringList.Create; sl:=TStringList.Create;
Macros:=nil; Macros:=nil;
try try
if aRow=MacroValues.Count+1 then if aRow=Grid.RowCount-1 then
sl.Add('(none)') sl.Add('(none)')
else else
sl.Add('(delete)'); sl.Add('(delete)');
@ -183,6 +139,18 @@ begin
end; end;
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; procedure TBuildModesEditorFrame.UpdateMacrosControls;
var var
Grid: TStringGrid; Grid: TStringGrid;
@ -222,6 +190,7 @@ var
i: Integer; i: Integer;
begin begin
Result:=TStringList.Create; Result:=TStringList.Create;
if AProject=nil then exit;
Add(AProject.CompilerOptions); Add(AProject.CompilerOptions);
PkgList:=nil; PkgList:=nil;
try try
@ -241,6 +210,62 @@ begin
TStringList(Result).Sort; TStringList(Result).Sort;
end; 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; function TBuildModesEditorFrame.GetTitle: String;
begin begin
Result := 'Build modes'; Result := 'Build modes';
@ -270,14 +295,20 @@ begin
if AOptions is TProjectCompilerOptions then begin if AOptions is TProjectCompilerOptions then begin
PCOptions:=TProjectCompilerOptions(AOptions); PCOptions:=TProjectCompilerOptions(AOptions);
FProject:=PCOptions.Project; FProject:=PCOptions.Project;
FMacroValues:=FProject.MacroValues; MacroValues.Assign(FProject.MacroValues);
UpdateMacrosControls; UpdateMacrosControls;
end; end;
end; end;
procedure TBuildModesEditorFrame.WriteSettings(AOptions: TAbstractIDEOptions); procedure TBuildModesEditorFrame.WriteSettings(AOptions: TAbstractIDEOptions);
var
PCOptions: TProjectCompilerOptions;
begin begin
if AOptions is TProjectCompilerOptions then begin
PCOptions:=TProjectCompilerOptions(AOptions);
Save;
PCOptions.Project.MacroValues.Assign(MacroValues);
end;
end; end;
class function TBuildModesEditorFrame.SupportedOptionsClass: TAbstractIDEOptionsClass; class function TBuildModesEditorFrame.SupportedOptionsClass: TAbstractIDEOptionsClass;

View File

@ -617,7 +617,7 @@ type
property ChangeStamp: integer read FChangeStamp; property ChangeStamp: integer read FChangeStamp;
procedure IncreaseChangeStamp; procedure IncreaseChangeStamp;
procedure LoadFromXMLConfig(XMLConfig: TXMLConfig; const Path: string); 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; property Modified: boolean read GetModified write SetModified;
end; end;
@ -727,6 +727,7 @@ type
procedure SetMainFileID(const AValue: Integer); override; procedure SetMainFileID(const AValue: Integer); override;
function GetFiles(Index: integer): TLazProjectFile; override; function GetFiles(Index: integer): TLazProjectFile; override;
procedure SetFlags(const AValue: TProjectFlags); override; procedure SetFlags(const AValue: TProjectFlags); override;
function GetModified: boolean; override;
function GetProjectInfoFile: string; override; function GetProjectInfoFile: string; override;
procedure SetProjectInfoFile(const NewFilename: string); override; procedure SetProjectInfoFile(const NewFilename: string); override;
procedure SetSessionStorage(const AValue: TProjectSessionStorage); override; procedure SetSessionStorage(const AValue: TProjectSessionStorage); override;
@ -3082,7 +3083,7 @@ begin
//DebugLn('TProject.ReadProject SessionStorage=',dbgs(ord(SessionStorage)),' ProjectSessionFile=',ProjectSessionFile); //DebugLn('TProject.ReadProject SessionStorage=',dbgs(ord(SessionStorage)),' ProjectSessionFile=',ProjectSessionFile);
// load MacroValues // load MacroValues
MacroValues.SaveToXMLConfig(xmlconfig,Path+'MacroValues/'); MacroValues.LoadFromXMLConfig(xmlconfig,Path+'MacroValues/');
// load properties // load properties
if FileVersion<9 then NewMainUnitID:=-1 else NewMainUnitID:=0; if FileVersion<9 then NewMainUnitID:=-1 else NewMainUnitID:=0;
@ -3500,6 +3501,13 @@ begin
inherited SetFlags(AValue); inherited SetFlags(AValue);
end; 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); procedure TProject.SetMainUnitID(const AValue: Integer);
begin begin
if AValue>=UnitCount then if AValue>=UnitCount then
@ -6242,7 +6250,7 @@ begin
end; end;
procedure TProjectBuildMacros.SaveToXMLConfig(XMLConfig: TXMLConfig; procedure TProjectBuildMacros.SaveToXMLConfig(XMLConfig: TXMLConfig;
const Path: string); const Path: string; ClearModified: boolean);
var var
i: Integer; i: Integer;
SubPath: String; SubPath: String;
@ -6253,6 +6261,8 @@ begin
XMLConfig.SetDeleteValue(SubPath+'Name',Names[i],''); XMLConfig.SetDeleteValue(SubPath+'Name',Names[i],'');
XMLConfig.SetDeleteValue(SubPath+'Value',ValueFromIndex(i),''); XMLConfig.SetDeleteValue(SubPath+'Value',ValueFromIndex(i),'');
end; end;
if ClearModified then
Modified:=false;
end; end;
initialization initialization

View File

@ -744,6 +744,7 @@ type
function GetFiles(Index: integer): TLazProjectFile; virtual; abstract; function GetFiles(Index: integer): TLazProjectFile; virtual; abstract;
procedure SetTitle(const AValue: String); virtual; procedure SetTitle(const AValue: String); virtual;
procedure SetFlags(const AValue: TProjectFlags); virtual; procedure SetFlags(const AValue: TProjectFlags); virtual;
function GetModified: boolean; virtual;
function GetProjectInfoFile: string; virtual; abstract; function GetProjectInfoFile: string; virtual; abstract;
procedure SetProjectInfoFile(const NewFilename: string); virtual; abstract; procedure SetProjectInfoFile(const NewFilename: string); virtual; abstract;
procedure SetProjectSessionFile(const AValue: string); virtual; procedure SetProjectSessionFile(const AValue: string); virtual;
@ -786,7 +787,7 @@ type
read FProjectSessionFile write SetProjectSessionFile; read FProjectSessionFile write SetProjectSessionFile;
property SessionStorage: TProjectSessionStorage read FSessionStorage property SessionStorage: TProjectSessionStorage read FSessionStorage
write SetSessionStorage; write SetSessionStorage;
property Modified: boolean read fModified property Modified: boolean read GetModified
write SetModified; // project data (not units, session), write SetModified; // project data (not units, session),
// units have their own Modified // units have their own Modified
property SessionModified: boolean read FSessionModified property SessionModified: boolean read FSessionModified
@ -1565,6 +1566,11 @@ begin
Modified:=true; Modified:=true;
end; end;
function TLazProject.GetModified: boolean;
begin
Result:=fModified;
end;
procedure TLazProject.SetExecutableType(const AValue: TProjectExecutableType); procedure TLazProject.SetExecutableType(const AValue: TProjectExecutableType);
begin begin
if FExecutableType=AValue then exit; if FExecutableType=AValue then exit;