on Leopard us the built-in delegate to select a row while typing, and make Tiger's behavior similar to the new behavior

This commit is contained in:
Mitchell Livingston 2007-10-27 14:57:46 +00:00
parent daf08fb435
commit 83df860896
3 changed files with 37 additions and 8 deletions

View File

@ -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"];
}

View File

@ -24,6 +24,10 @@
#import "NSApplicationAdditions.h"
#ifndef NSAppKitVersionNumber10_4
#define NSAppKitVersionNumber10_4 824
#endif
@implementation NSApplication (NSApplicationAdditions)
- (BOOL) isOnLeopardOrBetter

View File

@ -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;