mirror of
https://github.com/doublecmd/doublecmd.git
synced 2026-06-21 09:58:13 +00:00
ADD: MacOS: add System Services Sub Menu to PopupMenu (#536)
This commit is contained in:
parent
6fc22a2bff
commit
b944c7d35b
3 changed files with 73 additions and 3 deletions
|
|
@ -28,7 +28,7 @@ unit uMyDarwin;
|
|||
interface
|
||||
|
||||
uses
|
||||
Classes, SysUtils, MacOSAll, CocoaAll, CocoaUtils, CocoaInt, InterfaceBase;
|
||||
Classes, SysUtils, MacOSAll, CocoaAll, CocoaUtils, CocoaInt, InterfaceBase, Menus, CocoaWSMenus;
|
||||
|
||||
function NSGetTempPath: String;
|
||||
|
||||
|
|
@ -59,6 +59,13 @@ public
|
|||
procedure openWithNewTab( pboard:NSPasteboard; userData:NSString; error:NSStringPtr ); message 'openWithNewTab:userData:error:';
|
||||
end;
|
||||
|
||||
type TMacosServiceMenuHelper = class
|
||||
oldMenuPopupHandler: TNotifyEvent;
|
||||
procedure attachServicesMenu( Sender:TObject);
|
||||
public
|
||||
procedure PopUp( menu:TPopupMenu );
|
||||
end;
|
||||
|
||||
procedure InitNSServiceProvider(
|
||||
serveCallback: TNSServiceProviderCallBack;
|
||||
isReadyFunc: TNSServiceMenuIsReady;
|
||||
|
|
@ -67,12 +74,43 @@ procedure InitNSServiceProvider(
|
|||
var
|
||||
HasMountURL: Boolean = False;
|
||||
NSServiceProvider: TNSServiceProvider;
|
||||
MacosServiceMenuHelper: TMacosServiceMenuHelper;
|
||||
|
||||
implementation
|
||||
|
||||
uses
|
||||
DynLibs;
|
||||
|
||||
procedure TMacosServiceMenuHelper.attachServicesMenu( Sender:TObject);
|
||||
var
|
||||
servicesItem: TMenuItem;
|
||||
subMenu: TCocoaMenu;
|
||||
begin
|
||||
// call the previous OnMenuPopupHandler and restore it
|
||||
if Assigned(oldMenuPopupHandler) then oldMenuPopupHandler( Sender );
|
||||
OnMenuPopupHandler:= oldMenuPopupHandler;
|
||||
oldMenuPopupHandler:= nil;
|
||||
|
||||
// attach the Services Sub Menu by calling NSApplication.setServicesMenu()
|
||||
servicesItem:= TPopupMenu(Sender).Items.Find('Services');
|
||||
if servicesItem<>nil then
|
||||
begin
|
||||
subMenu:= TCocoaMenu.alloc.initWithTitle(NSString.string_);
|
||||
TCocoaMenuItem(servicesItem.Handle).setSubmenu( subMenu );
|
||||
TCocoaWidgetSet(WidgetSet).NSApp.setServicesMenu( NSMenu(servicesItem.Handle) );
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TMacosServiceMenuHelper.PopUp( menu:TPopupMenu );
|
||||
begin
|
||||
// because the menu item handle will be destroyed in TPopupMenu.PopUp()
|
||||
// we can only call NSApplication.setServicesMenu() in OnMenuPopupHandler()
|
||||
oldMenuPopupHandler:= OnMenuPopupHandler;
|
||||
OnMenuPopupHandler:= attachServicesMenu;
|
||||
menu.PopUp();
|
||||
end;
|
||||
|
||||
|
||||
procedure InitNSServiceProvider(
|
||||
serveCallback: TNSServiceProviderCallBack;
|
||||
isReadyFunc: TNSServiceMenuIsReady;
|
||||
|
|
@ -84,7 +122,7 @@ var
|
|||
begin
|
||||
DCApp:= TDCCocoaApplication( TCocoaWidgetSet(WidgetSet).NSApp );
|
||||
|
||||
// MacOs Service menu incoming setup
|
||||
// MacOS Service menu incoming setup
|
||||
if not Assigned(NSServiceProvider) then
|
||||
begin
|
||||
NSServiceProvider:= TNSServiceProvider.alloc.init;
|
||||
|
|
@ -93,7 +131,7 @@ begin
|
|||
end;
|
||||
NSServiceProvider.onOpenWithNewTab:= serveCallback;
|
||||
|
||||
// MacOs Service menu outgoing setup
|
||||
// MacOS Service menu outgoing setup
|
||||
sendTypes:= NSArray.arrayWithObject(NSFilenamesPboardType);
|
||||
returnTypes:= nil;
|
||||
DCApp.serviceMenuIsReady:= isReadyFunc;
|
||||
|
|
@ -254,6 +292,7 @@ begin
|
|||
@FSMountServerVolumeSync:= GetProcAddress(CoreServices, 'FSMountServerVolumeSync');
|
||||
end;
|
||||
HasMountURL:= Assigned(NetFSMountURLSync) or Assigned(FSMountServerVolumeSync);
|
||||
MacosServiceMenuHelper:= TMacosServiceMenuHelper.Create;
|
||||
end;
|
||||
|
||||
procedure Finalize;
|
||||
|
|
|
|||
|
|
@ -56,6 +56,9 @@ type
|
|||
private
|
||||
procedure LeaveDrive;
|
||||
function FillOpenWithSubMenu: Boolean;
|
||||
{$IF DEFINED(DARWIN)}
|
||||
procedure FillServicesSubMenu;
|
||||
{$ENDIF}
|
||||
procedure CreateActionSubMenu(MenuWhereToAdd:TComponent; aFile:TFile; bIncludeViewEdit:boolean);
|
||||
public
|
||||
constructor Create(Owner: TWinControl; ADrive: PDrive); reintroduce; overload;
|
||||
|
|
@ -476,6 +479,25 @@ begin
|
|||
end;
|
||||
{$ENDIF}
|
||||
|
||||
|
||||
{$IF DEFINED(DARWIN)}
|
||||
procedure TShellContextMenu.FillServicesSubMenu;
|
||||
var
|
||||
mi: TMenuItem;
|
||||
begin
|
||||
// Add delimiter menu
|
||||
mi:=TMenuItem.Create(Self);
|
||||
mi.Caption:='-';
|
||||
Self.Items.Add(mi);
|
||||
|
||||
// attach Services Menu in TMacosServiceMenuHelper
|
||||
mi:=TMenuItem.Create(Self);
|
||||
mi.Caption:='Services';
|
||||
Self.Items.Add(mi);
|
||||
end;
|
||||
{$ENDIF}
|
||||
|
||||
|
||||
constructor TShellContextMenu.Create(Owner: TWinControl; ADrive: PDrive);
|
||||
var
|
||||
mi: TMenuItem;
|
||||
|
|
@ -729,6 +751,11 @@ begin
|
|||
// Add "Open with" submenu if needed
|
||||
AddOpenWithMenu := FillOpenWithSubMenu;
|
||||
|
||||
// Add "Services" menu if MacOS
|
||||
{$IF DEFINED(DARWIN)}
|
||||
FillServicesSubMenu;
|
||||
{$ENDIF}
|
||||
|
||||
// Add delimiter menu
|
||||
mi:=TMenuItem.Create(Self);
|
||||
mi.Caption:='-';
|
||||
|
|
|
|||
|
|
@ -714,7 +714,11 @@ begin
|
|||
ShellContextMenu:= TShellContextMenu.Create(nil, Files, Background, UserWishForContextMenu);
|
||||
ShellContextMenu.OnClose := CloseEvent;
|
||||
// Show context menu
|
||||
{$IF DEFINED(DARWIN)}
|
||||
MacosServiceMenuHelper.PopUp( ShellContextMenu );
|
||||
{$ELSE}
|
||||
ShellContextMenu.PopUp(X, Y);
|
||||
{$ENDIF}
|
||||
end;
|
||||
{$ENDIF}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue