UPD: refactoring onMainMenuCreate from uMyDarwin to uDarwinApplication

This commit is contained in:
rich2014 2025-12-11 18:12:11 +08:00
commit 7f80cfcb70
3 changed files with 18 additions and 17 deletions

View file

@ -2965,7 +2965,7 @@ constructor TfrmMain.Create(TheOwner: TComponent);
begin
CocoaConfigMenu.appMenu.aboutItem:= mnuHelpAbout;
CocoaConfigMenu.appMenu.preferencesItem:= mnuConfigOptions;
CocoaConfigMenu.appMenu.onCreate:= @onMainMenuCreate;
CocoaConfigMenu.appMenu.onCreate:= @darwinOnMainMenuCreate;
end;
procedure setMacOSDockMenu();

View file

@ -7,7 +7,8 @@ interface
uses
Classes, SysUtils, fgl,
MacOSAll, CocoaAll, CocoaInt, Cocoa_Extra, CocoaUtils, CocoaConst,
MacOSAll, CocoaAll,
CocoaInt, CocoaPrivate, Cocoa_Extra, CocoaMenus, CocoaUtils, CocoaConst,
uDarwinUtil;
type
@ -67,6 +68,8 @@ type
class procedure openNewInstance;
end;
procedure darwinOnMainMenuCreate( menu: NSMenu );
implementation
{ TDCCocoaApplication }
@ -258,6 +261,19 @@ begin
NSWorkspace.sharedWorkspace.openURL( url );
end;
procedure darwinOnMainMenuCreate( menu: NSMenu );
var
lclForm: TObject;
keyWindow: NSWindow;
begin
lclForm:= nil;
keyWindow:= NSApplication(NSApp).keyWindow;
if keyWindow <> nil then
lclForm:= keyWindow.lclGetTarget;
if (lclForm=nil) or (lclForm.ClassName='TfrmMain') then
AttachEditMenu( menu, menu.numberOfItems, CocoaConst.NSSTR_EDIT_MENU );
end;
initialization
TDarwinApplicationUtil.init;

View file

@ -39,8 +39,6 @@ uses
const
FINDER_FAVORITE_TAGS_MENU_ITEM_CAPTION = #$EF#$BF#$BC'FinderFavoriteTags';
procedure onMainMenuCreate( menu: NSMenu );
type
{ TMacosServiceMenuHelper }
@ -66,19 +64,6 @@ implementation
uses
DynLibs;
procedure onMainMenuCreate( menu: NSMenu );
var
lclForm: TObject;
keyWindow: NSWindow;
begin
lclForm:= nil;
keyWindow:= NSApplication(NSApp).keyWindow;
if keyWindow <> nil then
lclForm:= keyWindow.lclGetTarget;
if (lclForm=nil) or (lclForm.ClassName='TfrmMain') then
AttachEditMenu( menu, menu.numberOfItems, CocoaConst.NSSTR_EDIT_MENU );
end;
procedure TMacosServiceMenuHelper.attachSystemMenu(Sender: TObject);
begin
self.attachServicesMenu( Sender );