Fixed up smart folders.

CQTexperiment
vspader 2007-10-15 23:18:58 +00:00
parent 47582ae4f4
commit 3ef46a0c82
5 changed files with 38 additions and 8 deletions

View File

@ -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

View File

@ -15,4 +15,15 @@
return YES;
}
//Disable watching for us, it doesn't matter.
- (void)startWatching
{
}
- (void)stopWatching
{
}
- (void)updatePathNotification:(NSNotification *)notification
{
}
@end

View File

@ -37,4 +37,8 @@
- (BOOL)isLeaf;
- (void)startWatching;
- (void)stopWatching;
- (void)updatePathNotification:(NSNotification *)notification;
@end

View File

@ -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];
}
}

View File

@ -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];
}