From 1259df9b51a2f4cbac55d1a613b59e75747252b4 Mon Sep 17 00:00:00 2001 From: rich2014 Date: Sat, 12 Oct 2024 19:00:14 +0800 Subject: [PATCH] Cocoa: add TCocoaConfigAppMenu.onCreate for custom --- lcl/interfaces/cocoa/cocoaconfig.inc | 1 + lcl/interfaces/cocoa/cocoaconfig.pas | 3 +++ lcl/interfaces/cocoa/cocoamenus.pas | 6 ++++++ 3 files changed, 10 insertions(+) diff --git a/lcl/interfaces/cocoa/cocoaconfig.inc b/lcl/interfaces/cocoa/cocoaconfig.inc index 6ce3510ca8..c0b995d81a 100644 --- a/lcl/interfaces/cocoa/cocoaconfig.inc +++ b/lcl/interfaces/cocoa/cocoaconfig.inc @@ -21,6 +21,7 @@ var aboutItem: nil; preferencesItem: nil; customMenus: nil; + onCreate: nil; dontAutoCreateItems: False; ); diff --git a/lcl/interfaces/cocoa/cocoaconfig.pas b/lcl/interfaces/cocoa/cocoaconfig.pas index bc5b4686cb..0373e48789 100644 --- a/lcl/interfaces/cocoa/cocoaconfig.pas +++ b/lcl/interfaces/cocoa/cocoaconfig.pas @@ -115,6 +115,8 @@ type defaultRadioImageName: NSString; end; + TCocoaConfigAppMenuOnCreate = procedure ( appMenu: NSMenu ); + // 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. @@ -124,6 +126,7 @@ type aboutItem: TMenuItem; preferencesItem: TMenuItem; customMenus: TMenuItem; + onCreate: TCocoaConfigAppMenuOnCreate; dontAutoCreateItems: Boolean; end; diff --git a/lcl/interfaces/cocoa/cocoamenus.pas b/lcl/interfaces/cocoa/cocoamenus.pas index cba4ba9fc8..ab5febff4d 100644 --- a/lcl/interfaces/cocoa/cocoamenus.pas +++ b/lcl/interfaces/cocoa/cocoamenus.pas @@ -523,6 +523,12 @@ begin rsMacOSMenuPreferences, VK_OEM_COMMA, [ssMeta]); + // Custom onCreate + if Assigned( CocoaConfigMenu.appMenu.onCreate ) then begin + submenu.addItem( NSMenuItem.separatorItem ); + CocoaConfigMenu.appMenu.onCreate( submenu ); + end; + // Auto Create App Menu below? if CocoaConfigMenu.appMenu.dontAutoCreateItems then Exit;