mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-04-10 20:28:52 +02:00
IDEIntf: started RestoreSettings for options dialogs
git-svn-id: trunk@27677 -
This commit is contained in:
parent
3ff98d74ff
commit
8ff93b3a7e
@ -81,7 +81,10 @@ inherited BuildModesEditorFrame: TBuildModesEditorFrame
|
||||
Width = 170
|
||||
end>
|
||||
FixedCols = 0
|
||||
Options = [goFixedVertLine, goFixedHorzLine, goVertLine, goHorzLine, goRangeSelect, goEditing, goSmoothScroll]
|
||||
TabOrder = 0
|
||||
OnCheckboxToggled = BuildModesStringGridCheckboxToggled
|
||||
OnValidateEntry = BuildModesStringGridValidateEntry
|
||||
ColWidths = (
|
||||
170
|
||||
170
|
||||
|
@ -21,7 +21,20 @@
|
||||
Abstract:
|
||||
The frame for 'build modes' on the compiler options.
|
||||
Allows to edit build modes and build macro values.
|
||||
It does not allow to define new build macros.
|
||||
It does not allow to define new build macros, only values.
|
||||
|
||||
ToDo:
|
||||
- add build mode
|
||||
- delete build mode
|
||||
- move build mode up/down
|
||||
- in session attribute
|
||||
- cancel
|
||||
- extend ide options with CancelSettings
|
||||
- create central copy of build modes at setup and store modified flags
|
||||
- access active build modes directly
|
||||
- on cancel: copy back and restore modified flags
|
||||
- on write: check is something has changed: if not restore modified flags
|
||||
- activate another build mode
|
||||
}
|
||||
unit BuildModesEditor;
|
||||
|
||||
@ -62,13 +75,17 @@ type
|
||||
procedure BuildModeDeleteSpeedButtonClick(Sender: TObject);
|
||||
procedure BuildModeMoveDownSpeedButtonClick(Sender: TObject);
|
||||
procedure BuildModeMoveUpSpeedButtonClick(Sender: TObject);
|
||||
procedure BuildModesStringGridCheckboxToggled(sender: TObject; aCol,
|
||||
aRow: Integer; aState: TCheckboxState);
|
||||
procedure BuildModesStringGridValidateEntry(sender: TObject; aCol,
|
||||
aRow: Integer; const OldValue: string; var NewValue: String);
|
||||
private
|
||||
FMacroValues: TProjectBuildMacros;
|
||||
FProject: TProject;
|
||||
procedure UpdateMacrosControls;
|
||||
function GetAllBuildMacros: TStrings;
|
||||
procedure CleanMacrosGrid;
|
||||
procedure Save(UpdateControls: boolean);
|
||||
procedure SaveMacros(UpdateControls: boolean);
|
||||
procedure UpdateInheritedOptions;
|
||||
function FindOptionFrame(AClass: TComponentClass): TComponent;
|
||||
procedure FillBuildModesGrid;
|
||||
@ -155,7 +172,7 @@ procedure TBuildModesEditorFrame.BuildMacroValuesStringGridEditingDone(
|
||||
Sender: TObject);
|
||||
begin
|
||||
//debugln(['TBuildModesEditorFrame.BuildMacroValuesStringGridEditingDone ']);
|
||||
Save(true);
|
||||
SaveMacros(true);
|
||||
end;
|
||||
|
||||
procedure TBuildModesEditorFrame.BuildMacroValuesStringGridSelection(
|
||||
@ -165,8 +182,21 @@ begin
|
||||
end;
|
||||
|
||||
procedure TBuildModesEditorFrame.BuildModeAddSpeedButtonClick(Sender: TObject);
|
||||
var
|
||||
i: Integer;
|
||||
NewName: String;
|
||||
begin
|
||||
ShowMessage('ToDo: TBuildModesEditorFrame.BuildModeAddSpeedButtonClick');
|
||||
i:=0;
|
||||
repeat
|
||||
inc(i);
|
||||
NewName:='Mode'+IntToStr(i);
|
||||
until AProject.BuildModes.Find(NewName)=nil;
|
||||
AProject.BuildModes.Add(NewName);
|
||||
FillBuildModesGrid;
|
||||
// select identifier
|
||||
BuildModesStringGrid.Col:=2;
|
||||
BuildModesStringGrid.Row:=BuildModesStringGrid.RowCount-1;
|
||||
BuildModesStringGrid.EditorMode:=true;
|
||||
end;
|
||||
|
||||
procedure TBuildModesEditorFrame.BuildModeDeleteSpeedButtonClick(Sender: TObject
|
||||
@ -177,14 +207,108 @@ end;
|
||||
|
||||
procedure TBuildModesEditorFrame.BuildModeMoveDownSpeedButtonClick(
|
||||
Sender: TObject);
|
||||
var
|
||||
i: Integer;
|
||||
begin
|
||||
ShowMessage('ToDo: TBuildModesEditorFrame.BuildModeMoveDownSpeedButtonClick');
|
||||
i:=BuildModesStringGrid.Row-1;
|
||||
if i+1>=AProject.BuildModes.Count then exit;
|
||||
AProject.BuildModes.Move(i,i+1);
|
||||
AProject.BuildModes[0].InSession:=false;
|
||||
inc(i);
|
||||
FillBuildModesGrid;
|
||||
BuildModesStringGrid.Row:=i+1;
|
||||
end;
|
||||
|
||||
procedure TBuildModesEditorFrame.BuildModeMoveUpSpeedButtonClick(Sender: TObject
|
||||
);
|
||||
var
|
||||
i: Integer;
|
||||
begin
|
||||
ShowMessage('ToDo: TBuildModesEditorFrame.BuildModeMoveUpSpeedButtonClick');
|
||||
i:=BuildModesStringGrid.Row-1;
|
||||
if i<=0 then exit;
|
||||
AProject.BuildModes.Move(i,i-1);
|
||||
dec(i);
|
||||
AProject.BuildModes[0].InSession:=false;
|
||||
FillBuildModesGrid;
|
||||
BuildModesStringGrid.Row:=i+1;
|
||||
end;
|
||||
|
||||
procedure TBuildModesEditorFrame.BuildModesStringGridCheckboxToggled(
|
||||
sender: TObject; aCol, aRow: Integer; aState: TCheckboxState);
|
||||
var
|
||||
CurMode: TProjectBuildMode;
|
||||
b: Boolean;
|
||||
i: Integer;
|
||||
begin
|
||||
debugln(['TBuildModesEditorFrame.BuildModesStringGridCheckboxToggled Row=',aRow,' Col=',aCol,' ',ord(aState)]);
|
||||
i:=aRow-1;
|
||||
if (i<0) or (i>=AProject.BuildModes.Count) then exit;
|
||||
debugln(['TBuildModesEditorFrame.BuildModesStringGridCheckboxToggled ',i]);
|
||||
CurMode:=AProject.BuildModes[i];
|
||||
case aCol of
|
||||
0:
|
||||
// activate
|
||||
;
|
||||
1:
|
||||
begin
|
||||
// in session
|
||||
b:=aState=cbChecked;
|
||||
if b and (i=0) then
|
||||
begin
|
||||
|
||||
MessageDlg('Error',
|
||||
'The first build mode is the default mode and must be stored in the project, not in the session.',
|
||||
mtError,[mbCancel],0);
|
||||
exit;
|
||||
end;
|
||||
CurMode.InSession:=b;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TBuildModesEditorFrame.BuildModesStringGridValidateEntry(
|
||||
sender: TObject; aCol, aRow: Integer; const OldValue: string;
|
||||
var NewValue: String);
|
||||
var
|
||||
CurMode: TProjectBuildMode;
|
||||
s: string;
|
||||
j: Integer;
|
||||
b: Boolean;
|
||||
i: Integer;
|
||||
begin
|
||||
debugln(['TBuildModesEditorFrame.BuildModesStringGridValidateEntry Row=',aRow,' Col=',aCol,' ',NewValue]);
|
||||
i:=aRow-1;
|
||||
if (i<0) or (i>=AProject.BuildModes.Count) then exit;
|
||||
debugln(['TBuildModesEditorFrame.SaveModes ',i]);
|
||||
CurMode:=AProject.BuildModes[i];
|
||||
case aCol of
|
||||
0:
|
||||
// activate
|
||||
;
|
||||
1:
|
||||
begin
|
||||
// in session
|
||||
b:=NewValue=BuildModesStringGrid.Columns[1].ValueChecked;
|
||||
if b and (i=0) then
|
||||
begin
|
||||
NewValue:=OldValue;
|
||||
MessageDlg('Error',
|
||||
'The first build mode is the default mode and must be stored in the project, not in the session.',
|
||||
mtError,[mbCancel],0);
|
||||
exit;
|
||||
end;
|
||||
CurMode.InSession:=b;
|
||||
end;
|
||||
2:
|
||||
begin
|
||||
// identifier
|
||||
s:=NewValue;
|
||||
for j:=1 to length(s) do
|
||||
if s[j]<' ' then s[j]:=' ';
|
||||
CurMode.Identifier:=s;
|
||||
NewValue:=s;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TBuildModesEditorFrame.UpdateMacrosControls;
|
||||
@ -275,7 +399,7 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TBuildModesEditorFrame.Save(UpdateControls: boolean);
|
||||
procedure TBuildModesEditorFrame.SaveMacros(UpdateControls: boolean);
|
||||
var
|
||||
Grid: TStringGrid;
|
||||
aRow: Integer;
|
||||
@ -399,6 +523,11 @@ begin
|
||||
BuildModesStringGrid.Cells[1, 0]:=lisInSession;
|
||||
BuildModesStringGrid.Cells[2, 0]:=lisDebugOptionsFrmName;
|
||||
|
||||
BuildModeAddSpeedButton.LoadGlyphFromLazarusResource('laz_add');
|
||||
BuildModeDeleteSpeedButton.LoadGlyphFromLazarusResource('laz_delete');
|
||||
BuildModeMoveUpSpeedButton.LoadGlyphFromLazarusResource('arrow_up');
|
||||
BuildModeMoveDownSpeedButton.LoadGlyphFromLazarusResource('arrow_down');
|
||||
|
||||
BuildMacroValuesGroupBox.Caption:=lisSetMacroValues;
|
||||
Grid:=BuildMacroValuesStringGrid;
|
||||
Grid.Columns.Add;
|
||||
@ -430,7 +559,7 @@ var
|
||||
begin
|
||||
if AOptions is TProjectCompilerOptions then begin
|
||||
PCOptions:=TProjectCompilerOptions(AOptions);
|
||||
Save(false);
|
||||
SaveMacros(false);
|
||||
if not PCOptions.LazProject.MacroValues.Equals(MacroValues) then begin
|
||||
PCOptions.LazProject.MacroValues.Assign(MacroValues);
|
||||
IncreaseBuildMacroChangeStamp;
|
||||
|
@ -36,6 +36,12 @@ uses
|
||||
EditorOptions, IDECommands;
|
||||
|
||||
type
|
||||
TIDEOptsDlgAction = (
|
||||
iodaRead,
|
||||
iodaWrite,
|
||||
iodaRestore
|
||||
);
|
||||
|
||||
{ TIDEOptionsDialog }
|
||||
|
||||
TIDEOptionsDialog = class(TAbstractOptionsEditorDialog)
|
||||
@ -77,8 +83,7 @@ type
|
||||
function FindEditor(AEditor: TAbstractIDEOptionsEditorClass): TAbstractIDEOptionsEditor; override;
|
||||
function FindEditor(GroupIndex, AIndex: integer): TAbstractIDEOptionsEditor; override;
|
||||
function FindEditorClass(GroupIndex, AIndex: integer): TAbstractIDEOptionsEditorClass; override;
|
||||
procedure ReadSettings(AOptions: TAbstractIDEOptions);
|
||||
procedure WriteSettings(AOptions: TAbstractIDEOptions);
|
||||
procedure TraverseSettings(AOptions: TAbstractIDEOptions; anAction: TIDEOptsDlgAction);
|
||||
procedure ReadAll;
|
||||
procedure WriteAll;
|
||||
|
||||
@ -204,7 +209,8 @@ begin
|
||||
ModalResult := mrCancel;
|
||||
end;
|
||||
|
||||
procedure TIDEOptionsDialog.ReadSettings(AOptions: TAbstractIDEOptions);
|
||||
procedure TIDEOptionsDialog.TraverseSettings(AOptions: TAbstractIDEOptions;
|
||||
anAction: TIDEOptsDlgAction);
|
||||
var
|
||||
ClassTypeForCompare: TClass;
|
||||
|
||||
@ -216,7 +222,13 @@ var
|
||||
with TAbstractIDEOptionsEditor(Node.Data) do
|
||||
if ((ClassTypeForCompare = nil) and (SupportedOptionsClass = nil)) or
|
||||
((SupportedOptionsClass <> nil) and ClassTypeForCompare.InheritsFrom(SupportedOptionsClass)) then
|
||||
ReadSettings(AOptions);
|
||||
begin
|
||||
case anAction of
|
||||
iodaRead: ReadSettings(AOptions);
|
||||
iodaWrite: WriteSettings(AOptions);
|
||||
iodaRestore: RestoreSettings(AOptions);
|
||||
end;
|
||||
end;
|
||||
Traverse(Node.GetFirstChild);
|
||||
Traverse(Node.GetNextSibling);
|
||||
end;
|
||||
@ -232,33 +244,6 @@ begin
|
||||
Traverse(CategoryTree.Items.GetFirstNode);
|
||||
end;
|
||||
|
||||
procedure TIDEOptionsDialog.WriteSettings(AOptions: TAbstractIDEOptions);
|
||||
var
|
||||
ClassTypeForCompare: TClass;
|
||||
|
||||
procedure Traverse(Node: TTreeNode);
|
||||
begin
|
||||
if Node <> nil then
|
||||
begin
|
||||
if Node.Data <> nil then
|
||||
with TAbstractIDEOptionsEditor(Node.Data) do
|
||||
if ((ClassTypeForCompare = nil) and (SupportedOptionsClass = nil)) or
|
||||
((SupportedOptionsClass <> nil) and ClassTypeForCompare.InheritsFrom(SupportedOptionsClass)) then
|
||||
WriteSettings(AOptions);
|
||||
Traverse(Node.GetFirstChild);
|
||||
Traverse(Node.GetNextSibling);
|
||||
end;
|
||||
end;
|
||||
|
||||
begin
|
||||
if AOptions <> nil then
|
||||
ClassTypeForCompare := AOptions.ClassType
|
||||
else
|
||||
ClassTypeForCompare := nil;
|
||||
|
||||
Traverse(CategoryTree.Items.GetFirstNode);
|
||||
end;
|
||||
|
||||
procedure TIDEOptionsDialog.ReadAll;
|
||||
var
|
||||
i: integer;
|
||||
@ -281,14 +266,14 @@ begin
|
||||
begin
|
||||
InstanceList.Add(Instance);
|
||||
Instance.DoBeforeRead;
|
||||
ReadSettings(Instance);
|
||||
TraverseSettings(Instance,iodaRead);
|
||||
Instance.DoAfterRead;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
// load settings that does not belong to any group
|
||||
ReadSettings(nil);
|
||||
TraverseSettings(nil,iodaRead);
|
||||
InstanceList.Free;
|
||||
end;
|
||||
|
||||
@ -311,14 +296,14 @@ begin
|
||||
if Instance <> nil then
|
||||
begin
|
||||
Instance.DoBeforeWrite;
|
||||
WriteSettings(Instance);
|
||||
TraverseSettings(Instance,iodaWrite);
|
||||
Instance.DoAfterWrite;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
// save settings that does not belong to any group
|
||||
WriteSettings(nil);
|
||||
TraverseSettings(nil,iodaWrite);
|
||||
end;
|
||||
|
||||
function TIDEOptionsDialog.CheckValues: boolean;
|
||||
@ -348,12 +333,12 @@ procedure TIDEOptionsDialog.LoadIDEOptions(Sender: TObject; AOptions: TAbstractI
|
||||
begin
|
||||
if Assigned(OnLoadIDEOptions) then
|
||||
OnLoadIDEOptions(Self, AOptions);
|
||||
ReadSettings(AOptions);
|
||||
TraverseSettings(AOptions,iodaRead);
|
||||
end;
|
||||
|
||||
procedure TIDEOptionsDialog.SaveIDEOptions(Sender: TObject; AOptions: TAbstractIDEOptions);
|
||||
begin
|
||||
WriteSettings(AOptions);
|
||||
TraverseSettings(AOptions,iodaWrite);
|
||||
if Assigned(OnSaveIDEOptions) then
|
||||
OnSaveIDEOptions(Self, AOptions);
|
||||
end;
|
||||
|
@ -696,6 +696,7 @@ type
|
||||
function IndexOf(Identifier: string): integer;
|
||||
function Find(Identifier: string): TProjectBuildMode;
|
||||
function Add(Identifier: string): TProjectBuildMode;
|
||||
procedure Move(FromIndex, ToIndex: integer);
|
||||
function Count: integer;
|
||||
property Items[Index: integer]: TProjectBuildMode read GetItems; default;
|
||||
property ChangeStamp: integer read FChangeStamp;
|
||||
@ -6806,7 +6807,7 @@ end;
|
||||
function TProjectBuildModes.IndexOf(Identifier: string): integer;
|
||||
begin
|
||||
Result:=Count-1;
|
||||
while (Count>=0)
|
||||
while (Result>=0)
|
||||
and (SysUtils.CompareText(Identifier,Items[Result].Identifier)<>0) do
|
||||
dec(Result);
|
||||
end;
|
||||
@ -6832,6 +6833,11 @@ begin
|
||||
fItems.Add(Result);
|
||||
end;
|
||||
|
||||
procedure TProjectBuildModes.Move(FromIndex, ToIndex: integer);
|
||||
begin
|
||||
fItems.Move(FromIndex,ToIndex);
|
||||
end;
|
||||
|
||||
function TProjectBuildModes.Count: integer;
|
||||
begin
|
||||
Result:=fItems.Count;
|
||||
|
@ -87,6 +87,7 @@ type
|
||||
procedure Setup(ADialog: TAbstractOptionsEditorDialog); virtual; abstract;
|
||||
procedure ReadSettings(AOptions: TAbstractIDEOptions); virtual; abstract;
|
||||
procedure WriteSettings(AOptions: TAbstractIDEOptions); virtual; abstract;
|
||||
procedure RestoreSettings(AOptions: TAbstractIDEOptions); virtual;
|
||||
class function SupportedOptionsClass: TAbstractIDEOptionsClass; virtual; abstract;
|
||||
class function DefaultCollapseChildNodes: Boolean; virtual;
|
||||
|
||||
@ -345,6 +346,12 @@ begin
|
||||
Result := True;
|
||||
end;
|
||||
|
||||
procedure TAbstractIDEOptionsEditor.RestoreSettings(
|
||||
AOptions: TAbstractIDEOptions);
|
||||
begin
|
||||
|
||||
end;
|
||||
|
||||
class function TAbstractIDEOptionsEditor.DefaultCollapseChildNodes: Boolean;
|
||||
begin
|
||||
Result := False;
|
||||
|
Loading…
Reference in New Issue
Block a user