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 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482
|
{
*****************************************************************************
This file is part of the EducationLaz package
See the file COPYING.modifiedLGPL.txt, included in this distribution,
for details about the license.
*****************************************************************************
Author: Mattias Gaertner
Abstract:
Options.
}
unit EduOptions;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, LCLProc, LazConfigStorage, Controls, Forms, BaseIDEIntf,
LazFileUtils, LazIDEIntf, IDEOptionsIntf, ProjectIntf;
resourcestring
EduRSEducation = 'Education';
ersShowAll = 'Show all';
ersHideAll = 'Hide all';
ersShowExtended = 'Show Extended';
ersShowMinimal = 'Show Minimal';
ersVisibleComponents = 'Visible components';
ersShowAllChilds = 'Show all children';
ersIDEMenuItems = 'IDE menu items';
ersNewSingleFileProgram = 'New single file program';
ersNewSingleFileEducationProgram = 'New single file education program';
ersNewProgram = 'New program';
ersAddIcon = 'Add icon';
ersAddASpeedButtonToTheIDEToolbarToCreateANewProgram = 'Add a speed button '
+'to the IDE toolbar to create a new program';
ersAddMenuItem = 'Add menu item';
ersAddAnIDEMenuItemToCreateANewProgram = 'Add an IDE menu item to create a new program';
ersAddToNewDialog = 'Add to %sNew ...%s dialog';
ersAddAnEntryToTheNewDialogToCreateANewProgram = 'Add an entry to the %'
+'sNew ...%s dialog to create a new program';
ersSource = 'Source';
ersSingleFileProgram = 'Single file program';
ersASimpleProgramOnlyOneFileIsCreatedAndAddedToTheCur = 'A simple program. '
+'Only one file is created and added to the current project.';
ersLoadDefaultCode = 'Load default code?';
ersReplaceCurrentWithDefaultSourceCode = 'Replace current with default '
+'source code?';
ersReplaceCurrentSourceWithDefaultSourceCode = 'Replace current source with '
+'default source code';
ersLoadSourceFromFile = 'Load source from file';
ersGrpBoxPropsMin = 'Properties: Minimal Configuration';
ersGrpBoxPropsExt = 'Properties: Extended Configuration';
ersGrpBoxPropsFull = 'Properties: Full Configuration';
ersGrpBoxEventsMin = 'Events: Minimal Configuration';
ersGrpBoxEventsExt = 'Events: Extended Configuration';
ersGrpBoxEventsFull = 'Events: Full Configuration';
ersStTextPropsMin = 'Name, Caption, Visible, Text, Checked, Items, Font, Color, Enabled, Height, Width, MaxLength, Picture, Columns';
ersStTextPropsExt ='Align, Left, Top, Hint, ShowHint, ParentFont, TabOrder, ParentShowHint, WordWrap, FixedCols, FixedRows, DefaultColWidth, DefaultRowHeight, ColCount, RowCount, Borderstyle, Glyph, State, Interval, DataSource, DataField + DB-Properties';
ersStTextPropsFull = 'All Properties available';
ersStTextEventsMin = 'OnClick, OnChange, OnMouseMove';
ersStTextEventsExt = 'OnClick, OnChange, OnMouseMove, OnDblClick, OnCreate, OnKeyPress, OnFormCreate';
ersStTextEventsFull = 'All Events available';
ersRdGrpPropsCaption = 'Properties';
ersRdGrpEventsCaption = 'Events';
ersEduEnvOptsFrameTitle = 'General';
ersEduPropsEventsTitle = 'Properties and Events';
ersEduCompPaletteTitle = 'Component palette';
ersEduNewProgramTitle = 'New program';
ersEduMenuTitle = 'Menus';
ersEduOIPages = 'Object Inspector';
ersRdBtnFull = 'Show All';
ersEnableEduCheckBoxCaption = 'Enable education settings';
ersShowOIPages = 'Show Object Inspector Pages';
ersEduSBTitle = 'Speed Buttons';
ersShowSelection = 'Show Selection';
ersVisibleSpeedButtons = 'Visible SpeedButtons';
const
DefaultEduOptionsFilename = 'education.xml';
var
EduOptionID: integer = 2000;
EduOptionGeneralID: integer = 100;
EduOptionCompPaletteID: integer = 200;
EduOptionMenuID: integer = 300;
EduOptionNewPrgID: integer = 400;
EduPropsEventsOptionsID: integer = 500;
EduOIPagesOptionsID: integer = 600;
EduSpeedButtonsOptionsID: integer = 700;
type
{ TEduOptionsNode }
TEduOptionsNode = class(TPersistent)
private
FChilds: TFPList; // list of TEduOptionsNode
FName: string;
FNextSibling: TEduOptionsNode;
FParent: TEduOptionsNode;
FPrevSibling: TEduOptionsNode;
function GetChildCount: integer;
function GetChilds(Index: integer): TEduOptionsNode;
procedure SetName(const AValue: string);
public
constructor Create; virtual;
destructor Destroy; override;
procedure Clear; virtual;
procedure Delete(Index: integer); virtual;
procedure Remove(Index: integer); virtual;
procedure Add(Node: TEduOptionsNode);
procedure Insert(Index: integer; Node: TEduOptionsNode);
procedure Unbind;
function Load(Config: TConfigStorage): TModalResult; virtual;
function Save(Config: TConfigStorage): TModalResult; virtual;
procedure Changed; virtual;
procedure Apply(Enable: boolean); virtual;
public
property Name: string read FName write SetName;
property Parent: TEduOptionsNode read FParent;
property NextSibling: TEduOptionsNode read FNextSibling;
property PrevSibling: TEduOptionsNode read FPrevSibling;
property ChildCount: integer read GetChildCount;
property Children[Index: integer]: TEduOptionsNode read GetChilds; default;
end;
{ TEduOptsRootNode }
TEduOptsRootNode = class(TEduOptionsNode)
private
FChangeStep: integer;
procedure SetChangeStep(const AValue: integer);
public
procedure Changed; override;
procedure IncreaseChangeStep;
property ChangeStep: integer read FChangeStep write SetChangeStep;
end;
TEduOptions = class(TAbstractIDEEnvironmentOptions)
private
FEnabled: boolean;
FFilename: string;
FNeedLoad: boolean;
FRoot: TEduOptionsNode;
FLastSavedChangeStep: integer;
procedure SetEnabled(const AValue: boolean);
procedure SetFilename(const AValue: string);
public
constructor Create;
destructor Destroy; override;
class function GetGroupCaption: string; override;
class function GetInstance: TAbstractIDEOptions; override;
property Root: TEduOptionsNode read FRoot;
function Load(Config: TConfigStorage): TModalResult; virtual;
function Save(Config: TConfigStorage): TModalResult; virtual;
function LoadFromFile(Filename: string): TModalResult; virtual;
function SaveToFile(Filename: string): TModalResult; virtual;
function Load: TModalResult; virtual;
function Save: TModalResult; virtual;
procedure DoAfterWrite(Restore: boolean); override;
procedure Apply; virtual;
function GetFullFilename: string;
function OnProjectOpened(Sender: TObject; {%H-}AProject: TLazProject): TModalResult;
property Filename: string read FFilename write SetFilename;
property Enabled: boolean read FEnabled write SetEnabled;
property NeedLoad: boolean read FNeedLoad write FNeedLoad;
end;
type
EducationIDEOptionsClass = TAbstractIDEEnvironmentOptions;
var
EducationOptions: TEduOptions = nil;
implementation
{ TEduOptionsNode }
procedure TEduOptionsNode.SetName(const AValue: string);
begin
if FName=AValue then exit;
FName:=AValue;
end;
function TEduOptionsNode.GetChilds(Index: integer): TEduOptionsNode;
begin
Result:=TEduOptionsNode(fChilds[Index]);
end;
function TEduOptionsNode.GetChildCount: integer;
begin
Result:=fChilds.Count;
end;
constructor TEduOptionsNode.Create;
begin
fChilds:=TFPList.Create;
end;
destructor TEduOptionsNode.Destroy;
begin
Clear;
FreeAndNil(fChilds);
inherited Destroy;
end;
procedure TEduOptionsNode.Clear;
begin
while ChildCount>0 do Delete(ChildCount-1);
end;
procedure TEduOptionsNode.Delete(Index: integer);
var
Child: TEduOptionsNode;
begin
Child:=Children[Index];
Remove(Index);
Child.Free;
end;
procedure TEduOptionsNode.Remove(Index: integer);
var
Child: TEduOptionsNode;
begin
Child:=Children[Index];
fChilds.Delete(Index);
Child.FParent:=nil;
Child.Unbind;
end;
procedure TEduOptionsNode.Add(Node: TEduOptionsNode);
begin
Insert(ChildCount,Node);
end;
procedure TEduOptionsNode.Insert(Index: integer; Node: TEduOptionsNode);
begin
Node.Unbind;
FChilds.Insert(Index,Node);
Node.FParent:=Self;
if Index>0 then begin
Node.FPrevSibling:=Children[Index-1];
Node.FPrevSibling.FNextSibling:=Node;
end;
if Index+1<ChildCount then begin
Node.FNextSibling:=Children[Index+1];
Node.FNextSibling.FPrevSibling:=Node;
end;
end;
procedure TEduOptionsNode.Unbind;
begin
if FParent<>nil then
FParent.fChilds.Remove(Self);
FParent:=nil;
if FPrevSibling<>nil then
FPrevSibling.FNextSibling:=FNextSibling;
if FNextSibling<>nil then
FNextSibling.FPrevSibling:=FPrevSibling;
FPrevSibling:=nil;
FNextSibling:=nil;
end;
function TEduOptionsNode.Load(Config: TConfigStorage): TModalResult;
var
i: Integer;
Child: TEduOptionsNode;
begin
for i:=0 to ChildCount-1 do begin
Child:=Children[i];
if not IsValidIdent(Child.Name) then continue;
Config.AppendBasePath(Child.Name);
try
Result:=Child.Load(Config);
if Result<>mrOK then exit;
finally
Config.UndoAppendBasePath;
end;
end;
Result:=mrOk;
end;
function TEduOptionsNode.Save(Config: TConfigStorage): TModalResult;
var
i: Integer;
Child: TEduOptionsNode;
begin
for i:=0 to ChildCount-1 do begin
Child:=Children[i];
if not IsValidIdent(Child.Name) then continue;
Config.AppendBasePath(Child.Name);
try
Result:=Child.Save(Config);
if Result<>mrOK then exit;
finally
Config.UndoAppendBasePath;
end;
end;
Result:=mrOk;
end;
procedure TEduOptionsNode.Changed;
begin
if FParent<>nil then FParent.Changed;
end;
procedure TEduOptionsNode.Apply(Enable: boolean);
var
i: Integer;
begin
for i:=0 to ChildCount-1 do
Children[i].Apply(Enable);
end;
{ TEduOptions }
procedure TEduOptions.SetFilename(const AValue: string);
begin
if FFilename=AValue then exit;
FFilename:=AValue;
end;
procedure TEduOptions.SetEnabled(const AValue: boolean);
begin
if FEnabled=AValue then exit;
FEnabled:=AValue;
Root.Changed;
Apply;
end;
constructor TEduOptions.Create;
begin
FRoot:=TEduOptsRootNode.Create;
FFilename:=DefaultEduOptionsFilename;
FNeedLoad:=true;
end;
destructor TEduOptions.Destroy;
begin
FreeAndNil(FRoot);
inherited Destroy;
end;
class function TEduOptions.GetGroupCaption: string;
begin
Result:=EduRSEducation;
end;
class function TEduOptions.GetInstance: TAbstractIDEOptions;
begin
Result:=EducationOptions;
end;
function TEduOptions.Load(Config: TConfigStorage): TModalResult;
begin
FEnabled:=Config.GetValue('Enabled',false);
Result:=FRoot.Load(Config);
end;
function TEduOptions.Save(Config: TConfigStorage): TModalResult;
begin
Config.SetDeleteValue('Enabled',Enabled,false);
Result:=FRoot.Save(Config);
end;
function TEduOptions.LoadFromFile(Filename: string): TModalResult;
var
Config: TConfigStorage;
begin
Config:=GetIDEConfigStorage(Filename,true);
try
Result:=Load(Config);
finally
Config.Free;
end;
end;
function TEduOptions.SaveToFile(Filename: string): TModalResult;
var
Config: TConfigStorage;
begin
//DebugLn(['TEduOptions.SaveToFile ',Filename]);
Config:=GetIDEConfigStorage(Filename,false);
try
Result:=Save(Config);
finally
Config.Free;
end;
end;
function TEduOptions.Load: TModalResult;
begin
Result:=LoadFromFile(Filename);
FLastSavedChangeStep:=TEduOptsRootNode(Root).ChangeStep;
end;
function TEduOptions.Save: TModalResult;
var
FullFilename: String;
begin
FullFilename:=GetFullFilename;
if FileExistsUTF8(FullFilename)
and (FLastSavedChangeStep=TEduOptsRootNode(Root).ChangeStep) then
Result:=mrOK;
Result:=SaveToFile(Filename);
FLastSavedChangeStep:=TEduOptsRootNode(Root).ChangeStep;
end;
procedure TEduOptions.DoAfterWrite(Restore: boolean);
begin
inherited DoAfterWrite(Restore);
if not Restore then begin
if EducationOptions.Save<>mrOk then
DebugLn(['TEduOptions.DoAfterWrite Failed']);
Apply;
end;
end;
procedure TEduOptions.Apply;
begin
//DebugLn(['TEduOptions.Apply ']);
Root.Apply(Enabled);
end;
function TEduOptions.GetFullFilename: string;
begin
Result:=Filename;
if FilenameIsAbsolute(Result) then exit;
Result:=AppendPathDelim(LazarusIDE.GetPrimaryConfigPath)+Result;
end;
function TEduOptions.OnProjectOpened(Sender: TObject; AProject: TLazProject
): TModalResult;
begin
Result:=mrOk;
if NeedLoad then
Load;
Apply;
end;
{ TEduOptsRootNode }
procedure TEduOptsRootNode.SetChangeStep(const AValue: integer);
begin
if FChangeStep=AValue then exit;
FChangeStep:=AValue;
end;
procedure TEduOptsRootNode.Changed;
begin
inherited Changed;
IncreaseChangeStep;
end;
procedure TEduOptsRootNode.IncreaseChangeStep;
begin
if FChangeStep=High(FChangeStep) then
FChangeStep:=low(FChangeStep)
else
inc(FChangeStep);
end;
initialization
EducationOptions:=TEduOptions.Create;
finalization
FreeAndNil(EducationOptions);
end.
|