Changeset 7308


Ignore:
Timestamp:
Dec 7, 2008, 6:20:14 PM (12 years ago)
Author:
livings124
Message:

add support to filter file list (not yet implemented in the interface)

Location:
trunk/macosx
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/macosx/FileOutlineController.h

    r5864 r7308  
    3131{
    3232    Torrent * fTorrent;
     33    NSArray * fFileList;
    3334   
    3435    IBOutlet FileOutlineView * fOutline;
     36   
     37    NSString * fFilterText;
    3538}
    3639
     
    3841
    3942- (void) setTorrent: (Torrent *) torrent;
     43
     44- (void) setFilterText: (NSString *) text;
    4045
    4146- (void) reloadData;
  • trunk/macosx/FileOutlineController.m

    r7005 r7308  
    7373}
    7474
     75- (void) dealloc
     76{
     77    [fFileList release];
     78    [fFilterText release];
     79    [super dealloc];
     80}
     81
    7582- (FileOutlineView *) outlineView
    7683{
    7784    return fOutline;
    78 }
    79 
    80 - (void) outlineViewSelectionDidChange: (NSNotification *) notification
    81 {
    82     [[QuickLookController quickLook] updateQuickLook];
    8385}
    8486
     
    8890    [fOutline setTorrent: fTorrent];
    8991   
     92    [fFileList release];
     93    fFileList = [[fTorrent fileList] retain];
     94   
     95    [fFilterText release];
     96    fFilterText = nil;
     97   
    9098    [fOutline deselectAll: nil];
    9199    [fOutline reloadData];
    92100}
    93101
     102- (void) setFilterText: (NSString *) text
     103{
     104    if ([text isEqualToString: @""])
     105        text = nil;
     106   
     107    if (text == fFilterText || [text isEqualToString: fFilterText])
     108        return;
     109   
     110    [fFilterText release];
     111    fFilterText = [text retain];
     112   
     113    [fFileList release];
     114    if (!fFilterText)
     115        fFileList = [[fTorrent fileList] retain];
     116    else
     117    {
     118        NSMutableArray * list = [NSMutableArray arrayWithCapacity: [fTorrent fileCount]];
     119       
     120        NSEnumerator * enumerator = [[fTorrent flatFileList] objectEnumerator];
     121        FileListNode * node;
     122        while ((node = [enumerator nextObject]))
     123        if ([[node name] rangeOfString: fFilterText options: NSCaseInsensitiveSearch].location != NSNotFound)
     124            [list addObject: node];
     125       
     126        fFileList = [[NSArray alloc] initWithArray: list];
     127    }
     128   
     129    [fOutline reloadData];
     130}
     131
    94132- (void) reloadData
    95133{
     
    98136}
    99137
     138- (void) outlineViewSelectionDidChange: (NSNotification *) notification
     139{
     140    [[QuickLookController quickLook] updateQuickLook];
     141}
     142
    100143- (NSInteger) outlineView: (NSOutlineView *) outlineView numberOfChildrenOfItem: (id) item
    101144{
    102145    if (!item)
    103         return fTorrent ? [[fTorrent fileList] count] : 0;
     146        return fFileList ? [fFileList count] : 0;
    104147    else
    105148    {
     
    116159- (id) outlineView: (NSOutlineView *) outlineView child: (NSInteger) index ofItem: (id) item
    117160{
    118     return [(item ? [(FileListNode *)item children] : [fTorrent fileList]) objectAtIndex: index];
     161    return [(item ? [(FileListNode *)item children] : fFileList) objectAtIndex: index];
    119162}
    120163
     
    296339        for (NSInteger i = [indexSet firstIndex]; i != NSNotFound; i = [indexSet indexGreaterThanIndex: i])
    297340            if ([[NSFileManager defaultManager] fileExistsAtPath:
    298                     [downloadFolder stringByAppendingPathComponent: [[[fTorrent fileList] objectAtIndex: i] fullPath]]])
     341                    [downloadFolder stringByAppendingPathComponent: [[fFileList objectAtIndex: i] fullPath]]])
    299342                return YES;
    300343        return NO;
  • trunk/macosx/Torrent.m

    r7307 r7308  
    467467            while ((node = [nodeEnumerator nextObject]))
    468468            {
     469                #warning this could be more thorough
    469470                if ([[node fullPath] hasPrefix: file])
    470471                {
Note: See TracChangeset for help on using the changeset viewer.