mirror of
https://github.com/transmission/transmission
synced 2024-12-31 20:16:57 +00:00
#2458 Tracker pane - copy addresses
This commit is contained in:
parent
d08ab9e510
commit
8296112fae
2 changed files with 46 additions and 0 deletions
|
@ -31,4 +31,6 @@
|
|||
|
||||
- (void) setTrackers: (NSArray *) trackers;
|
||||
|
||||
- (IBAction) copy: (id) sender;
|
||||
|
||||
@end
|
||||
|
|
|
@ -23,6 +23,8 @@
|
|||
*****************************************************************************/
|
||||
|
||||
#import "TrackerTableView.h"
|
||||
#import "NSApplicationAdditions.h"
|
||||
#import "TrackerNode.h"
|
||||
|
||||
@implementation TrackerTableView
|
||||
|
||||
|
@ -37,6 +39,48 @@
|
|||
fTrackers = trackers;
|
||||
}
|
||||
|
||||
- (IBAction) copy: (id) sender
|
||||
{
|
||||
NSMutableArray * addresses = [NSMutableArray arrayWithCapacity: [fTrackers count]];
|
||||
NSIndexSet * indexes = [self selectedRowIndexes];
|
||||
for (NSUInteger i = [indexes firstIndex]; i != NSNotFound; i = [indexes indexGreaterThanIndex: i])
|
||||
{
|
||||
id item = [fTrackers objectAtIndex: i];
|
||||
if ([item isKindOfClass: [NSNumber class]])
|
||||
{
|
||||
for (++i; i < [fTrackers count] && ![[fTrackers objectAtIndex: i] isKindOfClass: [NSNumber class]]; ++i)
|
||||
[addresses addObject: [(TrackerNode *)[fTrackers objectAtIndex: i] fullAnnounceAddress]];
|
||||
--i;
|
||||
}
|
||||
else
|
||||
[addresses addObject: [(TrackerNode *)item fullAnnounceAddress]];
|
||||
}
|
||||
|
||||
NSString * text = [addresses componentsJoinedByString: @"\n"];;
|
||||
|
||||
NSPasteboard * pb = [NSPasteboard generalPasteboard];
|
||||
if ([NSApp isOnSnowLeopardOrBetter])
|
||||
{
|
||||
[pb clearContents];
|
||||
[pb writeObjects: [NSArray arrayWithObject: text]];
|
||||
}
|
||||
else
|
||||
{
|
||||
[pb declareTypes: [NSArray arrayWithObject: NSStringPboardType] owner: nil];
|
||||
[pb setString: text forType: NSStringPboardType];
|
||||
}
|
||||
}
|
||||
|
||||
- (BOOL) validateMenuItem: (NSMenuItem *) menuItem
|
||||
{
|
||||
SEL action = [menuItem action];
|
||||
|
||||
if (action == @selector(copy:))
|
||||
return [self numberOfSelectedRows] > 0;
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
//alternating rows - first row after group row is white
|
||||
- (void) highlightSelectionInClipRect: (NSRect) clipRect
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue