Recent

Author Topic: submenu opened event / lazy menu creation  (Read 1165 times)

BeniBela

  • Hero Member
  • *****
  • Posts: 678
    • homepage
submenu opened event / lazy menu creation
« 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

Blaazen

  • Hero Member
  • *****
  • Posts: 2782
  • POKE 54296,15
    • Eye-Candy Controls
Re: submenu opened event / lazy menu creation
« Reply #1 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.
Lazarus 2.1.0 r59757M FPC 3.3.1 r40507 x86_64-linux-qt Chakra, Qt 4.8.7/5.11.2, Plasma 5.14.2
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

ASerge

  • Hero Member
  • *****
  • Posts: 1257
Re: submenu opened event / lazy menu creation
« Reply #2 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;

BeniBela

  • Hero Member
  • *****
  • Posts: 678
    • homepage
Re: submenu opened event / lazy menu creation
« Reply #3 on: February 25, 2019, 12:44:11 am »
That works in a mainmenu, but I cannot get it work in a popupmenu

jamie

  • Hero Member
  • *****
  • Posts: 1552
Re: submenu opened event / lazy menu creation
« Reply #4 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.

BeniBela

  • Hero Member
  • *****
  • Posts: 678
    • homepage
Re: submenu opened event / lazy menu creation
« Reply #5 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