From 8296112faeb7ef876dfd235be4c76b4ef1719a74 Mon Sep 17 00:00:00 2001 From: Mitchell Livingston Date: Mon, 28 Sep 2009 23:18:26 +0000 Subject: [PATCH] #2458 Tracker pane - copy addresses --- macosx/TrackerTableView.h | 2 ++ macosx/TrackerTableView.m | 44 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/macosx/TrackerTableView.h b/macosx/TrackerTableView.h index 6c56f3e7d..25a767da7 100644 --- a/macosx/TrackerTableView.h +++ b/macosx/TrackerTableView.h @@ -31,4 +31,6 @@ - (void) setTrackers: (NSArray *) trackers; +- (IBAction) copy: (id) sender; + @end diff --git a/macosx/TrackerTableView.m b/macosx/TrackerTableView.m index 09b7d1368..9c1ca146b 100644 --- a/macosx/TrackerTableView.m +++ b/macosx/TrackerTableView.m @@ -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 {