Recent

Author Topic: MainMenu: How to use the "Quit <App>" item that has been added in trunk?  (Read 13157 times)

daniel_sap

  • Full Member
  • ***
  • Posts: 106
Re: MainMenu: How to use the "Quit <App>" item that has been added in trunk?
« Reply #15 on: October 20, 2024, 05:53:21 pm »
Thank you, Rich

madref

  • Hero Member
  • *****
  • Posts: 1111
  • ..... A day not Laughed is a day wasted !!
    • Nursing With Humour
Re: MainMenu: How to use the "Quit <App>" item that has been added in trunk?
« Reply #16 on: December 09, 2024, 03:39:05 pm »
Can anyone post a working example with the code from Rich2014?
You treat a disease, you win, you lose.
You treat a person and I guarantee you, you win, no matter the outcome.

Main Platform:
--------------
Mac OS X Sequoaia 15.6.1
Lazarus 4.99 (rev main_4_99-2644-gfd63613782) FPC 3.3.1 x86_64-darwin-cocoa

Windows 10 Pro
Lazarus 3.99 (rev cbfd80ce39)

madref

  • Hero Member
  • *****
  • Posts: 1111
  • ..... A day not Laughed is a day wasted !!
    • Nursing With Humour
Re: MainMenu: How to use the "Quit <App>" item that has been added in trunk?
« Reply #17 on: December 10, 2024, 04:19:32 pm »
I am trying to do this...but with no succes...
Code: Pascal  [Select][+][-]
  1. type
  2.   TForm_Lint = class(TForm)
  3.     ....
  4.     PUM_Exit: TMenuItem;
  5.     ....
  6.   end;
  7.  
  8. uses {$IFDEF DARWIN}CocoaConfig, {$ENDIF}
  9.  
  10. ....
  11. ....
  12.  
  13. procedure TForm_Lint.FormCreate(Sender: TObject);
  14. begin
  15.   {$IFDEF DARWIN}
  16.     CocoaConfigMenu.appMenu.aboutItem := PUM_Exit;
  17.     CocoaConfigMenu.appMenu.preferencesItem:= PUM_Exit;
  18.     CocoaConfigMenu.appMenu.dontAutoCreateItems := True;
  19.   {$ENDIF}
  20. end;     // FormCreate
  21.  
You treat a disease, you win, you lose.
You treat a person and I guarantee you, you win, no matter the outcome.

Main Platform:
--------------
Mac OS X Sequoaia 15.6.1
Lazarus 4.99 (rev main_4_99-2644-gfd63613782) FPC 3.3.1 x86_64-darwin-cocoa

Windows 10 Pro
Lazarus 3.99 (rev cbfd80ce39)

madref

  • Hero Member
  • *****
  • Posts: 1111
  • ..... A day not Laughed is a day wasted !!
    • Nursing With Humour
Re: MainMenu: How to use the "Quit <App>" item that has been added in trunk?
« Reply #18 on: December 11, 2024, 10:33:59 am »
I found out that you must have an active main menu in your app. (Should have read Hansaplast post better because he already did the same :) )

Because I don't use a main menu but a ribbon is there another way to do this?
« Last Edit: December 11, 2024, 10:37:22 am by madref »
You treat a disease, you win, you lose.
You treat a person and I guarantee you, you win, no matter the outcome.

Main Platform:
--------------
Mac OS X Sequoaia 15.6.1
Lazarus 4.99 (rev main_4_99-2644-gfd63613782) FPC 3.3.1 x86_64-darwin-cocoa

Windows 10 Pro
Lazarus 3.99 (rev cbfd80ce39)

madref

  • Hero Member
  • *****
  • Posts: 1111
  • ..... A day not Laughed is a day wasted !!
    • Nursing With Humour
Re: MainMenu: How to use the "Quit <App>" item that has been added in trunk?
« Reply #19 on: December 11, 2024, 11:15:54 am »
Been tinkering a lot....
Found the following things out:
* I dropped a dummy TMainMenu with no menu on my main form
* Created a pop-up menu with the items I need (About & Preference).
* Instead of referring to the mailmen I refered to the pop-up menu.


Now I have the following (See attachment).


but I still don't have the [Quit] :(
Code: Pascal  [Select][+][-]
  1. procedure TForm_Lint.FormCreate(Sender: TObject);
  2. begin
  3.   {$IFDEF DARWIN}
  4.     CocoaConfigMenu.appMenu.aboutItem := PUM_Info;
  5.     CocoaConfigMenu.appMenu.preferencesItem := PUM_Exit;
  6.     CocoaConfigMenu.appMenu.dontAutoCreateItems := True;
  7.   {$ENDIF}
  8. end;     // FormCreate
  9.  


P.S. it now says [About test] -=> how to change this? (Does anyone know how to?
You treat a disease, you win, you lose.
You treat a person and I guarantee you, you win, no matter the outcome.

Main Platform:
--------------
Mac OS X Sequoaia 15.6.1
Lazarus 4.99 (rev main_4_99-2644-gfd63613782) FPC 3.3.1 x86_64-darwin-cocoa

Windows 10 Pro
Lazarus 3.99 (rev cbfd80ce39)

rich2014

  • New Member
  • *
  • Posts: 36
Re: MainMenu: How to use the "Quit <App>" item that has been added in trunk?
« Reply #20 on: December 14, 2024, 02:45:31 am »
hi, Madref

since you need to automatically generate the Quit menu item, you don't need to set dontAutoCreateItems.

Quote
CocoaConfigMenu.appMenu.dontAutoCreateItems := True;

madref

  • Hero Member
  • *****
  • Posts: 1111
  • ..... A day not Laughed is a day wasted !!
    • Nursing With Humour
Re: MainMenu: How to use the "Quit <App>" item that has been added in trunk?
« Reply #21 on: December 15, 2024, 02:44:39 am »
But if I set it to false I get all the other options too...
I only want to have [About] [Settings] and [Quit]


And do you know how to change the [About test] to let's say [About Referee DB]
You treat a disease, you win, you lose.
You treat a person and I guarantee you, you win, no matter the outcome.

Main Platform:
--------------
Mac OS X Sequoaia 15.6.1
Lazarus 4.99 (rev main_4_99-2644-gfd63613782) FPC 3.3.1 x86_64-darwin-cocoa

Windows 10 Pro
Lazarus 3.99 (rev cbfd80ce39)

rich2014

  • New Member
  • *
  • Posts: 36
Re: MainMenu: How to use the "Quit <App>" item that has been added in trunk?
« Reply #22 on: December 16, 2024, 01:47:52 pm »
CocoaConfigMenu.appMenu.customMenus for full control.

Quote
CocoaConfigMenu.appMenu.customMenus:= TMenuItem_costomMenus;

madref

  • Hero Member
  • *****
  • Posts: 1111
  • ..... A day not Laughed is a day wasted !!
    • Nursing With Humour
Re: MainMenu: How to use the "Quit <App>" item that has been added in trunk?
« Reply #23 on: December 16, 2024, 05:53:36 pm »
I finally found a solution to this problem with the help from Rich2014 and some tinkering.
I created a pop-up menu with a sub menu in it with the right references to the correct procedures.
Code: Pascal  [Select][+][-]
  1.     PUM_Main_Sub: TMenuItem;
  2.     PUM_Main_Settings: TMenuItem;
  3.     PUM_Main_Info: TMenuItem;
  4.     PUM_Main_Exit: TMenuItem;
  5.     PUM_Main: TPopupMenu;
Then the following code to create it all
Code: Pascal  [Select][+][-]
  1. procedure TForm_Lint.FormCreate(Sender: TObject);
  2. begin
  3.   {$IFDEF DARWIN}
  4.     CocoaConfigMenu.appMenu.customMenus := PUM_Main_Sub;
  5.     CocoaConfigMenu.appMenu.dontAutoCreateItems := True;
  6.   {$ENDIF}
  7. end;     // FormCreate
By setting the dontAutoCreateItems to True you get only the menu you created.


for the result see the attachment
« Last Edit: December 16, 2024, 06:16:42 pm by madref »
You treat a disease, you win, you lose.
You treat a person and I guarantee you, you win, no matter the outcome.

Main Platform:
--------------
Mac OS X Sequoaia 15.6.1
Lazarus 4.99 (rev main_4_99-2644-gfd63613782) FPC 3.3.1 x86_64-darwin-cocoa

Windows 10 Pro
Lazarus 3.99 (rev cbfd80ce39)

madref

  • Hero Member
  • *****
  • Posts: 1111
  • ..... A day not Laughed is a day wasted !!
    • Nursing With Humour
Re: MainMenu: How to use the "Quit <App>" item that has been added in trunk?
« Reply #24 on: January 13, 2025, 03:03:37 pm »
I still do have a question about this:


How can I change the bitmap once the menu has been created.
If you look closely the [Info]-bitmap is black and I am using a blue set of color.
So how can I change this during runtime because the user might change the color-scheme to red or another different color
You treat a disease, you win, you lose.
You treat a person and I guarantee you, you win, no matter the outcome.

Main Platform:
--------------
Mac OS X Sequoaia 15.6.1
Lazarus 4.99 (rev main_4_99-2644-gfd63613782) FPC 3.3.1 x86_64-darwin-cocoa

Windows 10 Pro
Lazarus 3.99 (rev cbfd80ce39)

Hansaplast

  • Hero Member
  • *****
  • Posts: 749
  • Tweaking4All.com
    • Tweaking4All
Re: MainMenu: How to use the "Quit <App>" item that has been added in trunk?
« Reply #25 on: November 17, 2025, 12:08:36 pm »
I know, it's an old and seemingly ongoing topic that I ran into again today.


Question for the devs (rich2014?):
Is there a way these steps can be included in the Menu Editor in the Lazarus IDE?

rich2014

  • New Member
  • *
  • Posts: 36
Re: MainMenu: How to use the "Quit <App>" item that has been added in trunk?
« Reply #26 on: November 18, 2025, 02:37:03 pm »
it is specific to Cocoa, so i think it's unlikely.

also, this menu should only have a few items, so implementing it via code configuration wouldn't be difficult.

Hansaplast

  • Hero Member
  • *****
  • Posts: 749
  • Tweaking4All.com
    • Tweaking4All
Re: MainMenu: How to use the "Quit <App>" item that has been added in trunk?
« Reply #27 on: November 18, 2025, 05:18:50 pm »
I was already afraid of that - then again, one could see this as a part of TMainMenu? Maybe? 😉


Had to use this last week and did find it rather cumbersome to gather all the pieces (in the forum here) together and write code around TMainMenu limitations. The Wiki page (link) looks outdated.
I wouldn't mind doing an effort to write something for the Wiki page, but I may need some guidance as I'm not quite sure what the "proper" way is on how to use the new method.
To keep designtime "easy" I abuse a TPopupMenu to design the menu pieces.

 

TinyPortal © 2005-2018