Recent

Author Topic: How to Add a MenuItem to the top level menu of lazarus IDE?  (Read 848 times)

LeoBruno

  • Jr. Member
  • **
  • Posts: 61
How to Add a MenuItem to the top level menu of lazarus IDE?
« on: August 12, 2022, 11:17:38 pm »
HI:

I need to create a ManuItem to the top level menu of the IDE, and some other inside the created menu.

How to achieve this?

Code: Pascal  [Select][+][-]
  1.  
  2. unit Model.IDE.Menu;
  3.  
  4. {$mode objfpc}{$H+}
  5.  
  6. interface
  7.  
  8. uses
  9.   Dialogs,
  10.   MenuIntf,
  11.   Classes,
  12.   SysUtils
  13. ;
  14.  
  15.  
  16. procedure Register;
  17.  
  18. procedure OpenJFWManager(Sender: TObject);
  19.  
  20. implementation
  21.  
  22. procedure Register;
  23. begin
  24.   RegisterIDEMenuCommand(mnuMain, 'mniJotaIdeWizardsMainMenu','&Jota Framework', nil, nil);
  25.   RegisterIDEMenuCommand('mniJotaIdeWizardsMainMenu', 'mniJotaIDEWizardsOpenProjectManager', 'Abrir JFW Manager', nil, @OpenJFWManager);
  26. end;
  27.  
  28. procedure OpenJFWManager(Sender: TObject);
  29. begin
  30.   ShowMessage('test!!!');
  31. end;
  32.  
  33. end.
  34.  
  35.  

The first line of the Register procedure the intetion was to create a MenuItem at the top level menu (sibling of "File", "Edit", "View"...)
The second line, should create another Menu, children of the MenuItem created above.

Any tips?

Thank's
« Last Edit: August 12, 2022, 11:46:13 pm by LeoBruno »
Lazarus 2.2.2 FPC 3.2.2 Windows (qt5) Anchor Docking


LeoBruno

  • Jr. Member
  • **
  • Posts: 61
Re: How to Add a MenuItem to the top level menu of lazarus IDE?
« Reply #2 on: August 13, 2022, 01:39:41 am »
Thank you.

I used that documentation to write the code above, but I missed something, because it didn't work.

The top level menu didn't show, and thus, so it's children.


https://wiki.lazarus.freepascal.org/Extending_the_IDE#Menu_items
Lazarus 2.2.2 FPC 3.2.2 Windows (qt5) Anchor Docking

HeavyUser

  • Sr. Member
  • ****
  • Posts: 397
Re: How to Add a MenuItem to the top level menu of lazarus IDE?
« Reply #3 on: August 13, 2022, 02:40:12 am »
Thank you.

I used that documentation to write the code above, but I missed something, because it didn't work.

The top level menu didn't show, and thus, so it's children.


https://wiki.lazarus.freepascal.org/Extending_the_IDE#Menu_items
have you tried calling
Code: Pascal  [Select][+][-]
  1. function RegisterIDEMenuRoot(const Name: string; MenuItem: TMenuItem = nil
  2.                              ): TIDEMenuSection;
  3.  
and build under that your menu?

PS. I would leave the MenuItem nill for the first tests.

LeoBruno

  • Jr. Member
  • **
  • Posts: 61
Re: How to Add a MenuItem to the top level menu of lazarus IDE?
« Reply #4 on: August 13, 2022, 02:59:29 am »
Well I managed to get the First Menu (the top level).

The problem now is creating the children inside it.

in other words, this works:

Code: Pascal  [Select][+][-]
  1. procedure Register;
  2. begin
  3.   RegisterIDEMenuCommand(mnuMain, 'mniJFrameworkMainMenu','&Jota Framework', nil, nil);  
  4. end;
  5.  

Now, I guess that the code above is creating a TIDEMenuCommand whith the name 'mniJFrameworkMainMenu'.

I'm trying to create the children, using the other overloaded method, passing the 'mniJFrameworkMainMenu' as the path parameter.

Code: Pascal  [Select][+][-]
  1. procedure Register;
  2. begin
  3.   RegisterIDEMenuCommand(mnuMain, 'mniJFrameworkMainMenu','&Jota Framework', nil, nil);
  4.   RegisterIDEMenuCommand('mniJFrameworkMainMenu', 'mniJFrameworkOpenProjectManager', 'Abrir JFW Manager', nil, @OpenJFWManager);  
  5. end;
  6.  

The second line doesn't work, Lazarus doesn't open. (Err. Msg: IDE Path Menu not found).







Thank you.

I used that documentation to write the code above, but I missed something, because it didn't work.

The top level menu didn't show, and thus, so it's children.
« Last Edit: August 13, 2022, 03:39:20 am by LeoBruno »
Lazarus 2.2.2 FPC 3.2.2 Windows (qt5) Anchor Docking

LeoBruno

  • Jr. Member
  • **
  • Posts: 61
