mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-09-03 22:20:17 +02:00
education: using normal options framework
git-svn-id: trunk@20796 -
This commit is contained in:
parent
4574f1311b
commit
207c9b617f
@ -17,9 +17,9 @@
|
||||
<Version Major="1" Release="1"/>
|
||||
<Files Count="4">
|
||||
<Item1>
|
||||
<Filename Value="eduoptionsdlg.pas"/>
|
||||
<Filename Value="eduenvoptsframe.pas"/>
|
||||
<HasRegisterProc Value="True"/>
|
||||
<UnitName Value="EduOptionsDlg"/>
|
||||
<UnitName Value="eduenvoptsframe"/>
|
||||
</Item1>
|
||||
<Item2>
|
||||
<Filename Value="README.txt"/>
|
||||
@ -31,6 +31,7 @@
|
||||
</Item3>
|
||||
<Item4>
|
||||
<Filename Value="edupkgsystem.pas"/>
|
||||
<HasRegisterProc Value="True"/>
|
||||
<UnitName Value="EduPkgSystem"/>
|
||||
</Item4>
|
||||
</Files>
|
||||
|
@ -7,13 +7,14 @@ unit EducationLaz;
|
||||
interface
|
||||
|
||||
uses
|
||||
EduOptionsDlg, EduOptions, LazarusPackageIntf;
|
||||
EduEnvOptsFrame, EduOptions, EduPkgSystem, LazarusPackageIntf;
|
||||
|
||||
implementation
|
||||
|
||||
procedure Register;
|
||||
begin
|
||||
RegisterUnit('EduOptionsDlg', @EduOptionsDlg.Register);
|
||||
RegisterUnit('EduEnvOptsFrame', @EduEnvOptsFrame.Register);
|
||||
RegisterUnit('EduPkgSystem', @EduPkgSystem.Register);
|
||||
end;
|
||||
|
||||
initialization
|
||||
|
@ -24,13 +24,21 @@ unit EduOptions;
|
||||
interface
|
||||
|
||||
uses
|
||||
Classes, SysUtils, LazConfigStorage, Controls, Forms;
|
||||
Classes, SysUtils, LazConfigStorage, Controls, Forms, BaseIDEIntf, FileUtil,
|
||||
LazIDEIntf, IDEOptionsIntf;
|
||||
|
||||
const
|
||||
DefaultEduOptionsFilename = 'education.xml';
|
||||
|
||||
EduOptionID = 2000;
|
||||
EduOptionGeneralID = 100;
|
||||
EduOptionPackagesID = 200;
|
||||
|
||||
type
|
||||
|
||||
{ TEduOptionsNode }
|
||||
|
||||
TEduOptionsNode = class
|
||||
TEduOptionsNode = class(TPersistent)
|
||||
private
|
||||
FChilds: TFPList; // list of TEduOptionsNode
|
||||
FName: string;
|
||||
@ -46,9 +54,12 @@ type
|
||||
procedure Clear; virtual;
|
||||
procedure Delete(Index: integer); virtual;
|
||||
procedure Remove(Index: integer); virtual;
|
||||
function GetCaption: string; 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;
|
||||
public
|
||||
property Name: string read FName write SetName;
|
||||
property Parent: TEduOptionsNode read FParent;
|
||||
@ -58,6 +69,41 @@ type
|
||||
property Childs[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(TAbstractIDEOptions)
|
||||
private
|
||||
FFilename: string;
|
||||
FRoot: TEduOptionsNode;
|
||||
FLastSavedChangeStep: integer;
|
||||
procedure SetFilename(const AValue: string);
|
||||
public
|
||||
constructor Create;
|
||||
destructor Destroy; 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;
|
||||
function GetFullFilename: string;
|
||||
property Filename: string read FFilename write SetFilename;
|
||||
end;
|
||||
|
||||
var
|
||||
EducationOptions: TEduOptions = nil;
|
||||
|
||||
implementation
|
||||
|
||||
{ TEduOptionsNode }
|
||||
@ -111,17 +157,40 @@ begin
|
||||
Child:=Childs[Index];
|
||||
fChilds.Delete(Index);
|
||||
Child.FParent:=nil;
|
||||
if Child.FPrevSibling<>nil then
|
||||
Child.FPrevSibling.FNextSibling:=FNextSibling;
|
||||
if Child.FNextSibling<>nil then
|
||||
Child.FNextSibling.FPrevSibling:=FPrevSibling;
|
||||
Child.FPrevSibling:=nil;
|
||||
Child.FNextSibling:=nil;
|
||||
Child.Unbind;
|
||||
end;
|
||||
|
||||
function TEduOptionsNode.GetCaption: string;
|
||||
procedure TEduOptionsNode.Add(Node: TEduOptionsNode);
|
||||
begin
|
||||
Result:=Name;
|
||||
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:=Childs[Index-1];
|
||||
Node.FPrevSibling.FNextSibling:=Node;
|
||||
end;
|
||||
if Index+1<ChildCount then begin
|
||||
Node.FNextSibling:=Childs[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;
|
||||
@ -156,5 +225,117 @@ begin
|
||||
Result:=mrOk;
|
||||
end;
|
||||
|
||||
procedure TEduOptionsNode.Changed;
|
||||
begin
|
||||
if FParent<>nil then FParent.Changed;
|
||||
end;
|
||||
|
||||
{ TEduOptions }
|
||||
|
||||
procedure TEduOptions.SetFilename(const AValue: string);
|
||||
begin
|
||||
if FFilename=AValue then exit;
|
||||
FFilename:=AValue;
|
||||
end;
|
||||
|
||||
constructor TEduOptions.Create;
|
||||
begin
|
||||
FRoot:=TEduOptsRootNode.Create;
|
||||
FFilename:=DefaultEduOptionsFilename;
|
||||
end;
|
||||
|
||||
destructor TEduOptions.Destroy;
|
||||
begin
|
||||
FreeAndNil(FRoot);
|
||||
inherited Destroy;
|
||||
end;
|
||||
|
||||
function TEduOptions.Load(Config: TConfigStorage): TModalResult;
|
||||
begin
|
||||
Result:=FRoot.Load(Config);
|
||||
end;
|
||||
|
||||
function TEduOptions.Save(Config: TConfigStorage): TModalResult;
|
||||
begin
|
||||
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
|
||||
Config:=GetIDEConfigStorage(Filename,false);
|
||||
try
|
||||
Result:=Save(Config);
|
||||
finally
|
||||
Config.Free;
|
||||
end;
|
||||
end;
|
||||
|
||||
function TEduOptions.Load: TModalResult;
|
||||
begin
|
||||
Result:=LoadFromFile(GetFullFilename);
|
||||
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;
|
||||
|
||||
function TEduOptions.GetFullFilename: string;
|
||||
begin
|
||||
Result:=Filename;
|
||||
if FilenameIsAbsolute(Result) then exit;
|
||||
Result:=AppendPathDelim(LazarusIDE.GetPrimaryConfigPath)+Result;
|
||||
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.
|
||||
|
||||
|
@ -11,7 +11,6 @@ object EduPkgSystemFrame: TEduPkgSystemFrame
|
||||
ChildSizing.ControlsPerLine = 1
|
||||
ClientHeight = 300
|
||||
ClientWidth = 400
|
||||
OnClick = FrameClick
|
||||
TabOrder = 0
|
||||
DesignLeft = 297
|
||||
DesignTop = 171
|
||||
|
@ -24,29 +24,135 @@ unit EduPkgSystem;
|
||||
interface
|
||||
|
||||
uses
|
||||
Classes, SysUtils, FileUtil, LResources, Forms, Controls, StdCtrls;
|
||||
Classes, SysUtils, FileUtil, LResources, Forms, Controls, StdCtrls, EduOptions,
|
||||
LazConfigStorage, IDEOptionsIntf;
|
||||
|
||||
type
|
||||
|
||||
{ TEduPkgSystemOptions }
|
||||
|
||||
TEduPkgSystemOptions = class(TEduOptionsNode)
|
||||
private
|
||||
FHideConfigureInstalledPkgs: boolean;
|
||||
FHideCreatePackage: boolean;
|
||||
FHideOpenPackage: boolean;
|
||||
FHidePackageGraph: boolean;
|
||||
procedure SetHideConfigureInstalledPkgs(const AValue: boolean);
|
||||
procedure SetHideCreatePackage(const AValue: boolean);
|
||||
procedure SetHideOpenPackage(const AValue: boolean);
|
||||
procedure SetHidePackageGraph(const AValue: boolean);
|
||||
public
|
||||
function Load(Config: TConfigStorage): TModalResult; override;
|
||||
function Save(Config: TConfigStorage): TModalResult; override;
|
||||
property HideCreatePackage: boolean read FHideCreatePackage write SetHideCreatePackage;
|
||||
property HideOpenPackage: boolean read FHideOpenPackage write SetHideOpenPackage;
|
||||
property HidePackageGraph: boolean read FHidePackageGraph write SetHidePackageGraph;
|
||||
property HideConfigureInstalledPkgs: boolean read FHideConfigureInstalledPkgs write SetHideConfigureInstalledPkgs;
|
||||
end;
|
||||
|
||||
{ TEduPkgSystemFrame }
|
||||
|
||||
TEduPkgSystemFrame = class(TFrame)
|
||||
TEduPkgSystemFrame = class(TAbstractIDEOptionsEditor)
|
||||
HideCreatePackageCheckBox: TCheckBox;
|
||||
HideOpenPackageCheckBox: TCheckBox;
|
||||
HidePackageGraphCheckBox: TCheckBox;
|
||||
HideConfigureInstalledPkgsCheckBox: TCheckBox;
|
||||
procedure FrameClick(Sender: TObject);
|
||||
private
|
||||
public
|
||||
function GetTitle: String; override;
|
||||
procedure Setup(ADialog: TAbstractOptionsEditorDialog); override;
|
||||
procedure ReadSettings(AOptions: TAbstractIDEOptions); override;
|
||||
procedure WriteSettings(AOptions: TAbstractIDEOptions); override;
|
||||
class function SupportedOptionsClass: TAbstractIDEOptionsClass; override;
|
||||
end;
|
||||
|
||||
procedure Register;
|
||||
|
||||
implementation
|
||||
|
||||
procedure Register;
|
||||
begin
|
||||
//EducationOptions.Root.Add(TEduPkgSystemOptions.Create);
|
||||
//RegisterIDEOptionsEditor(GroupEducation,TEduPkgSystemFrame,EduOptionPackagesID);
|
||||
end;
|
||||
|
||||
{ TEduPkgSystemFrame }
|
||||
|
||||
procedure TEduPkgSystemFrame.FrameClick(Sender: TObject);
|
||||
function TEduPkgSystemFrame.GetTitle: String;
|
||||
begin
|
||||
HideCreatePackageCheckBox.Caption:='Hide items to create new packages';
|
||||
Result:='Packages';
|
||||
end;
|
||||
|
||||
procedure TEduPkgSystemFrame.Setup(ADialog: TAbstractOptionsEditorDialog);
|
||||
begin
|
||||
HideCreatePackageCheckBox.Caption:='Hide menu items to create new packages';
|
||||
HideOpenPackageCheckBox.Caption:='Hide menu items to open package';
|
||||
HidePackageGraphCheckBox.Caption:='Hide menu item package graph';
|
||||
HideConfigureInstalledPkgsCheckBox.Caption:='Hide "Configure installed packages"';
|
||||
end;
|
||||
|
||||
procedure TEduPkgSystemFrame.ReadSettings(AOptions: TAbstractIDEOptions);
|
||||
begin
|
||||
|
||||
end;
|
||||
|
||||
procedure TEduPkgSystemFrame.WriteSettings(AOptions: TAbstractIDEOptions);
|
||||
begin
|
||||
|
||||
end;
|
||||
|
||||
class function TEduPkgSystemFrame.SupportedOptionsClass: TAbstractIDEOptionsClass;
|
||||
begin
|
||||
Result:=TEduOptions;
|
||||
end;
|
||||
|
||||
{ TEduPkgSystemOptions }
|
||||
|
||||
procedure TEduPkgSystemOptions.SetHideConfigureInstalledPkgs(
|
||||
const AValue: boolean);
|
||||
begin
|
||||
if FHideConfigureInstalledPkgs=AValue then exit;
|
||||
FHideConfigureInstalledPkgs:=AValue;
|
||||
Changed;
|
||||
end;
|
||||
|
||||
procedure TEduPkgSystemOptions.SetHideCreatePackage(const AValue: boolean);
|
||||
begin
|
||||
if FHideCreatePackage=AValue then exit;
|
||||
FHideCreatePackage:=AValue;
|
||||
Changed;
|
||||
end;
|
||||
|
||||
procedure TEduPkgSystemOptions.SetHideOpenPackage(const AValue: boolean);
|
||||
begin
|
||||
if FHideOpenPackage=AValue then exit;
|
||||
FHideOpenPackage:=AValue;
|
||||
Changed;
|
||||
end;
|
||||
|
||||
procedure TEduPkgSystemOptions.SetHidePackageGraph(const AValue: boolean);
|
||||
begin
|
||||
if FHidePackageGraph=AValue then exit;
|
||||
FHidePackageGraph:=AValue;
|
||||
Changed;
|
||||
end;
|
||||
|
||||
function TEduPkgSystemOptions.Load(Config: TConfigStorage): TModalResult;
|
||||
begin
|
||||
FHideConfigureInstalledPkgs:=Config.GetValue('HideConfigureInstalledPackages',false);
|
||||
FHideCreatePackage:=Config.GetValue('HideCreatePackage',false);
|
||||
FHideOpenPackage:=Config.GetValue('HideOpenPackage',false);
|
||||
FHidePackageGraph:=Config.GetValue('HidePackageGraph',false);
|
||||
Result:=inherited Load(Config);
|
||||
end;
|
||||
|
||||
function TEduPkgSystemOptions.Save(Config: TConfigStorage): TModalResult;
|
||||
begin
|
||||
Config.SetDeleteValue('HideConfigureInstalledPackages',FHideConfigureInstalledPkgs,false);
|
||||
Config.SetDeleteValue('HideCreatePackage',FHideCreatePackage,false);
|
||||
Config.SetDeleteValue('HideOpenPackage',FHideOpenPackage,false);
|
||||
Config.SetDeleteValue('HidePackageGraph',FHidePackageGraph,false);
|
||||
Result:=inherited Save(Config);
|
||||
end;
|
||||
|
||||
initialization
|
||||
|
Loading…
Reference in New Issue
Block a user