1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2025-02-02 04:22:44 +00:00

Type-ahead in the table view. Works similar to the way typing in the finder works.

This commit is contained in:
Mitchell Livingston 2006-07-23 20:53:31 +00:00
parent 67cbcb68b1
commit ba3b7ea279
4 changed files with 63 additions and 5 deletions

View file

@ -7,19 +7,19 @@
<key>IBEditorPositions</key>
<dict>
<key>153</key>
<string>299 469 554 217 0 0 1152 842 </string>
<string>155 441 554 217 0 0 1152 842 </string>
<key>28</key>
<string>124 423 554 295 0 0 1152 842 </string>
<string>229 409 554 290 0 0 1152 842 </string>
<key>41</key>
<string>299 417 554 321 0 0 1152 842 </string>
<string>125 133 554 321 0 0 1152 842 </string>
<key>66</key>
<string>299 526 554 104 0 0 1152 842 </string>
<string>212 526 554 104 0 0 1152 842 </string>
</dict>
<key>IBFramework Version</key>
<string>446.1</string>
<key>IBOpenObjects</key>
<array>
<integer>28</integer>
<integer>66</integer>
</array>
<key>IBSystem Version</key>
<string>8J135</string>

View file

@ -41,6 +41,8 @@
IBOutlet NSMenu * fContextRow, * fContextNoRow;
NSImage * fResumeOnIcon, * fResumeOffIcon, * fPauseOnIcon, * fPauseOffIcon,
* fRevealOnIcon, * fRevealOffIcon;
NSMutableArray * fKeyStrokes;
}
- (void) setTorrents: (NSArray *) torrents;

View file

@ -59,6 +59,8 @@
fClickPoint = NSZeroPoint;
fKeyStrokes = [[NSMutableArray alloc] init];
fDefaults = [NSUserDefaults standardUserDefaults];
}
@ -71,6 +73,12 @@
[fContextNoRow setTitle: @"Context"];
}
- (void) dealloc
{
[fKeyStrokes release];
[super dealloc];
}
- (void) setTorrents: (NSArray *) torrents
{
fTorrents = torrents;
@ -143,6 +151,54 @@
}
}
- (void) keyDown: (NSEvent *) event
{
unichar newChar = [[event characters] characterAtIndex: 0];
if (newChar == ' ' || [[NSCharacterSet alphanumericCharacterSet] characterIsMember: newChar])
{
if ([fKeyStrokes count] > 0 && [event timestamp] - [[fKeyStrokes lastObject] timestamp] > 1.0)
[fKeyStrokes removeAllObjects];
[fKeyStrokes addObject: event];
[self interpretKeyEvents: fKeyStrokes];
}
else
{
if ([fKeyStrokes count] > 0)
[fKeyStrokes removeAllObjects];
[super keyDown: event];
}
}
- (void) insertText: (NSString *) text
{
NSLog(text);
//sort torrents by name before finding closest match
NSSortDescriptor * nameDescriptor = [[[NSSortDescriptor alloc] initWithKey: @"name" ascending: YES] autorelease];
NSArray * descriptors = [[NSArray alloc] initWithObjects: nameDescriptor, nil];
NSArray * tempTorrents = [fTorrents sortedArrayUsingDescriptors: descriptors];
[descriptors release];
//select torrent closest to text that isn't before text alphabetically
NSEnumerator * enumerator = [tempTorrents objectEnumerator];
Torrent * torrent;
while ((torrent = [enumerator nextObject]))
{
if ([[torrent name] caseInsensitiveCompare: text] != NSOrderedAscending)
{
[self selectRow: [fTorrents indexOfObject: torrent] byExtendingSelection: NO];
break;
}
}
//select last torrent alphabetically if no match found
if (!torrent)
[self selectRow: [fTorrents indexOfObject: [tempTorrents lastObject]] byExtendingSelection: NO];
}
- (void) drawRect: (NSRect) r
{
NSRect rect;