mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-04-15 21:29:50 +02:00
educationlaz: implemented hiding menu items
git-svn-id: trunk@22241 -
This commit is contained in:
parent
1a06444518
commit
5ea22214c6
@ -38,7 +38,7 @@ type
|
||||
|
||||
TEduGeneralOptions = class(TEduOptionsNode)
|
||||
public
|
||||
constructor Create;
|
||||
constructor Create; override;
|
||||
destructor Destroy; override;
|
||||
function Load(Config: TConfigStorage): TModalResult; override;
|
||||
function Save(Config: TConfigStorage): TModalResult; override;
|
||||
|
@ -45,6 +45,8 @@ type
|
||||
function Load(Config: TConfigStorage): TModalResult; override;
|
||||
function Save(Config: TConfigStorage): TModalResult; override;
|
||||
function MenuItemToPath(Item: TIDEMenuItem): string;
|
||||
function FindItemWithPath(Path: string): TIDEMenuItem;
|
||||
function KeepItemVisible(Item: TIDEMenuItem): boolean;
|
||||
procedure Apply(Enable: boolean); override;
|
||||
property MenuHidden[MenuPath: string]: boolean read GetMenuHidden write SetMenuHidden;
|
||||
end;
|
||||
@ -200,12 +202,33 @@ end;
|
||||
procedure TEduMenuFrame.SaveMenuTree;
|
||||
var
|
||||
TVNode: TTreeNode;
|
||||
NewHide: Boolean;
|
||||
OldHide: boolean;
|
||||
Item: TIDEMenuItem;
|
||||
Path: String;
|
||||
OldHidden: TStringToStringTree;
|
||||
begin
|
||||
EduMenuOptions.ClearHMenuidden;
|
||||
TVNode:=MenusTreeView.Items.GetFirstNode;
|
||||
while TVNode<>nil do begin
|
||||
EduMenuOptions.MenuHidden[TVNodeToIDEMenuPath(TVNode)]:=TVNode.StateIndex=HideImgID;
|
||||
TVNode:=TVNode.GetNext;
|
||||
OldHidden:=TStringToStringTree.Create(false);
|
||||
try
|
||||
OldHidden.Assign(EduMenuOptions.fHidden);
|
||||
EduMenuOptions.ClearHMenuidden;
|
||||
TVNode:=MenusTreeView.Items.GetFirstNode;
|
||||
while TVNode<>nil do begin
|
||||
NewHide:=TVNode.StateIndex=HideImgID;
|
||||
Path:=TVNodeToIDEMenuPath(TVNode);
|
||||
OldHide:=OldHidden.Contains(Path);
|
||||
EduMenuOptions.MenuHidden[Path]:=NewHide;
|
||||
if NewHide<>OldHide then begin
|
||||
Item:=EduMenuOptions.FindItemWithPath(Path);
|
||||
if (Item<>nil) and (not EduMenuOptions.KeepItemVisible(Item)) then begin
|
||||
Item.Visible:=not NewHide;
|
||||
//debugln(['TEduMenuFrame.SaveMenuTree changed visibility: ',Item.GetPath,' visible=',Item.Visible,' Path=',Path,' OldHide=',OldHide,' NewHide=',NewHide]);
|
||||
end;
|
||||
end;
|
||||
TVNode:=TVNode.GetNext;
|
||||
end;
|
||||
finally
|
||||
OldHidden.Free;
|
||||
end;
|
||||
end;
|
||||
|
||||
@ -224,10 +247,8 @@ procedure TEduMenuFrame.UpdateTVNodeImage(TVNode: TTreeNode);
|
||||
|
||||
function ContainsHiddenNode(Node: TTreeNode): boolean;
|
||||
begin
|
||||
if (Node.StateIndex=HideImgID) and (Node<>TVNode) then begin
|
||||
debugln(['ContainsHiddenNode hidden Node=',Node.Text,' tvNode=',TVNode.Text]);
|
||||
if (Node.StateIndex=HideImgID) and (Node<>TVNode) then
|
||||
exit(true);
|
||||
end;
|
||||
Node:=Node.GetFirstChild;
|
||||
while Node<>nil do begin
|
||||
if ContainsHiddenNode(Node) then exit(true);
|
||||
@ -236,11 +257,8 @@ procedure TEduMenuFrame.UpdateTVNodeImage(TVNode: TTreeNode);
|
||||
Result:=false;
|
||||
end;
|
||||
|
||||
var
|
||||
OldStateIndex: LongInt;
|
||||
begin
|
||||
if TVNode=nil then exit;
|
||||
OldStateIndex:=TVNode.StateIndex;
|
||||
if TVNode.StateIndex=HideImgID then
|
||||
TVNode.StateIndex:=HideImgID
|
||||
else if ContainsHiddenNode(TVNode) then
|
||||
@ -380,10 +398,40 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
function TEduMenuOptions.FindItemWithPath(Path: string): TIDEMenuItem;
|
||||
begin
|
||||
Result:=IDEMenuRoots.FindByPath(Path,false);
|
||||
end;
|
||||
|
||||
function TEduMenuOptions.KeepItemVisible(Item: TIDEMenuItem): boolean;
|
||||
begin
|
||||
if (Item=mnuEnvironment) or (Item.HasAsParent(mnuEnvironment)) then exit(true);
|
||||
Result:=false;
|
||||
end;
|
||||
|
||||
procedure TEduMenuOptions.Apply(Enable: boolean);
|
||||
|
||||
procedure ApplyRecursive(Item: TIDEMenuItem);
|
||||
var
|
||||
Section: TIDEMenuSection;
|
||||
i: Integer;
|
||||
begin
|
||||
if (not KeepItemVisible(Item)) and MenuHidden[MenuItemToPath(Item)] then
|
||||
Item.Visible:=false;
|
||||
// Note: do not show items. Some items should be hidden independent of education.
|
||||
if Item is TIDEMenuSection then begin
|
||||
Section:=TIDEMenuSection(Item);
|
||||
for i:=0 to Section.Count-1 do
|
||||
ApplyRecursive(Section[i]);
|
||||
end;
|
||||
end;
|
||||
|
||||
var
|
||||
i: Integer;
|
||||
begin
|
||||
inherited Apply(Enable);
|
||||
// ToDo
|
||||
for i:=0 to IDEMenuRoots.Count-1 do
|
||||
ApplyRecursive(IDEMenuRoots[i]);
|
||||
end;
|
||||
|
||||
initialization
|
||||
|
@ -90,6 +90,7 @@ type
|
||||
function GetContainerSection: TIDEMenuSection;
|
||||
function GetContainerMenuItem: TMenuItem;
|
||||
function Size: integer; virtual;
|
||||
function HasAsParent(Item: TIDEMenuItem): boolean;
|
||||
procedure WriteDebugReport(const Prefix: string;
|
||||
MenuItemDebugReport: boolean); virtual;
|
||||
procedure ConsistencyCheck; virtual;
|
||||
@ -797,6 +798,18 @@ begin
|
||||
Result:=FSize;
|
||||
end;
|
||||
|
||||
function TIDEMenuItem.HasAsParent(Item: TIDEMenuItem): boolean;
|
||||
var
|
||||
CurItem: TIDEMenuSection;
|
||||
begin
|
||||
CurItem:=Section;
|
||||
while CurItem<>nil do begin
|
||||
if CurItem=Item then exit(true);
|
||||
CurItem:=CurItem.Section;
|
||||
end;
|
||||
Result:=false;
|
||||
end;
|
||||
|
||||
procedure TIDEMenuItem.WriteDebugReport(const Prefix: string;
|
||||
MenuItemDebugReport: boolean);
|
||||
begin
|
||||
|
@ -192,6 +192,7 @@ type
|
||||
constructor Create(const ACompareItems, ACompareNameWithItem: TListSortCompare);
|
||||
destructor Destroy; override;
|
||||
procedure Clear;
|
||||
procedure Assign(Src: TStringToStringTree);
|
||||
function Contains(const Name: string): Boolean;
|
||||
procedure Delete(const Name: string);
|
||||
procedure Add(const Name, Value, Delimiter: string);
|
||||
@ -1428,6 +1429,21 @@ begin
|
||||
FItems.Clear;
|
||||
end;
|
||||
|
||||
procedure TStringToStringTree.Assign(Src: TStringToStringTree);
|
||||
var
|
||||
Node: TAvgLvlTreeNode;
|
||||
Item: PStringToStringItem;
|
||||
begin
|
||||
Clear;
|
||||
if Src=nil then exit;
|
||||
Node:=Src.Tree.FindLowest;
|
||||
while Node<>nil do begin
|
||||
Item:=PStringToStringItem(Node.Data);
|
||||
Values[Item^.Name]:=Item^.Value;
|
||||
Node:=Src.Tree.FindSuccessor(Node);
|
||||
end;
|
||||
end;
|
||||
|
||||
function TStringToStringTree.Contains(const Name: string): Boolean;
|
||||
begin
|
||||
Result:=FindNode(Name)<>nil;
|
||||
|
Loading…
Reference in New Issue
Block a user