mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-27 00:40:18 +02:00
educationlaz: implemented hide components
git-svn-id: trunk@22177 -
This commit is contained in:
parent
732e56ff88
commit
8372f8ced8
@ -1,8 +1,9 @@
|
||||
inherited EduEnvFrame: TEduEnvFrame
|
||||
Height = 268
|
||||
Width = 359
|
||||
ClientHeight = 268
|
||||
ClientWidth = 344
|
||||
Height = 388
|
||||
Width = 495
|
||||
ClientHeight = 388
|
||||
ClientWidth = 495
|
||||
OnClick = FrameClick
|
||||
TabOrder = 0
|
||||
DesignLeft = 358
|
||||
DesignTop = 198
|
||||
@ -10,11 +11,40 @@ inherited EduEnvFrame: TEduEnvFrame
|
||||
AnchorSideLeft.Control = Owner
|
||||
AnchorSideTop.Control = Owner
|
||||
Left = 6
|
||||
Height = 18
|
||||
Height = 22
|
||||
Top = 6
|
||||
Width = 124
|
||||
Width = 130
|
||||
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
|
||||
|
@ -1,10 +1,22 @@
|
||||
{ This is an automatically generated lazarus resource file }
|
||||
|
||||
LazarusResources.Add('TEduEnvFrame','FORMDATA',[
|
||||
'TPF0'#241#12'TEduEnvFrame'#11'EduEnvFrame'#6'Height'#3#12#1#5'Width'#3'g'#1
|
||||
+#12'ClientHeight'#3#12#1#11'ClientWidth'#3'X'#1#8'TabOrder'#2#0#10'DesignLef'
|
||||
+'t'#3'f'#1#9'DesignTop'#3#198#0#0#242#2#0#9'TCheckBox'#14'EnableCheckBox'#22
|
||||
+'AnchorSideLeft.Control'#7#5'Owner'#21'AnchorSideTop.Control'#7#5'Owner'#4'L'
|
||||
+'eft'#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
|
||||
'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'
|
||||
+'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
|
||||
]);
|
||||
|
@ -25,8 +25,10 @@ interface
|
||||
|
||||
uses
|
||||
Classes, SysUtils, LCLProc, FileUtil, LResources, Forms, Controls, Graphics,
|
||||
Dialogs, ComCtrls, ExtCtrls, StdCtrls,
|
||||
LazConfigStorage, IDEOptionsIntf, EduOptions;
|
||||
Dialogs, ComCtrls, ExtCtrls, StdCtrls, AvgLvlTree,
|
||||
FormEditingIntf, LazConfigStorage, IDEOptionsIntf, ComponentReg,
|
||||
IDEImagesIntf,
|
||||
EduOptions;
|
||||
|
||||
const
|
||||
EnvOptionsEducation = 2000;
|
||||
@ -47,12 +49,39 @@ type
|
||||
property Enabled: boolean read FEnabled write SetEnabled default true;
|
||||
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;
|
||||
function GetTitle: String; override;
|
||||
procedure Setup(ADialog: TAbstractOptionsEditorDialog); override;
|
||||
procedure ReadSettings(AOptions: TAbstractIDEOptions); override;
|
||||
@ -63,6 +92,7 @@ type
|
||||
var
|
||||
EduEnvFrame: TEduEnvFrame;
|
||||
EduGeneralOptions: TEduGeneralOptions = nil;
|
||||
EduComponentPaletteOptions: TEduComponentPaletteOptions = nil;
|
||||
|
||||
procedure Register;
|
||||
|
||||
@ -74,6 +104,8 @@ begin
|
||||
RegisterIDEOptionsEditor(EduOptionID,TEduEnvFrame,EduOptionGeneralID);
|
||||
EduGeneralOptions:=TEduGeneralOptions.Create;
|
||||
EducationOptions.Root.Add(EduGeneralOptions);
|
||||
EduComponentPaletteOptions:=TEduComponentPaletteOptions.Create;
|
||||
EducationOptions.Root.Add(EduComponentPaletteOptions);
|
||||
|
||||
// load options
|
||||
EducationOptions.Load;
|
||||
@ -81,6 +113,111 @@ end;
|
||||
|
||||
{ TEduEnvFrame }
|
||||
|
||||
procedure TEduEnvFrame.FrameClick(Sender: TObject);
|
||||
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);
|
||||
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;
|
||||
begin
|
||||
inherited Destroy;
|
||||
end;
|
||||
|
||||
function TEduEnvFrame.GetTitle: String;
|
||||
begin
|
||||
Result:='General';
|
||||
@ -99,8 +236,11 @@ end;
|
||||
procedure TEduEnvFrame.WriteSettings(AOptions: TAbstractIDEOptions);
|
||||
begin
|
||||
EduGeneralOptions.Enabled:=EnableCheckBox.Checked;
|
||||
SaveFillComponentTreeView;
|
||||
|
||||
if EducationOptions.Save<>mrOk then
|
||||
DebugLn(['TEduEnvFrame.WriteSettings Failed']);
|
||||
EducationOptions.Apply(EduGeneralOptions.Enabled);
|
||||
end;
|
||||
|
||||
class function TEduEnvFrame.SupportedOptionsClass: TAbstractIDEOptionsClass;
|
||||
@ -142,6 +282,89 @@ 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}
|
||||
|
||||
|
@ -63,6 +63,7 @@ type
|
||||
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;
|
||||
@ -101,6 +102,7 @@ type
|
||||
function SaveToFile(Filename: string): TModalResult; virtual;
|
||||
function Load: TModalResult; virtual;
|
||||
function Save: TModalResult; virtual;
|
||||
procedure Apply(Enable: boolean); virtual;
|
||||
function GetFullFilename: string;
|
||||
property Filename: string read FFilename write SetFilename;
|
||||
end;
|
||||
@ -240,6 +242,14 @@ begin
|
||||
if FParent<>nil then FParent.Changed;
|
||||
end;
|
||||
|
||||
procedure TEduOptionsNode.Apply(Enable: boolean);
|
||||
var
|
||||
i: Integer;
|
||||
begin
|
||||
for i:=0 to ChildCount-1 do
|
||||
Childs[i].Apply(Enable);
|
||||
end;
|
||||
|
||||
{ TEduOptions }
|
||||
|
||||
procedure TEduOptions.SetFilename(const AValue: string);
|
||||
@ -317,6 +327,11 @@ begin
|
||||
FLastSavedChangeStep:=TEduOptsRootNode(Root).ChangeStep;
|
||||
end;
|
||||
|
||||
procedure TEduOptions.Apply(Enable: boolean);
|
||||
begin
|
||||
Root.Apply(Enable);
|
||||
end;
|
||||
|
||||
function TEduOptions.GetFullFilename: string;
|
||||
begin
|
||||
Result:=Filename;
|
||||
|
Loading…
Reference in New Issue
Block a user