Lazarus

Programming => LCL => Topic started by: BeniBela on February 24, 2019, 07:34:55 pm

Title: submenu opened event / lazy menu creation
Post by: BeniBela on February 24, 2019, 07:34:55 pm
Is there any event when a submenu (in a popupmenu) is opened?

I have a very large menu with multiple levels kind of like a file system, so I do not want to create the entire menu at once. Rather when the user opens one submenu/directory, it should initialize that submenu and then the next one only when the user opens another directory.

On GTK it works with OnClick on the directory menuitem, but it does not seem to work on Windows
Title: Re: submenu opened event / lazy menu creation
Post by: Blaazen on February 24, 2019, 08:43:01 pm
No idea where to hook. I tried assign Action to parent MenuItem which works in Qt but not in Wine.
Title: Re: submenu opened event / lazy menu creation
Post by: ASerge on February 24, 2019, 09:07:59 pm
On GTK it works with OnClick on the directory menuitem, but it does not seem to work on Windows
Also work. It is necessary to show before filling somehow that it contains subitems, for example by adding a separator. And by click do something like this:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.MenuGroupClick(Sender: TObject);
  2. var
  3.   CountBefore: Integer;
  4. begin
  5.   CountBefore := MenuGroup.Count;
  6.   MenuGroup.Add(NewItem('Test1', 0, False, True, nil, 0, ''));
  7.   MenuGroup.Add(NewItem('Test2', 0, False, True, nil, 0, ''));
  8.   while CountBefore > 0 do
  9.   begin
  10.     MenuGroup.Items[0].Free;
  11.     Dec(CountBefore);
  12.   end;
  13. end;
Title: Re: submenu opened event / lazy menu creation
Post by: BeniBela on February 25, 2019, 12:44:11 am
That works in a mainmenu, but I cannot get it work in a popupmenu
Title: Re: submenu opened event / lazy menu creation
Post by: jamie on February 25, 2019, 12:46:50 am
Maybe you need to invest in a different way of looking at it, have you thought about using a TtreeView ?

At least with that you can collapse the tree.
Title: Re: submenu opened event / lazy menu creation
Post by: BeniBela on February 25, 2019, 11:55:09 pm
Can you put the treeview in a popupmenu?

I have had it as popupmenu for years, and just recently decided it  is becoming  too big for normal initialization. It is a popupmenu, so the menu can be opened with a toolbar button
Title: Re: submenu opened event / lazy menu creation
Post by: BeniBela on March 13, 2019, 12:48:36 pm
https://bugs.freepascal.org/view.php?id=35219
TinyPortal © 2005-2018