Re: How to Add a MenuItem to the top level menu of lazarus IDE?
« Reply #5 on: August 13, 2022, 03:46:03 am »
https://wiki.lazarus.freepascal.org/Extending_the_IDE#Menu_items

have you tried calling
Code: Pascal  [Select][+][-]
  1. function RegisterIDEMenuRoot(const Name: string; MenuItem: TMenuItem = nil
  2.                              ): TIDEMenuSection;
  3.  
and build under that your menu?

PS. I would leave the MenuItem nill for the first tests.

Comments bellow each attempt

Code: Pascal  [Select][+][-]
  1.  
  2. procedure Register;
  3. var
  4.   _SecaoPai: TIDEMenuSection;
  5.   _MenuItem: TMenuItem;
  6. begin
  7.   _SecaoPai := RegisterIDEMenuRoot('mniJFrameworkMainMenu', _MenuItem);  
  8. end;
  9.  
  10.  

Menu doesn't show up

Code: Pascal  [Select][+][-]
  1. procedure Register;
  2. var
  3.   _SecaoPai: TIDEMenuSection;
  4.   _MenuItem: TMenuItem;
  5. begin
  6.   _SecaoPai := RegisterIDEMenuRoot('mniJFrameworkMainMenu', _MenuItem);
  7.   _SecaoPai.MenuItem.Caption := 'test';  
  8. end;
  9.  
  10.  

Access Violation

Code: Pascal  [Select][+][-]
  1.  
  2. procedure Register;
  3. var
  4.   _SecaoPai: TIDEMenuSection;
  5.   _MenuItem: TMenuItem;
  6. begin
  7.   _MenuItem := TMenuItem.Create(nil);
  8.   _SecaoPai := RegisterIDEMenuRoot('mniJFrameworkMainMenu', _MenuItem);
  9.   _SecaoPai.MenuItem.Caption := 'test';      
  10. end;
  11.  
  12.  

Menu doesn't show.






Lazarus 2.2.2 FPC 3.2.2 Windows (qt5) Anchor Docking

HeavyUser

  • Sr. Member
  • ****
  • Posts: 397
Re: How to Add a MenuItem to the top level menu of lazarus IDE?
« Reply #6 on: August 13, 2022, 07:34:45 am »
You are correct. What ever I tried I can't create a root level menu.

MarkMLl

  • Hero Member
  • *****
  • Posts: 5119
Re: How to Add a MenuItem to the top level menu of lazarus IDE?
« Reply #7 on: August 13, 2022, 09:23:27 am »
Any tips?

Yes: you've posted your message at a time when European developers are in bed so slow down and wait for a response.

Also put the version of Lazarus etc. that you're asking about in the body of your message (not in your signature), the developers will need that.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 8253
  • Debugger - SynEdit - and more
    • wiki
Re: How to Add a MenuItem to the top level menu of lazarus IDE?
« Reply #8 on: August 13, 2022, 10:08:02 am »
Not tested, but try

Code: Pascal  [Select][+][-]
  1. Section:=RegisterIDESubMenu(mnuMain, 'MenuItemName' ,'MenuItemCaption');

HeavyUser

  • Sr. Member
  • ****
  • Posts: 397
Re: How to Add a MenuItem to the top level menu of lazarus IDE?
« Reply #9 on: August 13, 2022, 11:40:54 am »
Not tested, but try

Code: Pascal  [Select][+][-]
  1. Section:=RegisterIDESubMenu(mnuMain, 'MenuItemName' ,'MenuItemCaption');
Already tested it, also with nil instead of mnuMain. I can't see the menu anywhere, I searched all the menus not only the root level.
Lazarus 2.2 on windows 10.
« Last Edit: August 13, 2022, 11:48:15 am by HeavyUser »

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 8253
  • Debugger - SynEdit - and more
    • wiki
Re: How to Add a MenuItem to the top level menu of lazarus IDE?
« Reply #10 on: August 13, 2022, 12:09:13 pm »
Already tested it, also with nil instead of mnuMain. I can't see the menu anywhere, I searched all the menus not only the root level.
Lazarus 2.2 on windows 10.
mnuMain is in
components\ideintf\menuintf.pas
« Last Edit: August 13, 2022, 01:09:31 pm by Martin_fr »

HeavyUser

  • Sr. Member
  • ****
  • Posts: 397
Re: How to Add a MenuItem to the top level menu of lazarus IDE?
« Reply #11 on: August 13, 2022, 12:13:49 pm »
mnuMain is in
components\ideintf\menuintf.pas
I know, here is the unit I'm using for testing

Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, MenuIntf, Dialogs, Menus;
  9.  
  10. procedure Register;
  11.  
  12. procedure MessageClick(Sender:TObject);
  13.  
  14. implementation
  15. var
  16.   vSect : TIDEMenuSection;
  17.  
  18.  
  19. procedure MessageClick(Sender: TObject);
  20. begin
  21.   ShowMessage((Sender as TComponent).Name);
  22. end;
  23.  
  24.  
  25. procedure Register;
  26. var
  27.   Path :String;
  28. begin
  29.   //vSect := RegisterIDEMenuRoot('Heavy User',nil);
  30.   //Path := vSect.Name;
  31.   //RegisterIDEMenuCommand(Path, 'mniJotaIdeWizardsMainMenu','&Jota Framework', nil, @MessageClick);
  32.   //RegisterIDEMenuCommand(Path, 'mniJotaIdeWizard','&Jota', nil, @MessageClick);
  33.  
  34.   //vSect := RegisterIDESubMenu(nil,'HeavyUser','Heavy User');
  35.   //RegisterIDEMenuCommand(vSect, 'mniJotaIdeWizardsMainMenu','&Jota Framework', nil, @MessageClick);
  36.   //RegisterIDEMenuCommand(vSect, 'mniJotaIdeWizard','&Jota', nil, @MessageClick);
  37.  
  38.   //vSect := RegisterIDESubMenu(mnuMain,'HeavyUser','Heavy User');
  39.   //RegisterIDEMenuCommand(vSect, 'mniJotaIdeWizardsMainMenu','&Jota Framework', nil, @MessageClick);
  40.   //RegisterIDEMenuCommand(vSect, 'mniJotaIdeWizard','&Jota', nil, @MessageClick);
  41.  
  42.   vSect := RegisterIDESubMenu('','HeavyUser','Heavy User');
  43.   RegisterIDEMenuCommand(vSect, 'mniJotaIdeWizardsMainMenu','&Jota Framework', nil, @MessageClick);
  44.   RegisterIDEMenuCommand(vSect, 'mniJotaIdeWizard','&Jota', nil, @MessageClick);
  45. end;
  46.  
  47. end.
  48.  
  49.  

LeoBruno

  • Jr. Member
  • **
  • Posts: 61
Re: How to Add a MenuItem to the top level menu of lazarus IDE?
« Reply #12 on: August 13, 2022, 01:02:46 pm »
Thank's guys...

I'm using lazarus 2.2.2 and fpc 3.2.2 (Windows)

I already said it before, but registering the top level menu like this, worked...

Code: Pascal  [Select][+][-]
  1.  
  2. procedure Register;
  3. begin
  4.   RegisterIDEMenuCommand(mnuMain, 'mniJFrameworkMainMenu','&Jota Framework', nil, nil);  
  5. end;
  6.  
  7.  

Bui I can't register the submenu inside it, the IDE doesn't find it when the application start.

Lazarus 2.2.2 FPC 3.2.2 Windows (qt5) Anchor Docking

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4105
  • I like bugs.
Re: How to Add a MenuItem to the top level menu of lazarus IDE?
« Reply #13 on: August 13, 2022, 04:22:42 pm »
Code: Pascal  [Select][+][-]
  1.   vSect := RegisterIDESubMenu('','HeavyUser','Heavy User');
  2.   RegisterIDEMenuCommand(vSect, 'mniJotaIdeWizardsMainMenu','&Jota Framework', nil, @MessageClick);
  3.   RegisterIDEMenuCommand(vSect, 'mniJotaIdeWizard','&Jota', nil, @MessageClick);
If you give mnuMain as the first parameter for RegisterIDESubMenu, it should work.
Code: Pascal  [Select][+][-]
  1.   vSect := RegisterIDESubMenu(mnuMain,'HeavyUser','Heavy User');
Mostly Lazarus trunk and FPC 3.2 on Manjaro Linux 64-bit.

LeoBruno

  • Jr. Member
  • **
  • Posts: 61
Re: How to Add a MenuItem to the top level menu of lazarus IDE?
« Reply #14 on: August 13, 2022, 04:53:41 pm »
If what needed to be done is this....   it didn't work.

Code: Pascal  [Select][+][-]
  1. begin
  2.   vSect := RegisterIDESubMenu(mnuMain,'mniJFrameworkMainMenu','Jota Framework');
  3.   RegisterIDEMenuCommand(vSect, 'mniJotaIdeWizard','Abrir JFW Manager [Ctrl+M]', nil, @OpenJFWManager);
  4. end;
  5.  
  6.  

vSect in this example is a global variable.


Code: Pascal  [Select][+][-]
  1.   vSect := RegisterIDESubMenu('','HeavyUser','Heavy User');
  2.   RegisterIDEMenuCommand(vSect, 'mniJotaIdeWizardsMainMenu','&Jota Framework', nil, @MessageClick);
  3.   RegisterIDEMenuCommand(vSect, 'mniJotaIdeWizard','&Jota', nil, @MessageClick);
If you give mnuMain as the first parameter for RegisterIDESubMenu, it should work.
Code: Pascal  [Select][+][-]
  1.   vSect := RegisterIDESubMenu(mnuMain,'HeavyUser','Heavy User');
Lazarus 2.2.2 FPC 3.2.2 Windows (qt5) Anchor Docking

 

TinyPortal © 2005-2018