mirror of
https://github.com/doublecmd/doublecmd.git
synced 2026-06-21 09:58:13 +00:00
ADD: Share ContextMenu supported on MacOS
(cherry picked from commit 0c3f996e0e)
This commit is contained in:
parent
a10531d22b
commit
50daef684a
2 changed files with 53 additions and 2 deletions
|
|
@ -35,7 +35,7 @@ interface
|
|||
uses
|
||||
Classes, SysUtils, UnixType,
|
||||
Cocoa_Extra, MacOSAll, CocoaAll, CocoaUtils, CocoaInt, CocoaConst, CocoaMenus,
|
||||
InterfaceBase, Menus;
|
||||
InterfaceBase, Menus, Controls, Forms, LazLoggerBase;
|
||||
|
||||
// Darwin Util Function
|
||||
function StringToNSString(const S: String): NSString;
|
||||
|
|
@ -125,6 +125,9 @@ procedure InitNSServiceProvider(
|
|||
isReadyFunc: TNSServiceMenuIsReady;
|
||||
getFilenamesFunc: TNSServiceMenuGetFilenames );
|
||||
|
||||
// MacOS Sharing
|
||||
procedure showMacOSSharingServiceMenu;
|
||||
|
||||
// MacOS Theme
|
||||
type TNSThemeChangedHandler = Procedure() of object;
|
||||
|
||||
|
|
@ -264,6 +267,35 @@ begin
|
|||
FreeAndNil( filenameList );
|
||||
end;
|
||||
|
||||
procedure showMacOSSharingServiceMenu;
|
||||
var
|
||||
picker: NSSharingServicePicker;
|
||||
filenameArray: NSMutableArray;
|
||||
filenameList: TStringList;
|
||||
url: NSUrl;
|
||||
filename: String;
|
||||
point: TPoint;
|
||||
popupNSRect: NSRect;
|
||||
control: TWinControl;
|
||||
begin
|
||||
filenameList:= TDCCocoaApplication(NSApp).serviceMenuGetFilenames;
|
||||
|
||||
filenameArray:= NSMutableArray.alloc.init;
|
||||
for filename in filenameList do begin
|
||||
url:= NSUrl.fileURLWithPath( StringToNSString(filename) );
|
||||
filenameArray.addObject( url );
|
||||
end;
|
||||
|
||||
control:= Screen.ActiveControl;
|
||||
point:= control.ScreenToClient( Mouse.CursorPos );
|
||||
popupNSRect.origin.x:= point.X;
|
||||
popupNSRect.origin.y:= point.Y;
|
||||
popupNSRect.size:= NSZeroSize;
|
||||
|
||||
picker:= NSSharingServicePicker.alloc.initWithItems( filenameArray );
|
||||
picker.showRelativeToRect_ofView_preferredEdge( popupNSRect, NSView(control.handle) , NSMinYEdge );
|
||||
end;
|
||||
|
||||
procedure TDCCocoaApplication.observeValueForKeyPath_ofObject_change_context(
|
||||
keyPath: NSString; object_: id; change: NSDictionary; context: pointer);
|
||||
begin
|
||||
|
|
|
|||
|
|
@ -58,6 +58,7 @@ type
|
|||
function FillOpenWithSubMenu: Boolean;
|
||||
{$IF DEFINED(DARWIN)}
|
||||
procedure FillServicesSubMenu;
|
||||
procedure SharingMenuItemSelect(Sender: TObject);
|
||||
{$ENDIF}
|
||||
procedure CreateActionSubMenu(MenuWhereToAdd:TComponent; aFile:TFile; bIncludeViewEdit:boolean);
|
||||
public
|
||||
|
|
@ -73,7 +74,7 @@ uses
|
|||
uOSUtils, uFileProcs, uShellExecute, uLng, uPixMapManager, uMyUnix, uOSForms,
|
||||
fMain, fFileProperties, DCOSUtils, DCStrUtils, uExts, uArchiveFileSourceUtil, uSysFolders
|
||||
{$IF DEFINED(DARWIN)}
|
||||
, MacOSAll
|
||||
, MacOSAll, uMyDarwin
|
||||
{$ELSEIF NOT DEFINED(HAIKU)}
|
||||
, uKeyFile, uMimeActions
|
||||
{$IF DEFINED(LINUX)}
|
||||
|
|
@ -507,6 +508,24 @@ begin
|
|||
mi:=TMenuItem.Create(Self);
|
||||
mi.Caption:=uLng.rsMenuMacOsServices;
|
||||
Self.Items.Add(mi);
|
||||
|
||||
// Add delimiter menu
|
||||
mi:=TMenuItem.Create(Self);
|
||||
mi.Caption:='-';
|
||||
Self.Items.Add(mi);
|
||||
|
||||
// add Sharing Menu
|
||||
// similar to MacOS 13, the Share MenuItem does not expand the submenu,
|
||||
// and the SharingServicePicker pops up after clicking Share MenuItem.
|
||||
mi:=TMenuItem.Create(Self);
|
||||
mi.Caption := 'Share';
|
||||
mi.OnClick:= self.SharingMenuItemSelect;
|
||||
Self.Items.Add(mi);
|
||||
end;
|
||||
|
||||
procedure TShellContextMenu.SharingMenuItemSelect(Sender: TObject);
|
||||
begin
|
||||
showMacOSSharingServiceMenu;
|
||||
end;
|
||||
{$ENDIF}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue