Changeset 680


Ignore:
Timestamp:
Jul 23, 2006, 8:53:31 PM (15 years ago)
Author:
livings124
Message:

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

Location:
trunk/macosx
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/macosx/English.lproj/PrefsWindow.nib/info.nib

    r658 r680  
    88        <dict>
    99                <key>153</key>
    10                 <string>299 469 554 217 0 0 1152 842 </string>
     10                <string>155 441 554 217 0 0 1152 842 </string>
    1111                <key>28</key>
    12                 <string>124 423 554 295 0 0 1152 842 </string>
     12                <string>229 409 554 290 0 0 1152 842 </string>
    1313                <key>41</key>
    14                 <string>299 417 554 321 0 0 1152 842 </string>
     14                <string>125 133 554 321 0 0 1152 842 </string>
    1515                <key>66</key>
    16                 <string>299 526 554 104 0 0 1152 842 </string>
     16                <string>212 526 554 104 0 0 1152 842 </string>
    1717        </dict>
    1818        <key>IBFramework Version</key>
     
    2020        <key>IBOpenObjects</key>
    2121        <array>
    22                 <integer>28</integer>
     22                <integer>66</integer>
    2323        </array>
    2424        <key>IBSystem Version</key>
  • trunk/macosx/TorrentTableView.h

    r530 r680  
    4242    NSImage             * fResumeOnIcon, * fResumeOffIcon, * fPauseOnIcon, * fPauseOffIcon,
    4343                        * fRevealOnIcon, * fRevealOffIcon;
     44   
     45    NSMutableArray      * fKeyStrokes;
    4446}
    4547- (void) setTorrents: (NSArray *) torrents;
  • trunk/macosx/TorrentTableView.m

    r678 r680  
    6060        fClickPoint = NSZeroPoint;
    6161       
     62        fKeyStrokes = [[NSMutableArray alloc] init];
     63       
    6264        fDefaults = [NSUserDefaults standardUserDefaults];
    6365    }
     
    7072    [fContextRow setTitle: @"Context"];
    7173    [fContextNoRow setTitle: @"Context"];
     74}
     75
     76- (void) dealloc
     77{
     78    [fKeyStrokes release];
     79    [super dealloc];
    7280}
    7381
     
    142150        return fContextNoRow;
    143151    }
     152}
     153
     154- (void) keyDown: (NSEvent *) event
     155{
     156    unichar newChar = [[event characters] characterAtIndex: 0];
     157    if (newChar == ' ' || [[NSCharacterSet alphanumericCharacterSet] characterIsMember: newChar])
     158    {
     159        if ([fKeyStrokes count] > 0 && [event timestamp] - [[fKeyStrokes lastObject] timestamp] > 1.0)
     160            [fKeyStrokes removeAllObjects];
     161        [fKeyStrokes addObject: event];
     162   
     163        [self interpretKeyEvents: fKeyStrokes];
     164    }
     165    else
     166    {
     167        if ([fKeyStrokes count] > 0)
     168            [fKeyStrokes removeAllObjects];
     169       
     170        [super keyDown: event];
     171    }
     172}
     173
     174- (void) insertText: (NSString *) text
     175{
     176    NSLog(text);
     177   
     178    //sort torrents by name before finding closest match
     179    NSSortDescriptor * nameDescriptor = [[[NSSortDescriptor alloc] initWithKey: @"name" ascending: YES] autorelease];
     180    NSArray * descriptors = [[NSArray alloc] initWithObjects: nameDescriptor, nil];
     181
     182    NSArray * tempTorrents = [fTorrents sortedArrayUsingDescriptors: descriptors];
     183    [descriptors release];
     184   
     185    //select torrent closest to text that isn't before text alphabetically
     186    NSEnumerator * enumerator = [tempTorrents objectEnumerator];
     187    Torrent * torrent;
     188    while ((torrent = [enumerator nextObject]))
     189    {
     190        if ([[torrent name] caseInsensitiveCompare: text] != NSOrderedAscending)
     191        {
     192            [self selectRow: [fTorrents indexOfObject: torrent] byExtendingSelection: NO];
     193            break;
     194        }
     195    }
     196   
     197    //select last torrent alphabetically if no match found
     198    if (!torrent)
     199        [self selectRow: [fTorrents indexOfObject: [tempTorrents lastObject]] byExtendingSelection: NO];
    144200}
    145201
Note: See TracChangeset for help on using the changeset viewer.