From 3ef46a0c821065c701d9101bad598953d91a27ca Mon Sep 17 00:00:00 2001 From: vspader Date: Mon, 15 Oct 2007 23:18:58 +0000 Subject: [PATCH] Fixed up smart folders. --- FileDrawer/DirectoryNode.m | 11 ++++++++++- FileDrawer/FileNode.m | 11 +++++++++++ FileDrawer/PathNode.h | 4 ++++ FileDrawer/PathNode.m | 10 +++++----- FileDrawer/SmartFolderNode.m | 10 ++++++++-- 5 files changed, 38 insertions(+), 8 deletions(-) diff --git a/FileDrawer/DirectoryNode.m b/FileDrawer/DirectoryNode.m index e87c45fda..f67425121 100644 --- a/FileDrawer/DirectoryNode.m +++ b/FileDrawer/DirectoryNode.m @@ -21,8 +21,17 @@ - (void)updatePath { NSArray *contents = [[[NSFileManager defaultManager] directoryContentsAtPath:path] sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)]; + NSMutableArray *fullPaths = [[NSMutableArray alloc] init]; + NSString *s; + NSEnumerator *e = [contents objectEnumerator]; + while (s = [e nextObject]) + { + [fullPaths addObject:[path stringByAppendingPathComponent: s]]; + } - [self processPaths: contents]; + [self processPaths: fullPaths]; + + [fullPaths release]; } @end diff --git a/FileDrawer/FileNode.m b/FileDrawer/FileNode.m index 3b4c79cb7..26dc62d0e 100644 --- a/FileDrawer/FileNode.m +++ b/FileDrawer/FileNode.m @@ -15,4 +15,15 @@ return YES; } +//Disable watching for us, it doesn't matter. +- (void)startWatching +{ +} +- (void)stopWatching +{ +} +- (void)updatePathNotification:(NSNotification *)notification +{ +} + @end diff --git a/FileDrawer/PathNode.h b/FileDrawer/PathNode.h index 05a96f247..8324bddf4 100644 --- a/FileDrawer/PathNode.h +++ b/FileDrawer/PathNode.h @@ -37,4 +37,8 @@ - (BOOL)isLeaf; +- (void)startWatching; +- (void)stopWatching; +- (void)updatePathNotification:(NSNotification *)notification; + @end diff --git a/FileDrawer/PathNode.m b/FileDrawer/PathNode.m index 98cfb63bc..3657b23a0 100644 --- a/FileDrawer/PathNode.m +++ b/FileDrawer/PathNode.m @@ -128,17 +128,17 @@ } PathNode *newNode; - NSString *newSubpath = [path stringByAppendingPathComponent: s]; if ([[s pathExtension] caseInsensitiveCompare:@"savedSearch"] == NSOrderedSame) { - newNode = [[SmartFolderNode alloc] initWithDataSource:dataSource path:newSubpath]; + NSLog(@"Smart folder!"); + newNode = [[SmartFolderNode alloc] initWithDataSource:dataSource path:s]; } else { BOOL isDir; - [[NSFileManager defaultManager] fileExistsAtPath:newSubpath isDirectory:&isDir]; + [[NSFileManager defaultManager] fileExistsAtPath:s isDirectory:&isDir]; if (!isDir && ![[AudioPlayer fileTypes] containsObject:[s pathExtension]]) { @@ -147,11 +147,11 @@ if (isDir) { - newNode = [[DirectoryNode alloc] initWithDataSource:dataSource path: newSubpath]; + newNode = [[DirectoryNode alloc] initWithDataSource:dataSource path: s]; } else { - newNode = [[FileNode alloc] initWithDataSource:dataSource path: newSubpath]; + newNode = [[FileNode alloc] initWithDataSource:dataSource path: s]; } } diff --git a/FileDrawer/SmartFolderNode.m b/FileDrawer/SmartFolderNode.m index 7475a7478..2ee4ef1ee 100644 --- a/FileDrawer/SmartFolderNode.m +++ b/FileDrawer/SmartFolderNode.m @@ -9,6 +9,7 @@ #import "SmartFolderNode.h" #import "DirectoryNode.h" #import "FileNode.h" +#import "FileTreeDataSource.h" @implementation SmartFolderNode @@ -31,6 +32,7 @@ [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(queryFinished:) name:(NSString*)kMDQueryDidFinishNotification object:(id)query]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(queryUpdate:) name:(NSString*)kMDQueryDidUpdateNotification object:(id)query]; + NSLog(@"Making query!"); MDQueryExecute(query, kMDQueryWantsUpdates); //Note: This is asynchronous! @@ -55,6 +57,7 @@ - (void)queryFinished:(NSNotification *)notification { + NSLog(@"Query finished!"); MDQueryRef query = (MDQueryRef)[notification object]; NSMutableArray *results = [NSMutableArray array]; @@ -68,7 +71,7 @@ MDItemRef item = (MDItemRef)MDQueryGetResultAtIndex(query, i); NSString *itemPath = (NSString*)MDItemCopyAttribute(item, kMDItemPath); - + [results addObject:itemPath]; [itemPath release]; @@ -76,13 +79,16 @@ MDQueryEnableUpdates(query); - [self processPaths:results]; + NSLog(@"Query update!"); + + [self processPaths:[results sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)]]; [dataSource reloadPathNode:self]; } - (void)queryUpdate:(NSNotification *)notification { + NSLog(@"Query update!"); [self queryFinished: notification]; }