diff --git a/macosx/FileOutlineController.h b/macosx/FileOutlineController.h index e54f6195e..d35834a12 100644 --- a/macosx/FileOutlineController.h +++ b/macosx/FileOutlineController.h @@ -30,14 +30,19 @@ @interface FileOutlineController : NSObject { Torrent * fTorrent; + NSArray * fFileList; IBOutlet FileOutlineView * fOutline; + + NSString * fFilterText; } - (FileOutlineView *) outlineView; - (void) setTorrent: (Torrent *) torrent; +- (void) setFilterText: (NSString *) text; + - (void) reloadData; - (void) setCheck: (id) sender; diff --git a/macosx/FileOutlineController.m b/macosx/FileOutlineController.m index 5e08ab972..c781edfc4 100644 --- a/macosx/FileOutlineController.m +++ b/macosx/FileOutlineController.m @@ -72,35 +72,78 @@ typedef enum [self setTorrent: nil]; } +- (void) dealloc +{ + [fFileList release]; + [fFilterText release]; + [super dealloc]; +} + - (FileOutlineView *) outlineView { return fOutline; } -- (void) outlineViewSelectionDidChange: (NSNotification *) notification -{ - [[QuickLookController quickLook] updateQuickLook]; -} - - (void) setTorrent: (Torrent *) torrent { fTorrent = torrent; [fOutline setTorrent: fTorrent]; + [fFileList release]; + fFileList = [[fTorrent fileList] retain]; + + [fFilterText release]; + fFilterText = nil; + [fOutline deselectAll: nil]; [fOutline reloadData]; } +- (void) setFilterText: (NSString *) text +{ + if ([text isEqualToString: @""]) + text = nil; + + if (text == fFilterText || [text isEqualToString: fFilterText]) + return; + + [fFilterText release]; + fFilterText = [text retain]; + + [fFileList release]; + if (!fFilterText) + fFileList = [[fTorrent fileList] retain]; + else + { + NSMutableArray * list = [NSMutableArray arrayWithCapacity: [fTorrent fileCount]]; + + NSEnumerator * enumerator = [[fTorrent flatFileList] objectEnumerator]; + FileListNode * node; + while ((node = [enumerator nextObject])) + if ([[node name] rangeOfString: fFilterText options: NSCaseInsensitiveSearch].location != NSNotFound) + [list addObject: node]; + + fFileList = [[NSArray alloc] initWithArray: list]; + } + + [fOutline reloadData]; +} + - (void) reloadData { [fTorrent updateFileStat]; [fOutline reloadData]; } +- (void) outlineViewSelectionDidChange: (NSNotification *) notification +{ + [[QuickLookController quickLook] updateQuickLook]; +} + - (NSInteger) outlineView: (NSOutlineView *) outlineView numberOfChildrenOfItem: (id) item { if (!item) - return fTorrent ? [[fTorrent fileList] count] : 0; + return fFileList ? [fFileList count] : 0; else { FileListNode * node = (FileListNode *)item; @@ -115,7 +158,7 @@ typedef enum - (id) outlineView: (NSOutlineView *) outlineView child: (NSInteger) index ofItem: (id) item { - return [(item ? [(FileListNode *)item children] : [fTorrent fileList]) objectAtIndex: index]; + return [(item ? [(FileListNode *)item children] : fFileList) objectAtIndex: index]; } - (id) outlineView: (NSOutlineView *) outlineView objectValueForTableColumn: (NSTableColumn *) tableColumn byItem: (id) item @@ -295,7 +338,7 @@ typedef enum NSIndexSet * indexSet = [fOutline selectedRowIndexes]; for (NSInteger i = [indexSet firstIndex]; i != NSNotFound; i = [indexSet indexGreaterThanIndex: i]) if ([[NSFileManager defaultManager] fileExistsAtPath: - [downloadFolder stringByAppendingPathComponent: [[[fTorrent fileList] objectAtIndex: i] fullPath]]]) + [downloadFolder stringByAppendingPathComponent: [[fFileList objectAtIndex: i] fullPath]]]) return YES; return NO; } diff --git a/macosx/Torrent.m b/macosx/Torrent.m index 1a0c52439..c0d18b061 100644 --- a/macosx/Torrent.m +++ b/macosx/Torrent.m @@ -466,6 +466,7 @@ void completenessChangeCallback(tr_torrent * torrent, tr_completeness status, vo FileListNode * node; while ((node = [nodeEnumerator nextObject])) { + #warning this could be more thorough if ([[node fullPath] hasPrefix: file]) { isExtra = NO;