educationlaz: added frame for component palette

git-svn-id: trunk@22229 -
This commit is contained in:
mattias 2009-10-19 12:01:05 +00:00
parent 24b6026795
commit 94eb8856f3
10 changed files with 373 additions and 261 deletions

3
.gitattributes vendored
View File

@ -693,6 +693,9 @@ components/editortoolbar/toolbar.lrs svneol=native#text/pascal
components/education/README.txt svneol=native#text/plain
components/education/educationlaz.lpk svneol=native#text/plain
components/education/educationlaz.pas svneol=native#text/plain
components/education/educomppalette.lfm svneol=native#text/plain
components/education/educomppalette.lrs svneol=native#text/plain
components/education/educomppalette.pas svneol=native#text/plain
components/education/eduenvoptsframe.lfm svneol=native#text/plain
components/education/eduenvoptsframe.lrs svneol=native#text/plain
components/education/eduenvoptsframe.pas svneol=native#text/plain

View File

@ -15,11 +15,11 @@
<Description Value="IDE package for training, courses and education."/>
<License Value="LGPL-2 or any later"/>
<Version Major="1" Release="1"/>
<Files Count="4">
<Files Count="5">
<Item1>
<Filename Value="eduenvoptsframe.pas"/>
<HasRegisterProc Value="True"/>
<UnitName Value="eduenvoptsframe"/>
<UnitName Value="EduEnvOptsFrame"/>
</Item1>
<Item2>
<Filename Value="README.txt"/>
@ -34,6 +34,10 @@
<HasRegisterProc Value="True"/>
<UnitName Value="EduPkgSystem"/>
</Item4>
<Item5>
<Filename Value="educomppalette.pas"/>
<UnitName Value="EduCompPalette"/>
</Item5>
</Files>
<i18n>
<OutDir Value="languages"/>

View File

@ -7,7 +7,8 @@ unit EducationLaz;
interface
uses
EduEnvOptsFrame, EduOptions, EduPkgSystem, LazarusPackageIntf;
EduEnvOptsFrame, EduOptions, EduPkgSystem, EduCompPalette,
LazarusPackageIntf;
implementation

View File

@ -0,0 +1,37 @@
inherited EduCompPaletteFrame: TEduCompPaletteFrame
Height = 380
Width = 480
ClientHeight = 380
ClientWidth = 480
TabOrder = 0
DesignLeft = 395
DesignTop = 160
object ComponentsGroupBox: TGroupBox[0]
AnchorSideLeft.Control = Owner
AnchorSideTop.Control = Owner
AnchorSideBottom.Control = Owner
AnchorSideBottom.Side = asrBottom
Left = 6
Height = 368
Top = 6
Width = 290
Anchors = [akTop, akLeft, akBottom]
BorderSpacing.Around = 6
Caption = 'ComponentsGroupBox'
ClientHeight = 346
ClientWidth = 282
TabOrder = 0
object ComponentsTreeView: TTreeView
Left = 0
Height = 346
Top = 0
Width = 282
Align = alClient
DefaultItemHeight = 19
ReadOnly = True
TabOrder = 0
OnMouseDown = ComponentsTreeViewMouseDown
Options = [tvoAutoItemHeight, tvoHideSelection, tvoKeepCollapsedNodes, tvoReadOnly, tvoShowButtons, tvoShowLines, tvoShowRoot, tvoToolTips]
end
end
end

View File

