#5584 Share option in File menu and context menu
This commit is contained in:
parent
36032bf7b5
commit
6be3af35b3
|
@ -277,6 +277,7 @@
|
|||
A2B3FB460E5901E700FF78FB /* cli.c in Sources */ = {isa = PBXBuildFile; fileRef = A2B3FB450E5901E700FF78FB /* cli.c */; };
|
||||
A2B3FB4C0E59023000FF78FB /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */; };
|
||||
A2B3FB530E59027100FF78FB /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */; };
|
||||
A2B5B4E91880665E0071A66A /* ShareTorrentFileHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = A2B5B4E81880665E0071A66A /* ShareTorrentFileHelper.m */; };
|
||||
A2B6141C1395ADE9000E0975 /* libz.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = A2B6141B1395ADE9000E0975 /* libz.dylib */; };
|
||||
A2B6141D1395B0E3000E0975 /* libz.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = A2B6141B1395ADE9000E0975 /* libz.dylib */; };
|
||||
A2B6141E1395B0EC000E0975 /* libz.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = A2B6141B1395ADE9000E0975 /* libz.dylib */; };
|
||||
|
@ -998,6 +999,8 @@
|
|||
A2AF23C616B44FA0003BC59E /* log.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = log.c; path = libtransmission/log.c; sourceTree = "<group>"; };
|
||||
A2AF23C716B44FA0003BC59E /* log.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = log.h; path = libtransmission/log.h; sourceTree = "<group>"; };
|
||||
A2B3FB450E5901E700FF78FB /* cli.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = cli.c; path = cli/cli.c; sourceTree = "<group>"; };
|
||||
A2B5B4E71880665E0071A66A /* ShareTorrentFileHelper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ShareTorrentFileHelper.h; path = macosx/ShareTorrentFileHelper.h; sourceTree = "<group>"; };
|
||||
A2B5B4E81880665E0071A66A /* ShareTorrentFileHelper.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = ShareTorrentFileHelper.m; path = macosx/ShareTorrentFileHelper.m; sourceTree = "<group>"; };
|
||||
A2B5BB7A0D9C7C2300FCB650 /* es */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = es; path = macosx/es.lproj/AddWindow.xib; sourceTree = "<group>"; };
|
||||
A2B6141B1395ADE9000E0975 /* libz.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libz.dylib; path = usr/lib/libz.dylib; sourceTree = SDKROOT; };
|
||||
A2B9F90311BD10BE003FC8CA /* fr */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = fr; path = macosx/fr.lproj/AddMagnetWindow.xib; sourceTree = "<group>"; };
|
||||
|
@ -1399,6 +1402,8 @@
|
|||
A28E1DDF0CFFD8EC00E16385 /* ButtonToolbarItem.h */,
|
||||
A225A4BE187E369C00CDE823 /* ShareToolbarItem.h */,
|
||||
A225A4BF187E369C00CDE823 /* ShareToolbarItem.m */,
|
||||
A2B5B4E71880665E0071A66A /* ShareTorrentFileHelper.h */,
|
||||
A2B5B4E81880665E0071A66A /* ShareTorrentFileHelper.m */,
|
||||
A21979890D07B78400438EA7 /* GroupToolbarItem.h */,
|
||||
A219798A0D07B78400438EA7 /* GroupToolbarItem.m */,
|
||||
A20BFFB50D091CC700CE5D2B /* ToolbarSegmentedCell.h */,
|
||||
|
@ -2789,6 +2794,7 @@
|
|||
A2F7CF5F13035FFD0016FF10 /* URLSheetWindowController.m in Sources */,
|
||||
A2E57ABB1310822C00A7DAB1 /* StatusBarController.m in Sources */,
|
||||
A2E57BA713109E6B00A7DAB1 /* FilterBarController.m in Sources */,
|
||||
A2B5B4E91880665E0071A66A /* ShareTorrentFileHelper.m in Sources */,
|
||||
A22BAE281388040500FB022F /* NSMutableArrayAdditions.m in Sources */,
|
||||
A2966E8713DAF74C007B52DF /* GlobalOptionsPopoverViewController.m in Sources */,
|
||||
A234EA541453563B000F3E97 /* NSImageAdditions.m in Sources */,
|
||||
|
|
|
@ -97,6 +97,9 @@ typedef enum
|
|||
|
||||
IBOutlet NSMenu * fGroupsSetMenu, * fGroupsSetContextMenu;
|
||||
|
||||
IBOutlet NSMenu * fShareMenu, * fShareContextMenu;
|
||||
IBOutlet NSMenuItem * fShareMenuItem, * fShareContextMenuItem; // remove when dropping 10.6
|
||||
|
||||
QLPreviewPanel * fPreviewPanel;
|
||||
BOOL fQuitting;
|
||||
BOOL fQuitRequested;
|
||||
|
|
|
@ -45,6 +45,7 @@
|
|||
#import "ButtonToolbarItem.h"
|
||||
#import "GroupToolbarItem.h"
|
||||
#import "ShareToolbarItem.h"
|
||||
#import "ShareTorrentFileHelper.h"
|
||||
#import "ToolbarSegmentedCell.h"
|
||||
#import "BlocklistDownloader.h"
|
||||
#import "StatusBarController.h"
|
||||
|
@ -524,6 +525,12 @@ static void sleepCallback(void * controller, io_service_t y, natural_t messageTy
|
|||
if ([NSApp isOnMountainLionOrBetter])
|
||||
[[NSUserNotificationCenterMtLion defaultUserNotificationCenter] setDelegate: self];
|
||||
|
||||
// remove Share menu items
|
||||
if (![NSApp isOnMountainLionOrBetter]) {
|
||||
[[fShareMenuItem menu] removeItem:fShareMenuItem];
|
||||
[[fShareContextMenuItem menu] removeItem:fShareContextMenuItem];
|
||||
}
|
||||
|
||||
//observe notifications
|
||||
NSNotificationCenter * nc = [NSNotificationCenter defaultCenter];
|
||||
|
||||
|
@ -2877,6 +2884,14 @@ static void sleepCallback(void * controller, io_service_t y, natural_t messageTy
|
|||
[item release];
|
||||
}
|
||||
}
|
||||
else if (menu == fShareMenu || menu == fShareContextMenu) {
|
||||
[menu removeAllItems];
|
||||
|
||||
for (NSMenuItem * item in [[ShareTorrentFileHelper sharedHelper] menuItems])
|
||||
{
|
||||
[menu addItem:item];
|
||||
}
|
||||
}
|
||||
else;
|
||||
}
|
||||
|
||||
|
@ -3815,7 +3830,7 @@ static void sleepCallback(void * controller, io_service_t y, natural_t messageTy
|
|||
{
|
||||
NSParameterAssert([sender isKindOfClass:[NSButton class]]);
|
||||
|
||||
NSSharingServicePicker * picker = [[NSSharingServicePicker alloc] initWithItems: [ShareToolbarItem shareTorrentURLs]];
|
||||
NSSharingServicePicker * picker = [[NSSharingServicePicker alloc] initWithItems: [[ShareTorrentFileHelper sharedHelper] shareTorrentURLs]];
|
||||
picker.delegate = self;
|
||||
|
||||
[picker showRelativeToRect:[sender bounds] ofView:sender preferredEdge:NSMinYEdge];
|
||||
|
|
|
@ -10,6 +10,4 @@
|
|||
|
||||
@interface ShareToolbarItem : ButtonToolbarItem
|
||||
|
||||
+ (NSArray *)shareTorrentURLs;
|
||||
|
||||
@end
|
||||
|
|
|
@ -7,46 +7,21 @@
|
|||
//
|
||||
|
||||
#import "ShareToolbarItem.h"
|
||||
#import "Controller.h"
|
||||
#import "ShareTorrentFileHelper.h"
|
||||
#import "NSApplicationAdditions.h"
|
||||
#import "Torrent.h"
|
||||
|
||||
@implementation ShareToolbarItem
|
||||
|
||||
// move somewhere else?
|
||||
+ (NSArray *)shareTorrentURLs
|
||||
{
|
||||
NSArray * torrents = [(Controller *)[NSApp delegate] selectedTorrents];
|
||||
NSMutableArray * fileURLs = [NSMutableArray arrayWithCapacity: [torrents count]];
|
||||
for (Torrent * torrent in torrents)
|
||||
{
|
||||
NSString * location = [torrent torrentLocation];
|
||||
if ([location length] > 0) {
|
||||
[fileURLs addObject: [NSURL fileURLWithPath:location]];
|
||||
}
|
||||
}
|
||||
return fileURLs;
|
||||
}
|
||||
|
||||
- (NSMenuItem *) menuFormRepresentation
|
||||
{
|
||||
NSMenuItem * menuItem = [[NSMenuItem alloc] initWithTitle: [self label] action: nil keyEquivalent: @""];
|
||||
[menuItem setEnabled: [[self target] validateToolbarItem: self]];
|
||||
|
||||
NSArray * fileURLs = [[self class] shareTorrentURLs];
|
||||
if ([menuItem isEnabled] && [fileURLs count] > 0) {
|
||||
if ([menuItem isEnabled]) {
|
||||
NSMenu *servicesMenu = [[NSMenu alloc] initWithTitle: @""];
|
||||
for (NSSharingService * service in [NSSharingService sharingServicesForItems: fileURLs])
|
||||
for (NSMenuItem * item in [[ShareTorrentFileHelper sharedHelper] menuItems])
|
||||
{
|
||||
NSMenuItem *item = [[NSMenuItem alloc] initWithTitle: service.title // 10.9: change to menuItemTitle
|
||||
action: @selector(performShareAction:)
|
||||
keyEquivalent: @""];
|
||||
item.image = service.image;
|
||||
item.representedObject = service;
|
||||
service.delegate = (Controller *)[NSApp delegate];
|
||||
item.target = self;
|
||||
[servicesMenu addItem:item];
|
||||
[item release];
|
||||
}
|
||||
|
||||
[menuItem setSubmenu:servicesMenu];
|
||||
|
@ -56,10 +31,4 @@
|
|||
return menuItem;
|
||||
}
|
||||
|
||||
- (void)performShareAction:(NSMenuItem *)item
|
||||
{
|
||||
NSSharingService * service = item.representedObject;
|
||||
[service performWithItems: [[self class] shareTorrentURLs]]; // on 10.9, use attachmentFileURLs?
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
//
|
||||
// ShareTorrentFileHelper.h
|
||||
// Transmission
|
||||
//
|
||||
// Created by Mitchell Livingston on 1/10/14.
|
||||
// Copyright (c) 2014 The Transmission Project. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
@interface ShareTorrentFileHelper : NSObject
|
||||
|
||||
+ (ShareTorrentFileHelper *) sharedHelper;
|
||||
|
||||
- (NSArray *) shareTorrentURLs;
|
||||
- (NSArray *) menuItems;
|
||||
|
||||
@end
|
|
@ -0,0 +1,66 @@
|
|||
//
|
||||
// ShareTorrentFileHelper.m
|
||||
// Transmission
|
||||
//
|
||||
// Created by Mitchell Livingston on 1/10/14.
|
||||
// Copyright (c) 2014 The Transmission Project. All rights reserved.
|
||||
//
|
||||
|
||||
#import "ShareTorrentFileHelper.h"
|
||||
#import "Controller.h"
|
||||
#import "Torrent.h"
|
||||
|
||||
@implementation ShareTorrentFileHelper
|
||||
|
||||
+ (ShareTorrentFileHelper *) sharedHelper
|
||||
{
|
||||
static ShareTorrentFileHelper *helper;
|
||||
static dispatch_once_t onceToken;
|
||||
dispatch_once(&onceToken, ^{
|
||||
helper = [[ShareTorrentFileHelper alloc] init];
|
||||
});
|
||||
return helper;
|
||||
}
|
||||
|
||||
- (NSArray *) shareTorrentURLs
|
||||
{
|
||||
NSArray * torrents = [(Controller *)[NSApp delegate] selectedTorrents];
|
||||
NSMutableArray * fileURLs = [NSMutableArray arrayWithCapacity: [torrents count]];
|
||||
for (Torrent * torrent in torrents)
|
||||
{
|
||||
NSString * location = [torrent torrentLocation];
|
||||
if ([location length] > 0) {
|
||||
[fileURLs addObject: [NSURL fileURLWithPath: location]];
|
||||
}
|
||||
}
|
||||
return fileURLs;
|
||||
}
|
||||
|
||||
- (NSArray *)menuItems
|
||||
{
|
||||
NSArray * services = [NSSharingService sharingServicesForItems: [self shareTorrentURLs]];
|
||||
NSMutableArray * items = [NSMutableArray arrayWithCapacity: [services count]];
|
||||
for (NSSharingService * service in services)
|
||||
{
|
||||
NSMenuItem *item = [[NSMenuItem alloc] initWithTitle: service.title // 10.9: change to menuItemTitle
|
||||
action: @selector(performShareAction:)
|
||||
keyEquivalent: @""];
|
||||
item.image = service.image;
|
||||
item.representedObject = service;
|
||||
service.delegate = (Controller *)[NSApp delegate];
|
||||
item.target = self;
|
||||
[items addObject: item];
|
||||
[item release];
|
||||
}
|
||||
|
||||
return items;
|
||||
}
|
||||
|
||||
|
||||
- (void)performShareAction:(NSMenuItem *)item
|
||||
{
|
||||
NSSharingService * service = item.representedObject;
|
||||
[service performWithItems: [self shareTorrentURLs]]; // on 10.9, use attachmentFileURLs?
|
||||
}
|
||||
|
||||
@end
|
|
@ -157,7 +157,7 @@
|
|||
|
||||
NSPoint point = [controlView convertPoint: [event locationInWindow] fromView: nil];
|
||||
|
||||
const NSRect controlRect= [self controlButtonRectForBounds: cellFrame];
|
||||
const NSRect controlRect = [self controlButtonRectForBounds: cellFrame];
|
||||
const BOOL checkControl = NSMouseInRect(point, controlRect, [controlView isFlipped]);
|
||||
|
||||
const NSRect revealRect = [self revealButtonRectForBounds: cellFrame];
|
||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue