1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201
|
unit ExWinSettings;
{
**********************************************************************
This file is part of a Lazarus Package, Examples Window.
See the file COPYING.modifiedLGPL.txt, included in this distribution,
for details about the license.
**********************************************************************
This unit makes a frame that is poked into Lazarus's Options Tree. At present
all it gets back is the user's preference as to where the Example Projects
working space is. Easily extended. David Bannon, Feb 2022
}
{$mode ObjFPC}{$H+}
interface
uses
Classes, SysUtils,
// LazUtils
LazConfigStorage, LazFileUtils, LazLoggerBase,
// LCL
Controls, StdCtrls, EditBtn, Dialogs,
// BuildIntf
IDEOptionsIntf, baseIDEIntf,
// IdeIntf
LazIDEIntf, IDEOptEditorIntf,
//
UConst;
{ TExWinSettings }
// -------- The Options Group ID, and, perhaps, a place in the Tree View -------
type
TExWinSettings = class(TAbstractIDEEnvironmentOptions) // needed by options group.
private
public
constructor Create(const {%H-}pbReadRegFile: boolean);
destructor Destroy; override;
class function GetGroupCaption: String; override;
class function GetInstance: TAbstractIDEOptions; override;
procedure DoAfterWrite({%H-}Restore: boolean); override;
end;
// ------ This is the Frame displayed when user clicks the Tree View note ------
type
{ TExWinSettingsFrame }
TExWinSettingsFrame = class(TAbstractIDEOptionsEditor)
ButtonDefault: TButton;
DirectoryEdit1: TDirectoryEdit;
Label1: TLabel;
procedure ButtonDefaultClick(Sender: TObject);
private
DefaultExamplesHome : string;
public
constructor Create(TheOwner: TComponent); override;
destructor Destroy; override;
function GetTitle: String; override;
procedure ReadSettings({%H-}AOptions: TAbstractIDEOptions); override;
procedure Setup({%H-}ADialog: TAbstractOptionsEditorDialog); override;
class function SupportedOptionsClass: TAbstractIDEOptionsClass; override;
procedure WriteSettings({%H-}AOptions: TAbstractIDEOptions); override;
procedure RestoreSettings({%H-}AOptions: TAbstractIDEOptions); override;
end;
var
ExWindowOptionsGroup : integer;
ExWinOptionsFrameID : integer;
implementation
{$R *.lfm}
{ TExWinSettings }
constructor TExWinSettings.Create(const pbReadRegFile: boolean);
begin
// inherited Create;
end;
destructor TExWinSettings.Destroy;
begin
inherited Destroy;
end;
class function TExWinSettings.GetGroupCaption: String;
begin
Result := rsExampleProjects;
end;
class function TExWinSettings.GetInstance: TAbstractIDEOptions;
begin
//result := TAbstractIDEOptions(self); // Nope, it does not like that !
result := nil;
end;
procedure TExWinSettings.DoAfterWrite(Restore: boolean);
begin
inherited DoAfterWrite(Restore);
end;
{ TExWinSettingsFrame }
procedure TExWinSettingsFrame.ButtonDefaultClick(Sender: TObject);
begin
DirectoryEdit1.Text := DefaultExamplesHome;
end;
constructor TExWinSettingsFrame.Create(TheOwner: TComponent);
begin
inherited Create(TheOwner);
DefaultExamplesHome := AppendPathDelim(LazarusIDE.GetPrimaryConfigPath)
+ AppendPathDelim(cExamplesDir);
end;
destructor TExWinSettingsFrame.Destroy;
begin
inherited Destroy;
end;
function TExWinSettingsFrame.GetTitle: String;
begin
Result := rsGeneral;
end;
procedure TExWinSettingsFrame.ReadSettings(AOptions: TAbstractIDEOptions);
var
Config: TConfigStorage;
begin
try
Config := GetIDEConfigStorage(cConfigFileName, true);
try
DirectoryEdit1.Text := Config.GetValue('Examples/Directory', DefaultExamplesHome);
finally
Config.Free;
end;
except
on E: Exception do begin
DebugLn('TExWinSettingsFrame.ReadSettings Loading ' + cConfigFileName + ' failed: ' + E.Message);
end;
end;
end;
// Maybe the initial settings before we have a config file ? Labels and Captions.
procedure TExWinSettingsFrame.Setup(ADialog: TAbstractOptionsEditorDialog);
begin
Label1.Caption := rsDirWhereExamplesGo;
ButtonDefault.Caption := rsDefault;
end;
class function TExWinSettingsFrame.SupportedOptionsClass: TAbstractIDEOptionsClass;
begin
Result := nil;
end;
// Gets called whenever user opens Options tree.
procedure TExWinSettingsFrame.WriteSettings(AOptions: TAbstractIDEOptions);
var
Config: TConfigStorage;
begin
try
Config := GetIDEConfigStorage(cConfigFileName,false);
try
Config.SetDeleteValue('Examples/Directory',DirectoryEdit1.Text, DefaultExamplesHome);
finally
Config.Free;
end;
except
on E: Exception do begin
DebugLn('TExWinSettingsFrame.ReadSettings Saving ' + cConfigFileName + ' failed: ' + E.Message);
end;
end;
end;
procedure TExWinSettingsFrame.RestoreSettings(AOptions: TAbstractIDEOptions);
begin
inherited RestoreSettings(AOptions);
end;
initialization
ExWindowOptionsGroup := GetFreeIDEOptionsGroupIndex(GroupEditor);
RegisterIDEOptionsGroup(ExWindowOptionsGroup, TExWinSettings, False); // F cos I get Index from above line. I think.
end.
|