mirror of
https://github.com/doublecmd/doublecmd.git
synced 2026-06-21 09:58:13 +00:00
ADD: add Download Now / Remove Download into contextMenu in iCloudDriver
This commit is contained in:
parent
68112b7fdd
commit
67c9fc946b
2 changed files with 87 additions and 3 deletions
|
|
@ -1,24 +1,36 @@
|
|||
unit uiCloudDriver;
|
||||
|
||||
{$mode ObjFPC}{$H+}
|
||||
{$modeswitch objectivec1}
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
Classes, SysUtils,
|
||||
Classes, SysUtils, Menus,
|
||||
uFile, uMountedFileSource,
|
||||
uDCUtils, uMyDarwin;
|
||||
uDCUtils, uMyDarwin,
|
||||
CocoaAll, CocoaUtils;
|
||||
|
||||
type
|
||||
{ TiCloudDriverFileSource }
|
||||
|
||||
TiCloudDriverFileSource = class(TMountedFileSource)
|
||||
private
|
||||
_files: TFiles;
|
||||
private
|
||||
procedure downloadAction(Sender: TObject);
|
||||
public
|
||||
class function isSeedFile(aFile: TFile): Boolean;
|
||||
class function isSeedFiles(aFiles: TFiles): Boolean;
|
||||
public
|
||||
destructor Destroy; override;
|
||||
|
||||
function getDefaultPointForPath(const path: String): String; override;
|
||||
function GetRootDir(sPath : String): String; override;
|
||||
function IsSystemFile(aFile: TFile): Boolean; override;
|
||||
function IsPathAtRoot(Path: String): Boolean; override;
|
||||
function GetDisplayFileName(aFile: TFile): String; override;
|
||||
function QueryContextMenu(AFiles: TFiles; var AMenu: TPopupMenu): Boolean; override;
|
||||
end;
|
||||
|
||||
implementation
|
||||
|
|
@ -28,6 +40,50 @@ const
|
|||
|
||||
{ TiCloudDriverFileSource }
|
||||
|
||||
destructor TiCloudDriverFileSource.Destroy;
|
||||
begin
|
||||
FreeAndNil( _files );
|
||||
inherited Destroy;
|
||||
end;
|
||||
|
||||
procedure TiCloudDriverFileSource.downloadAction(Sender: TObject);
|
||||
var
|
||||
isSeed: Boolean;
|
||||
i: Integer;
|
||||
manager: NSFileManager;
|
||||
url: NSUrl;
|
||||
begin
|
||||
if _files = nil then
|
||||
Exit;
|
||||
|
||||
manager:= NSFileManager.defaultManager;
|
||||
isSeed:= isSeedFiles( _files );
|
||||
for i:= 0 to _files.Count-1 do begin
|
||||
url:= NSUrl.fileURLWithPath( StrToNSString(_files[i].FullPath) );
|
||||
if isSeed then
|
||||
manager.startDownloadingUbiquitousItemAtURL_error( url, nil )
|
||||
else
|
||||
manager.evictUbiquitousItemAtURL_error( url, nil );
|
||||
end;
|
||||
|
||||
FreeAndNil( _files );
|
||||
end;
|
||||
|
||||
class function TiCloudDriverFileSource.isSeedFile(aFile: TFile): Boolean;
|
||||
begin
|
||||
Result:= False;
|
||||
if NOT aFile.Name.StartsWith( '.' ) then
|
||||
Exit;
|
||||
if NOT aFile.Name.EndsWith( '.icloud', True ) then
|
||||
Exit;
|
||||
Result:= True;
|
||||
end;
|
||||
|
||||
class function TiCloudDriverFileSource.isSeedFiles(aFiles: TFiles): Boolean;
|
||||
begin
|
||||
Result:= isSeedFile( aFiles[0] );
|
||||
end;
|
||||
|
||||
function TiCloudDriverFileSource.getDefaultPointForPath(const path: String): String;
|
||||
begin
|
||||
Result:= getMacOSDisplayNameFromPath( path );
|
||||
|
|
@ -47,7 +103,7 @@ function TiCloudDriverFileSource.IsSystemFile(aFile: TFile): Boolean;
|
|||
begin
|
||||
Result:= inherited;
|
||||
if Result then
|
||||
Result:= NOT aFile.Name.EndsWith( '.icloud', True );
|
||||
Result:= NOT isSeedFile( aFile );
|
||||
end;
|
||||
|
||||
function TiCloudDriverFileSource.IsPathAtRoot(Path: String): Boolean;
|
||||
|
|
@ -68,5 +124,30 @@ begin
|
|||
Result:= getMacOSDisplayNameFromPath( aFile.FullPath );
|
||||
end;
|
||||
|
||||
function TiCloudDriverFileSource.QueryContextMenu(AFiles: TFiles; var AMenu: TPopupMenu): Boolean;
|
||||
var
|
||||
menuItem: TMenuItem;
|
||||
begin
|
||||
Result:= False;
|
||||
if AFiles.Count = 0 then
|
||||
Exit;
|
||||
|
||||
FreeAndNil( _files );
|
||||
_files:= AFiles.clone;
|
||||
|
||||
menuItem:= TMenuItem.Create( AMenu );
|
||||
if isSeedFile(AFiles[0]) then
|
||||
menuItem.Caption:= 'Download Now'
|
||||
else
|
||||
menuItem.Caption:= 'Remove Download';
|
||||
MenuItem.OnClick:= @self.downloadAction;
|
||||
AMenu.Items.Insert(0, menuItem);
|
||||
menuItem:= TMenuItem.Create( AMenu );
|
||||
menuItem.Caption:= '-';
|
||||
AMenu.Items.Insert(1, menuItem);
|
||||
|
||||
Result:= True;
|
||||
end;
|
||||
|
||||
end.
|
||||
|
||||
|
|
|
|||
|
|
@ -761,6 +761,7 @@ end;
|
|||
{$ELSEIF DEFINED(DARWIN)}
|
||||
var
|
||||
filepath: String;
|
||||
contextFiles: TFiles;
|
||||
begin
|
||||
if Files.Count = 0 then
|
||||
begin
|
||||
|
|
@ -771,8 +772,10 @@ begin
|
|||
filepath:= Files[0].FullPath;
|
||||
try
|
||||
// Create new context menu
|
||||
contextFiles:= Files;
|
||||
ShellContextMenu:= TShellContextMenu.Create(nil, Files, Background, UserWishForContextMenu);
|
||||
ShellContextMenu.OnClose := CloseEvent;
|
||||
frmMain.ActiveFrame.FileSource.QueryContextMenu(contextFiles, TPopupMenu(ShellContextMenu));
|
||||
// Show context menu
|
||||
MacosServiceMenuHelper.PopUp( ShellContextMenu, rsMacOSMenuServices, filepath );
|
||||
finally
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue