Forum > Cocoa

MainMenu: How to use the "Quit <App>" item that has been added in trunk?

<< < (2/5) > >>

rich2014:
hi, Hansaplast

in Lazarus Main Trunk,Application interface provided to facilitate APP to operate App Menu.
it's easy to set About, Preferences, and customized menus,
only the LCL TMenuItem is needed to pass in.
and we can control whether Cocoa is needed to automatically add
Hide, Hide Others, Show All, and Quit menu items.


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---{$IF DEFINED(DARWIN)}Uses  CocoaMenus;var   item1: TMenuItem;  item2: TMenuItem;  item3: TMenuItem;begin  macOS_AppMenuIntf.aboutItem:= item1;           // About   macOS_AppMenuIntf.preferencesItem:= item2;     // Preferences...  macOS_AppMenuIntf.customMenus:= item3          // any custom menu items  macOS_AppMenuIntf.dontAutoCreateAppMenuItems:= True; // disable auto App Menuend;{$ENDIF} 

Hansaplast:
Hi Rich 😊


Apologies for not responding earlier, I do appreciate you Cocoa efforts!


Now ... It took me some time to figure out how to use the steps you described. Seems equally less intuitive as the old method. Which means, that whenever I need a menu, I'll need to go find this post and remember what I did, or consult the Wiki.


Is there any way we can incorporate this in the menu editor?
Or maybe in the object inspector (of a TMainMenu)?
Maybe adding these as properties of a TMainMenu (just like some of the "Restricted" properties we see with all controls)?


Anything I can do to help? (I'm not very familiar with the IDE code and such)


Just been tinkering some more, and manually creating a TMenuItem in code is not very RAD, is it?

Shebuka:

--- Quote from: Hansaplast on June 16, 2024, 04:12:30 pm ---[...]
Just been tinkering some more, and manually creating a TMenuItem in code is not very RAD, is it?

--- End quote ---

You don't need to create them in code, just create the menu items as you would for a windows app in the GUI, take a reference to them and then move them to the apple menu, eg code in my formCreate:


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---    AppMenu := TMenuItem.Create(Self);  {Application menu}    AppMenu.Caption := #$EF#$A3#$BF;  {Unicode Apple logo char}    main_menu.Items.Insert(0, AppMenu);     help_mnu.Remove(help_about_mnu);    help_about_mnu.Bitmap.Clear;        // on windows we have an icon, on mac no app has icon in the apple menu    AppMenu.Add(help_about_mnu);  {Add About as item in application menu}

Hansaplast:
Thans Shebuka for chiming in. I'll give that a try. 😊

rich2014:
although the previous method mentioned by @Shebuka is still supported, the new method has the following benefits:

1. i18n supported

2. ShortCut take care

3. Icon take care

4. "Hide, Hide Others, Show All, and Quit" controled

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version