@ -0,0 +1,18 @@
{ This is an automatically generated lazarus resource file }
LazarusResources.Add('TEduCompPaletteFrame','FORMDATA',[
'TPF0'#241#20'TEduCompPaletteFrame'#19'EduCompPaletteFrame'#6'Height'#3'|'#1#5
+'Width'#3#224#1#12'ClientHeight'#3'|'#1#11'ClientWidth'#3#224#1#8'TabOrder'#2
+#0#10'DesignLeft'#3#139#1#9'DesignTop'#3#160#0#0#242#2#0#9'TGroupBox'#18'Com'
+'ponentsGroupBox'#22'AnchorSideLeft.Control'#7#5'Owner'#21'AnchorSideTop.Con'
+'trol'#7#5'Owner'#24'AnchorSideBottom.Control'#7#5'Owner'#21'AnchorSideBotto'
+'m.Side'#7#9'asrBottom'#4'Left'#2#6#6'Height'#3'p'#1#3'Top'#2#6#5'Width'#3'"'
+#1#7'Anchors'#11#5'akTop'#6'akLeft'#8'akBottom'#0#20'BorderSpacing.Around'#2
+#6#7'Caption'#6#18'ComponentsGroupBox'#12'ClientHeight'#3'Z'#1#11'ClientWidt'
+'h'#3#26#1#8'TabOrder'#2#0#0#9'TTreeView'#18'ComponentsTreeView'#4'Left'#2#0
+#6'Height'#3'Z'#1#3'Top'#2#0#5'Width'#3#26#1#5'Align'#7#8'alClient'#17'Defau'
+'ltItemHeight'#2#19#8'ReadOnly'#9#8'TabOrder'#2#0#11'OnMouseDown'#7#27'Compo'
+'nentsTreeViewMouseDown'#7'Options'#11#17'tvoAutoItemHeight'#16'tvoHideSelec'
+'tion'#21'tvoKeepCollapsedNodes'#11'tvoReadOnly'#14'tvoShowButtons'#12'tvoSh'
+'owLines'#11'tvoShowRoot'#11'tvoToolTips'#0#0#0#0#0
]);

View File

@ -0,0 +1,287 @@
{
*****************************************************************************
* *
* This file is part of the EducationLaz package *
* *
* See the file COPYING.modifiedLGPL.txt, included in this distribution, *
* for details about the copyright. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* *
*****************************************************************************
Author: Mattias Gaertner
Abstract:
Frame to setup the component palette.
}
unit EduCompPalette;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, LCLProc, FileUtil, LResources, Forms, Controls, Graphics,
Dialogs, ComCtrls, ExtCtrls, StdCtrls, AvgLvlTree,
FormEditingIntf, LazConfigStorage, IDEOptionsIntf, ComponentReg,
IDEImagesIntf, LazIDEIntf,
EduOptions;
type
{ TEduComponentPaletteOptions }
TEduComponentPaletteOptions = class(TEduOptionsNode)
private
fVisible: TStringToStringTree;
function GetComponentVisible(ComponentName: string): boolean;
procedure SetComponentVisible(ComponentName: string; const AValue: boolean);
public
constructor Create;
destructor Destroy; override;
function Load(Config: TConfigStorage): TModalResult; override;
function Save(Config: TConfigStorage): TModalResult; override;
procedure Apply(Enable: boolean); override;
property ComponentVisible[ComponentName: string]: boolean read GetComponentVisible write SetComponentVisible;
end;
{ TEduCompPaletteFrame }
TEduCompPaletteFrame = class(TAbstractIDEOptionsEditor)
ComponentsGroupBox: TGroupBox;
ComponentsTreeView: TTreeView;
procedure ComponentsTreeViewMouseDown(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
private
HideImgID: LongInt;
ShowImgID: LongInt;
procedure FillComponentTreeView;
procedure SaveFillComponentTreeView;
public
function GetTitle: String; override;
procedure ReadSettings(AOptions: TAbstractIDEOptions); override;
procedure Setup(ADialog: TAbstractOptionsEditorDialog); override;
class function SupportedOptionsClass: TAbstractIDEOptionsClass; override;
procedure WriteSettings(AOptions: TAbstractIDEOptions); override;
end;
var
EduComponentPaletteOptions: TEduComponentPaletteOptions = nil;
procedure Register;
implementation
procedure Register;
begin
EduComponentPaletteOptions:=TEduComponentPaletteOptions.Create;
EducationOptions.Root.Add(EduComponentPaletteOptions);
RegisterIDEOptionsEditor(EduOptionID,TEduCompPaletteFrame,EduOptionCompPaletteID);
end;
{ TEduCompPaletteFrame }
procedure TEduCompPaletteFrame.ComponentsTreeViewMouseDown(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var
Node: TTreeNode;
Hit: THitTests;
begin
if Button<>mbLeft then exit;
Node:=ComponentsTreeView.GetNodeAt(X,Y);
if (Node=nil) then exit;
if Node.Parent=nil then exit;
Hit:=ComponentsTreeView.GetHitTestInfoAt(X,Y);
if htOnStateIcon in Hit then begin
if Node.StateIndex=ShowImgID then
Node.StateIndex:=HideImgID
else
Node.StateIndex:=ShowImgID;
end;
end;
procedure TEduCompPaletteFrame.FillComponentTreeView;
var
i: Integer;
Page: TBaseComponentPage;
j: Integer;
Comp: TRegisteredComponent;
PageNode: TTreeNode;
CompNode: TTreeNode;
ResHandle: TLResource;
Image: TCustomBitmap;
CompName: String;
begin
if ComponentsTreeView.Images=nil then begin
ComponentsTreeView.Images:=TImageList.Create(Self);
ComponentsTreeView.Images.Width:=ComponentPaletteImageWidth;
ComponentsTreeView.Images.Height:=ComponentPaletteImageHeight;
ComponentsTreeView.StateImages:=IDEImages.Images_16;
end else
ComponentsTreeView.Images.Clear;
ShowImgID:=IDEImages.LoadImage(16,'menu_run');
HideImgID:=IDEImages.LoadImage(16,'menu_stop');
ComponentsTreeView.BeginUpdate;
ComponentsTreeView.Items.Clear;
for i:=0 to IDEComponentPalette.Count-1 do begin
Page:=IDEComponentPalette[i];
if Page.PageName='' then continue;
PageNode:=ComponentsTreeView.Items.Add(nil,Page.PageName);
for j:=0 to Page.Count-1 do begin
Comp:=Page[j];
CompName:=Comp.ComponentClass.ClassName;
CompNode:=ComponentsTreeView.Items.AddChild(PageNode,CompName);
ResHandle := LazarusResources.Find(CompName);
if ResHandle <> nil then
Image := CreateBitmapFromLazarusResource(ResHandle)
else
Image := nil;
if Image = nil then
Image := CreateBitmapFromLazarusResource('default');
CompNode.ImageIndex:=ComponentsTreeView.Images.Add(Image,nil);
Image.Free;
CompNode.SelectedIndex:=CompNode.ImageIndex;
if EduComponentPaletteOptions.ComponentVisible[CompName] then
CompNode.StateIndex:=ShowImgID
else
CompNode.StateIndex:=HideImgID;
end;
PageNode.Expanded:=true;
end;
ComponentsTreeView.EndUpdate;
end;
procedure TEduCompPaletteFrame.SaveFillComponentTreeView;
var
Node: TTreeNode;
CompName: String;
begin
Node:=ComponentsTreeView.Items.GetFirstNode;
while Node<>nil do begin
if Node.Parent<>nil then begin
CompName:=Node.Text;
EduComponentPaletteOptions.ComponentVisible[CompName]:=
Node.StateIndex=ShowImgID;
end else begin
end;
Node:=Node.GetNext;
end;
end;
function TEduCompPaletteFrame.GetTitle: String;
begin
Result:='Component palette';
end;
procedure TEduCompPaletteFrame.ReadSettings(AOptions: TAbstractIDEOptions);
begin
end;
procedure TEduCompPaletteFrame.Setup(ADialog: TAbstractOptionsEditorDialog);
begin
ComponentsGroupBox.Caption:='Visible components';
FillComponentTreeView;
end;
class function TEduCompPaletteFrame.SupportedOptionsClass: TAbstractIDEOptionsClass;
begin
Result:=nil;
end;
procedure TEduCompPaletteFrame.WriteSettings(AOptions: TAbstractIDEOptions);
begin
SaveFillComponentTreeView;
end;
{ TEduComponentPaletteOptions }
function TEduComponentPaletteOptions.GetComponentVisible(ComponentName: string
): boolean;
begin
Result:=fVisible[ComponentName]='1';
end;
procedure TEduComponentPaletteOptions.SetComponentVisible(
ComponentName: string; const AValue: boolean);
begin
if AValue then
fVisible[ComponentName]:='1'
else
fVisible.Delete(ComponentName);
end;
constructor TEduComponentPaletteOptions.Create;
begin
inherited Create;
Name:='ComponentPalette';
fVisible:=TStringToStringTree.Create(false);
end;
destructor TEduComponentPaletteOptions.Destroy;
begin
FreeAndNil(fVisible);
inherited Destroy;
end;
function TEduComponentPaletteOptions.Load(Config: TConfigStorage
): TModalResult;
var
Cnt: LongInt;
i: Integer;
ComponentName: String;
begin
fVisible.Clear;
Cnt:=Config.GetValue('Visible/Count',0);
for i:=1 to Cnt do begin
ComponentName:=Config.GetValue('Visible/Item'+IntToStr(i),'');
if ComponentName='' then continue;
fVisible[ComponentName]:='1';
end;
Result:=inherited Load(Config);
end;
function TEduComponentPaletteOptions.Save(Config: TConfigStorage
): TModalResult;
var
Node: TAvgLvlTreeNode;
Item: PStringToStringItem;
Cnt: Integer;
begin
Cnt:=0;
Node:=fVisible.Tree.FindLowest;
while Node<>nil do begin
inc(Cnt);
Item:=PStringToStringItem(Node.Data);
Config.SetDeleteValue('Visible/Item'+IntToStr(Cnt),Item^.Name,'');
Node:=fVisible.Tree.FindSuccessor(Node);
end;
Config.SetDeleteValue('Visible/Count',Cnt,0);
Result:=inherited Save(Config);
end;
procedure TEduComponentPaletteOptions.Apply(Enable: boolean);
var
i: Integer;
Page: TBaseComponentPage;
j: Integer;
Comp: TRegisteredComponent;
begin
inherited Apply(Enable);
for i:=0 to IDEComponentPalette.Count-1 do begin
Page:=IDEComponentPalette[i];
for j:=0 to Page.Count-1 do begin
Comp:=Page[j];
Comp.Visible:=(not Enable) or ComponentVisible[Comp.ComponentClass.ClassName];
end;
end;
end;
initialization
{$I educomppalette.lrs}
end.

View File

@ -5,46 +5,17 @@ inherited EduEnvFrame: TEduEnvFrame
ClientWidth = 495
OnClick = FrameClick
TabOrder = 0
DesignLeft = 358
DesignTop = 198
DesignLeft = 352
DesignTop = 192
object EnableCheckBox: TCheckBox[0]
AnchorSideLeft.Control = Owner
AnchorSideTop.Control = Owner
Left = 6
Height = 22
Height = 18
Top = 6
Width = 130
Width = 124
BorderSpacing.Around = 6
Caption = 'EnableCheckBox'
TabOrder = 0
end
object ComponentsGroupBox: TGroupBox[1]
AnchorSideLeft.Control = Owner
AnchorSideTop.Control = EnableCheckBox
AnchorSideTop.Side = asrBottom
AnchorSideBottom.Control = Owner
AnchorSideBottom.Side = asrBottom
Left = 6
Height = 348
Top = 34
Width = 234
Anchors = [akTop, akLeft, akBottom]
BorderSpacing.Around = 6
Caption = 'ComponentsGroupBox'
ClientHeight = 329
ClientWidth = 230
TabOrder = 1
object ComponentsTreeView: TTreeView
Left = 0
Height = 329
Top = 0
Width = 230
Align = alClient
DefaultItemHeight = 19
ReadOnly = True
TabOrder = 0
OnMouseDown = ComponentsTreeViewMouseDown
Options = [tvoAutoItemHeight, tvoHideSelection, tvoKeepCollapsedNodes, tvoReadOnly, tvoShowButtons, tvoShowLines, tvoShowRoot, tvoToolTips]
end
end
end

View File

@ -3,20 +3,9 @@
LazarusResources.Add('TEduEnvFrame','FORMDATA',[
'TPF0'#241#12'TEduEnvFrame'#11'EduEnvFrame'#6'Height'#3#132#1#5'Width'#3#239#1
+#12'ClientHeight'#3#132#1#11'ClientWidth'#3#239#1#7'OnClick'#7#10'FrameClick'
+#8'TabOrder'#2#0#10'DesignLeft'#3'f'#1#9'DesignTop'#3#198#0#0#242#2#0#9'TChe'
+#8'TabOrder'#2#0#10'DesignLeft'#3'`'#1#9'DesignTop'#3#192#0#0#242#2#0#9'TChe'
+'ckBox'#14'EnableCheckBox'#22'AnchorSideLeft.Control'#7#5'Owner'#21'AnchorSi'
+'deTop.Control'#7#5'Owner'#4'Left'#2#6#6'Height'#2#22#3'Top'#2#6#5'Width'#3
+#130#0#20'BorderSpacing.Around'#2#6#7'Caption'#6#14'EnableCheckBox'#8'TabOrd'
+'er'#2#0#0#0#242#2#1#9'TGroupBox'#18'ComponentsGroupBox'#22'AnchorSideLeft.C'
+'ontrol'#7#5'Owner'#21'AnchorSideTop.Control'#7#14'EnableCheckBox'#18'Anchor'
+'SideTop.Side'#7#9'asrBottom'#24'AnchorSideBottom.Control'#7#5'Owner'#21'Anc'
+'horSideBottom.Side'#7#9'asrBottom'#4'Left'#2#6#6'Height'#3'\'#1#3'Top'#2'"'
+#5'Width'#3#234#0#7'Anchors'#11#5'akTop'#6'akLeft'#8'akBottom'#0#20'BorderSp'
+'acing.Around'#2#6#7'Caption'#6#18'ComponentsGroupBox'#12'ClientHeight'#3'I'
+#1#11'ClientWidth'#3#230#0#8'TabOrder'#2#1#0#9'TTreeView'#18'ComponentsTreeV'
+'iew'#4'Left'#2#0#6'Height'#3'I'#1#3'Top'#2#0#5'Width'#3#230#0#5'Align'#7#8
+'alClient'#17'DefaultItemHeight'#2#19#8'ReadOnly'#9#8'TabOrder'#2#0#11'OnMou'
+'seDown'#7#27'ComponentsTreeViewMouseDown'#7'Options'#11#17'tvoAutoItemHeigh'
+'t'#16'tvoHideSelection'#21'tvoKeepCollapsedNodes'#11'tvoReadOnly'#14'tvoSho'
+'wButtons'#12'tvoShowLines'#11'tvoShowRoot'#11'tvoToolTips'#0#0#0#0#0
+'deTop.Control'#7#5'Owner'#4'Left'#2#6#6'Height'#2#18#3'Top'#2#6#5'Width'#2
+'|'#20'BorderSpacing.Around'#2#6#7'Caption'#6#14'EnableCheckBox'#8'TabOrder'
+#2#0#0#0#0
]);

View File

@ -15,7 +15,7 @@
Author: Mattias Gaertner
Abstract:
Dialog to setup the education package.
Frame to setup the education package.
}
unit EduEnvOptsFrame;
@ -28,7 +28,7 @@ uses
Dialogs, ComCtrls, ExtCtrls, StdCtrls, AvgLvlTree,
FormEditingIntf, LazConfigStorage, IDEOptionsIntf, ComponentReg,
IDEImagesIntf, LazIDEIntf,
EduOptions;
EduOptions, EduCompPalette;
const
EnvOptionsEducation = 2000;
@ -45,36 +45,12 @@ type
function Save(Config: TConfigStorage): TModalResult; override;
end;
{ TEduComponentPaletteOptions }
TEduComponentPaletteOptions = class(TEduOptionsNode)
private
fVisible: TStringToStringTree;
function GetComponentVisible(ComponentName: string): boolean;
procedure SetComponentVisible(ComponentName: string; const AValue: boolean);
public
constructor Create;
destructor Destroy; override;
function Load(Config: TConfigStorage): TModalResult; override;
function Save(Config: TConfigStorage): TModalResult; override;
procedure Apply(Enable: boolean); override;
property ComponentVisible[ComponentName: string]: boolean read GetComponentVisible write SetComponentVisible;
end;
{ TEduEnvFrame }
TEduEnvFrame = class(TAbstractIDEOptionsEditor)
EnableCheckBox: TCheckBox;
ComponentsGroupBox: TGroupBox;
ComponentsTreeView: TTreeView;
procedure ComponentsTreeViewMouseDown(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
procedure FrameClick(Sender: TObject);
private
HideImgID: LongInt;
ShowImgID: LongInt;
procedure FillComponentTreeView;
procedure SaveFillComponentTreeView;
public
constructor Create(TheOwner: TComponent); override;
destructor Destroy; override;
@ -88,7 +64,6 @@ type
var
EduEnvFrame: TEduEnvFrame;
EduGeneralOptions: TEduGeneralOptions = nil;
EduComponentPaletteOptions: TEduComponentPaletteOptions = nil;
procedure Register;
@ -96,15 +71,10 @@ implementation
procedure Register;
begin
RegisterIDEOptionsGroup(EduOptionID,TEduOptions);
RegisterIDEOptionsEditor(EduOptionID,TEduEnvFrame,EduOptionGeneralID);
EduGeneralOptions:=TEduGeneralOptions.Create;
EducationOptions.Root.Add(EduGeneralOptions);
EduComponentPaletteOptions:=TEduComponentPaletteOptions.Create;
EducationOptions.Root.Add(EduComponentPaletteOptions);
// load options
EducationOptions.Load;
RegisterIDEOptionsGroup(EduOptionID,TEduOptions);
RegisterIDEOptionsEditor(EduOptionID,TEduEnvFrame,EduOptionGeneralID);
LazarusIDE.AddHandlerOnProjectOpened(@EducationOptions.OnProjectOpened);
end;
@ -116,100 +86,10 @@ begin
end;
procedure TEduEnvFrame.ComponentsTreeViewMouseDown(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var
Node: TTreeNode;
Hit: THitTests;
begin
if Button<>mbLeft then exit;
Node:=ComponentsTreeView.GetNodeAt(X,Y);
if (Node=nil) then exit;
if Node.Parent=nil then exit;
Hit:=ComponentsTreeView.GetHitTestInfoAt(X,Y);
if htOnStateIcon in Hit then begin
if Node.StateIndex=ShowImgID then
Node.StateIndex:=HideImgID
else
Node.StateIndex:=ShowImgID;
end;
end;
procedure TEduEnvFrame.FillComponentTreeView;
var
i: Integer;
Page: TBaseComponentPage;
j: Integer;
Comp: TRegisteredComponent;
PageNode: TTreeNode;
CompNode: TTreeNode;
ResHandle: TLResource;
Image: TCustomBitmap;
CompName: String;
begin
if ComponentsTreeView.Images=nil then begin
ComponentsTreeView.Images:=TImageList.Create(Self);
ComponentsTreeView.Images.Width:=ComponentPaletteImageWidth;
ComponentsTreeView.Images.Height:=ComponentPaletteImageHeight;
ComponentsTreeView.StateImages:=IDEImages.Images_16;
end else
ComponentsTreeView.Images.Clear;
ShowImgID:=IDEImages.LoadImage(16,'menu_run');
HideImgID:=IDEImages.LoadImage(16,'menu_stop');
ComponentsTreeView.BeginUpdate;
ComponentsTreeView.Items.Clear;
for i:=0 to IDEComponentPalette.Count-1 do begin
Page:=IDEComponentPalette[i];
if Page.PageName='' then continue;
PageNode:=ComponentsTreeView.Items.Add(nil,Page.PageName);
for j:=0 to Page.Count-1 do begin
Comp:=Page[j];
CompName:=Comp.ComponentClass.ClassName;
CompNode:=ComponentsTreeView.Items.AddChild(PageNode,CompName);
ResHandle := LazarusResources.Find(CompName);
if ResHandle <> nil then
Image := CreateBitmapFromLazarusResource(ResHandle)
else
Image := nil;
if Image = nil then
Image := CreateBitmapFromLazarusResource('default');
CompNode.ImageIndex:=ComponentsTreeView.Images.Add(Image,nil);
Image.Free;
CompNode.SelectedIndex:=CompNode.ImageIndex;
if EduComponentPaletteOptions.ComponentVisible[CompName] then
CompNode.StateIndex:=ShowImgID
else
CompNode.StateIndex:=HideImgID;
end;
PageNode.Expanded:=true;
end;
ComponentsTreeView.EndUpdate;
end;
procedure TEduEnvFrame.SaveFillComponentTreeView;
var
Node: TTreeNode;
CompName: String;
begin
Node:=ComponentsTreeView.Items.GetFirstNode;
while Node<>nil do begin
if Node.Parent<>nil then begin
CompName:=Node.Text;
EduComponentPaletteOptions.ComponentVisible[CompName]:=
Node.StateIndex=ShowImgID;
end else begin
end;
Node:=Node.GetNext;
end;
end;
constructor TEduEnvFrame.Create(TheOwner: TComponent);
begin
inherited Create(TheOwner);
ComponentsGroupBox.Caption:='Visible components';
FillComponentTreeView;
end;
destructor TEduEnvFrame.Destroy;
@ -235,7 +115,6 @@ end;
procedure TEduEnvFrame.WriteSettings(AOptions: TAbstractIDEOptions);
begin
EducationOptions.Enabled:=EnableCheckBox.Checked;
SaveFillComponentTreeView;
if EducationOptions.Save<>mrOk then
DebugLn(['TEduEnvFrame.WriteSettings Failed']);
@ -271,89 +150,6 @@ begin
Result:=inherited Save(Config);
end;
{ TEduComponentPaletteOptions }
function TEduComponentPaletteOptions.GetComponentVisible(ComponentName: string
): boolean;
begin
Result:=fVisible[ComponentName]='1';
end;
procedure TEduComponentPaletteOptions.SetComponentVisible(
ComponentName: string; const AValue: boolean);
begin
if AValue then
fVisible[ComponentName]:='1'
else
fVisible.Delete(ComponentName);
end;
constructor TEduComponentPaletteOptions.Create;
begin
inherited Create;
Name:='ComponentPalette';
fVisible:=TStringToStringTree.Create(false);
end;
destructor TEduComponentPaletteOptions.Destroy;
begin
FreeAndNil(fVisible);
inherited Destroy;
end;
function TEduComponentPaletteOptions.Load(Config: TConfigStorage
): TModalResult;
var
Cnt: LongInt;
i: Integer;
ComponentName: String;
begin
fVisible.Clear;
Cnt:=Config.GetValue('Visible/Count',0);
for i:=1 to Cnt do begin
ComponentName:=Config.GetValue('Visible/Item'+IntToStr(i),'');
if ComponentName='' then continue;
fVisible[ComponentName]:='1';
end;
Result:=inherited Load(Config);
end;
function TEduComponentPaletteOptions.Save(Config: TConfigStorage
): TModalResult;
var
Node: TAvgLvlTreeNode;
Item: PStringToStringItem;
Cnt: Integer;
begin
Cnt:=0;
Node:=fVisible.Tree.FindLowest;
while Node<>nil do begin
inc(Cnt);
Item:=PStringToStringItem(Node.Data);
Config.SetDeleteValue('Visible/Item'+IntToStr(Cnt),Item^.Name,'');
Node:=fVisible.Tree.FindSuccessor(Node);
end;
Config.SetDeleteValue('Visible/Count',Cnt,0);
Result:=inherited Save(Config);
end;
procedure TEduComponentPaletteOptions.Apply(Enable: boolean);
var
i: Integer;
Page: TBaseComponentPage;
j: Integer;
Comp: TRegisteredComponent;
begin
inherited Apply(Enable);
for i:=0 to IDEComponentPalette.Count-1 do begin
Page:=IDEComponentPalette[i];
for j:=0 to Page.Count-1 do begin
Comp:=Page[j];
Comp.Visible:=(not Enable) or ComponentVisible[Comp.ComponentClass.ClassName];
end;
end;
end;
initialization
{$I eduenvoptsframe.lrs}

View File

@ -34,8 +34,9 @@ const
DefaultEduOptionsFilename = 'education.xml';
EduOptionID = 2000;
EduOptionGeneralID = 100;
EduOptionPackagesID = 200;
EduOptionGeneralID = 100;
EduOptionCompPaletteID = 200;
EduOptionPackagesID = 300;
type
@ -89,6 +90,7 @@ type
private
FEnabled: boolean;
FFilename: string;
FNeedLoad: boolean;
FRoot: TEduOptionsNode;
FLastSavedChangeStep: integer;
procedure SetEnabled(const AValue: boolean);
@ -109,6 +111,7 @@ type
function OnProjectOpened(Sender: TObject; 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;
var
@ -274,6 +277,7 @@ constructor TEduOptions.Create;
begin
FRoot:=TEduOptsRootNode.Create;
FFilename:=DefaultEduOptionsFilename;
FNeedLoad:=true;
end;
destructor TEduOptions.Destroy;
@ -357,6 +361,8 @@ function TEduOptions.OnProjectOpened(Sender: TObject; AProject: TLazProject
): TModalResult;
begin
Result:=mrOk;
if NeedLoad then
Load;
Apply;
end;