From 83df860896d26edcd61960d5d5f6bcc6ea934c02 Mon Sep 17 00:00:00 2001 From: Mitchell Livingston Date: Sat, 27 Oct 2007 14:57:46 +0000 Subject: [PATCH] on Leopard us the built-in delegate to select a row while typing, and make Tiger's behavior similar to the new behavior --- macosx/InfoWindowController.m | 2 +- macosx/NSApplicationAdditions.m | 4 ++++ macosx/TorrentTableView.m | 39 +++++++++++++++++++++++++++------ 3 files changed, 37 insertions(+), 8 deletions(-) diff --git a/macosx/InfoWindowController.m b/macosx/InfoWindowController.m index 944803341..8bba4257f 100644 --- a/macosx/InfoWindowController.m +++ b/macosx/InfoWindowController.m @@ -804,7 +804,7 @@ typedef enum } } -- (NSString *)outlineView:(NSOutlineView *)outlineView typeSelectStringForTableColumn:(NSTableColumn *)tableColumn item:(id)item +- (NSString *) outlineView: (NSOutlineView *) outlineView typeSelectStringForTableColumn: (NSTableColumn *) tableColumn item: (id) item { return [item objectForKey: @"Name"]; } diff --git a/macosx/NSApplicationAdditions.m b/macosx/NSApplicationAdditions.m index 373ce7575..bcaab6d85 100644 --- a/macosx/NSApplicationAdditions.m +++ b/macosx/NSApplicationAdditions.m @@ -24,6 +24,10 @@ #import "NSApplicationAdditions.h" +#ifndef NSAppKitVersionNumber10_4 +#define NSAppKitVersionNumber10_4 824 +#endif + @implementation NSApplication (NSApplicationAdditions) - (BOOL) isOnLeopardOrBetter diff --git a/macosx/TorrentTableView.m b/macosx/TorrentTableView.m index 98a4a0ec9..9d5ee5679 100644 --- a/macosx/TorrentTableView.m +++ b/macosx/TorrentTableView.m @@ -26,6 +26,7 @@ #import "TorrentCell.h" #import "Controller.h" #import "Torrent.h" +#import "NSApplicationAdditions.h" #import "NSMenuAdditions.h" #define PADDING 3.0 @@ -106,8 +107,15 @@ [cell setRepresentedObject: [fTorrents objectAtIndex: row]]; } + +- (NSString *) tableView: (NSTableView *) tableView typeSelectStringForTableColumn: (NSTableColumn *) tableColumn row: (int) row +{ + return [[fTorrents objectAtIndex: row] name]; +} + - (void) mouseDown: (NSEvent *) event { + //NSLog(@"down"); fClickPoint = [self convertPoint: [event locationInWindow] fromView: nil]; if ([self pointInActionRect: fClickPoint]) @@ -150,6 +158,7 @@ #warning not always working - (void) mouseUp: (NSEvent *) event { + //NSLog(@"up"); NSPoint point = [self convertPoint: [event locationInWindow] fromView: nil]; int row = [self rowAtPoint: point], oldRow = [self rowAtPoint: fClickPoint]; @@ -239,8 +248,21 @@ } } +- (void) flagsChanged: (NSEvent *) event +{ + [self display]; + [super flagsChanged: event]; +} + - (void) keyDown: (NSEvent *) event { + //this is handled by the delegate in Leopard + if ([NSApp isOnLeopardOrBetter]) + { + [super keyDown: event]; + return; + } + if (!fKeyStrokes) fKeyStrokes = [[NSMutableArray alloc] init]; @@ -262,14 +284,15 @@ } } -- (void) flagsChanged: (NSEvent *) event -{ - [self display]; - [super flagsChanged: event]; -} - - (void) insertText: (NSString *) text { + //this is handled by the delegate in Leopard + if ([NSApp isOnLeopardOrBetter]) + { + [super insertText: text]; + return; + } + //sort torrents by name before finding closest match NSSortDescriptor * nameDescriptor = [[[NSSortDescriptor alloc] initWithKey: @"name" ascending: YES selector: @selector(caseInsensitiveCompare:)] autorelease]; @@ -278,12 +301,14 @@ NSArray * tempTorrents = [fTorrents sortedArrayUsingDescriptors: descriptors]; [descriptors release]; + text = [text lowercaseString]; + //select torrent closest to text that isn't before text alphabetically int row; NSEnumerator * enumerator = [tempTorrents objectEnumerator]; Torrent * torrent; while ((torrent = [enumerator nextObject])) - if ([[torrent name] caseInsensitiveCompare: text] != NSOrderedAscending) + if ([[[torrent name] lowercaseString] hasPrefix: text]) { row = [fTorrents indexOfObject: torrent]; break;