Basic smartfolder support for file drawer.
parent
e3d076dbf7
commit
e8242824a8
|
@ -7,6 +7,8 @@
|
|||
objects = {
|
||||
|
||||
/* Begin PBXBuildFile section */
|
||||
171678BF0AC8C39E00C28CF3 /* SmartFolderNode.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 171678BD0AC8C39E00C28CF3 /* SmartFolderNode.h */; };
|
||||
171678C00AC8C39E00C28CF3 /* SmartFolderNode.m in Sources */ = {isa = PBXBuildFile; fileRef = 171678BE0AC8C39E00C28CF3 /* SmartFolderNode.m */; };
|
||||
8D11072A0486CEB800E47090 /* MainMenu.nib in Resources */ = {isa = PBXBuildFile; fileRef = 29B97318FDCFA39411CA2CEA /* MainMenu.nib */; };
|
||||
8D11072B0486CEB800E47090 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 089C165CFE840E0CC02AAC07 /* InfoPlist.strings */; };
|
||||
8D11072D0486CEB800E47090 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 29B97316FDCFA39411CA2CEA /* main.m */; settings = {ATTRIBUTES = (); }; };
|
||||
|
@ -183,6 +185,7 @@
|
|||
8E07AAF20AAC910500A4B32F /* SS_PrefsController.h in CopyFiles */,
|
||||
8E07AB780AAC930B00A4B32F /* PreferencesController.h in CopyFiles */,
|
||||
8E7C2B160AACE0F2009B4EAD /* NDHotKeyEvent.h in CopyFiles */,
|
||||
171678BF0AC8C39E00C28CF3 /* SmartFolderNode.h in CopyFiles */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
@ -192,6 +195,8 @@
|
|||
089C165DFE840E0CC02AAC07 /* English */ = {isa = PBXFileReference; fileEncoding = 10; lastKnownFileType = text.plist.strings; name = English; path = English.lproj/InfoPlist.strings; sourceTree = "<group>"; };
|
||||
1058C7A1FEA54F0111CA2CBB /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = /System/Library/Frameworks/Cocoa.framework; sourceTree = "<absolute>"; };
|
||||
13E42FB307B3F0F600E4EEF1 /* CoreData.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreData.framework; path = /System/Library/Frameworks/CoreData.framework; sourceTree = "<absolute>"; };
|
||||
171678BD0AC8C39E00C28CF3 /* SmartFolderNode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SmartFolderNode.h; sourceTree = "<group>"; };
|
||||
171678BE0AC8C39E00C28CF3 /* SmartFolderNode.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SmartFolderNode.m; sourceTree = "<group>"; };
|
||||
29B97316FDCFA39411CA2CEA /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
|
||||
29B97319FDCFA39411CA2CEA /* English */ = {isa = PBXFileReference; lastKnownFileType = wrapper.nib; name = English; path = English.lproj/MainMenu.nib; sourceTree = "<group>"; };
|
||||
29B97324FDCFA39411CA2CEA /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = /System/Library/Frameworks/AppKit.framework; sourceTree = "<absolute>"; };
|
||||
|
@ -714,6 +719,8 @@
|
|||
8EFFCD470AA093AF00C458A5 /* FileNode.m */,
|
||||
8EFFCD520AA093AF00C458A5 /* PathNode.h */,
|
||||
8EFFCD530AA093AF00C458A5 /* PathNode.m */,
|
||||
171678BD0AC8C39E00C28CF3 /* SmartFolderNode.h */,
|
||||
171678BE0AC8C39E00C28CF3 /* SmartFolderNode.m */,
|
||||
);
|
||||
path = FileDrawer;
|
||||
sourceTree = "<group>";
|
||||
|
@ -878,6 +885,7 @@
|
|||
8E07AAF30AAC910500A4B32F /* SS_PrefsController.m in Sources */,
|
||||
8E07AB790AAC930B00A4B32F /* PreferencesController.m in Sources */,
|
||||
8E7C2B170AACE0F2009B4EAD /* NDHotKeyEvent.m in Sources */,
|
||||
171678C00AC8C39E00C28CF3 /* SmartFolderNode.m in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
|
||||
#import "DirectoryNode.h"
|
||||
#import "FileNode.h"
|
||||
#import "SmartFolderNode.h"
|
||||
|
||||
@implementation DirectoryNode
|
||||
|
||||
|
@ -39,12 +40,8 @@
|
|||
return NO;
|
||||
}
|
||||
|
||||
- (NSArray *)subpaths
|
||||
- (void)processContents: (NSArray *)contents
|
||||
{
|
||||
if (subpaths == nil)
|
||||
{
|
||||
subpaths = [[NSMutableArray alloc] init];
|
||||
NSArray *contents = [[NSFileManager defaultManager] directoryContentsAtPath:path];
|
||||
NSEnumerator *e = [contents objectEnumerator];
|
||||
NSString *s;
|
||||
while ((s = [e nextObject]))
|
||||
|
@ -54,10 +51,17 @@
|
|||
continue;
|
||||
}
|
||||
|
||||
BOOL isDir;
|
||||
PathNode *newNode;
|
||||
NSString *newSubpath = [path stringByAppendingPathComponent: s];
|
||||
|
||||
if ([[s pathExtension] caseInsensitiveCompare:@"savedSearch"] == NSOrderedSame)
|
||||
{
|
||||
newNode = [[SmartFolderNode alloc] initWithPath:newSubpath controller:controller];
|
||||
}
|
||||
else
|
||||
{
|
||||
BOOL isDir;
|
||||
|
||||
[[NSFileManager defaultManager] fileExistsAtPath:newSubpath isDirectory:&isDir];
|
||||
|
||||
if (!isDir && ![[controller acceptableFileTypes] containsObject:[s pathExtension]])
|
||||
|
@ -69,15 +73,26 @@
|
|||
newNode = [[DirectoryNode alloc] initWithPath: newSubpath controller:controller];
|
||||
else
|
||||
newNode = [[FileNode alloc] initWithPath: newSubpath];
|
||||
}
|
||||
|
||||
[subpaths addObject:newNode];
|
||||
|
||||
[newNode release];
|
||||
}
|
||||
}
|
||||
|
||||
- (NSArray *)subpaths
|
||||
{
|
||||
if (subpaths == nil)
|
||||
{
|
||||
subpaths = [[NSMutableArray alloc] init];
|
||||
NSArray *contents = [[NSFileManager defaultManager] directoryContentsAtPath:path];
|
||||
|
||||
[self processContents: contents];
|
||||
|
||||
[[controller watcher] addPath:[self path]];
|
||||
}
|
||||
|
||||
// NSLog(@"subpaths; %@", subpaths);
|
||||
return subpaths;
|
||||
}
|
||||
|
||||
|
|
|
@ -41,6 +41,9 @@
|
|||
[rootPath release];
|
||||
rootPath = r;
|
||||
|
||||
[watcher removePath:r];
|
||||
[watcher addPath:rootPath];
|
||||
|
||||
[self refreshRoot];
|
||||
}
|
||||
|
||||
|
|
|
@ -48,5 +48,4 @@
|
|||
pathIcon = pi;
|
||||
}
|
||||
|
||||
|
||||
@end
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
//
|
||||
// SmartFolderNode.h
|
||||
// Cog
|
||||
//
|
||||
// Created by Vincent Spader on 9/25/06.
|
||||
// Copyright 2006 __MyCompanyName__. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
#import "PathNode.h"
|
||||
|
||||
@interface SmartFolderNode : PathNode {
|
||||
NSMutableArray *subpaths;
|
||||
id controller;
|
||||
}
|
||||
|
||||
@end
|
|
@ -0,0 +1,160 @@
|
|||
//
|
||||
// SmartFolderNode.m
|
||||
// Cog
|
||||
//
|
||||
// Created by Vincent Spader on 9/25/06.
|
||||
// Copyright 2006 __MyCompanyName__. All rights reserved.
|
||||
//
|
||||
|
||||
#import "SmartFolderNode.h"
|
||||
#import "DirectoryNode.h"
|
||||
#import "FileNode.h"
|
||||
|
||||
@implementation SmartFolderNode
|
||||
|
||||
-(id)initWithPath:(NSString *)p controller:(id) c
|
||||
{
|
||||
self = [super initWithPath:p];
|
||||
if (self)
|
||||
{
|
||||
controller = [c retain];
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)dealloc {
|
||||
if (subpaths)
|
||||
[subpaths release];
|
||||
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
|
||||
- (BOOL)isLeaf
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
|
||||
//need to merge this and directorynode
|
||||
- (void)processContents: (NSArray *)contents
|
||||
{
|
||||
NSLog(@"PROCESSING: %@", contents);
|
||||
NSEnumerator *e = [contents objectEnumerator];
|
||||
NSString *s;
|
||||
|
||||
while (s = [e nextObject])
|
||||
{
|
||||
NSLog(@"STRING: %@", s);
|
||||
/* if ([s characterAtIndex:0] == '.')
|
||||
{
|
||||
continue;
|
||||
}
|
||||
*/
|
||||
PathNode *newNode;
|
||||
// NSString *newSubpath = [path stringByAppendingPathComponent: s];
|
||||
|
||||
if ([[s pathExtension] caseInsensitiveCompare:@"savedSearch"] == NSOrderedSame)
|
||||
{
|
||||
newNode = [[SmartFolderNode alloc] initWithPath:s controller:controller];
|
||||
}
|
||||
else
|
||||
{
|
||||
BOOL isDir;
|
||||
|
||||
[[NSFileManager defaultManager] fileExistsAtPath:s isDirectory:&isDir];
|
||||
|
||||
NSLog(@"IS IT ACCEPTABLE?");
|
||||
if (!isDir && ![[controller acceptableFileTypes] containsObject:[s pathExtension]])
|
||||
continue;
|
||||
NSLog(@"IS IT A FILE?");
|
||||
if (isDir)
|
||||
newNode = [[DirectoryNode alloc] initWithPath: s controller:controller];
|
||||
else
|
||||
newNode = [[FileNode alloc] initWithPath: s];
|
||||
}
|
||||
|
||||
[subpaths addObject:newNode];
|
||||
NSLog(@"SUBPATHS IN PROCESS: %@", subpaths);
|
||||
[newNode release];
|
||||
}
|
||||
}
|
||||
|
||||
- (NSArray *)subpaths
|
||||
{
|
||||
if (subpaths == nil)
|
||||
{
|
||||
subpaths = [[NSMutableArray alloc] init];
|
||||
|
||||
NSDictionary *doc = [NSDictionary dictionaryWithContentsOfFile:path];
|
||||
NSString *rawQuery = [doc objectForKey:@"RawQuery"];
|
||||
NSArray *searchPaths = [[doc objectForKey:@"SearchCriteria"] objectForKey:@"CurrentFolderPath"];
|
||||
|
||||
NSLog(@"Query: %@", rawQuery);
|
||||
// Ugh, Carbon from now on...
|
||||
MDQueryRef query = MDQueryCreate(kCFAllocatorDefault, (CFStringRef)rawQuery, NULL, NULL);
|
||||
|
||||
MDQuerySetSearchScope(query, (CFArrayRef)searchPaths, 0);
|
||||
|
||||
[[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(@"PATHS: %@", searchPaths);
|
||||
MDQueryExecute(query, kMDQueryWantsUpdates | kMDQuerySynchronous);
|
||||
NSLog(@"QUERY FINISHED: %@", subpaths);
|
||||
}
|
||||
|
||||
return subpaths;
|
||||
}
|
||||
|
||||
- (void)setSubpaths:(id)s
|
||||
{
|
||||
[s retain];
|
||||
[subpaths release];
|
||||
subpaths = s;
|
||||
}
|
||||
|
||||
- (unsigned int)countOfSubpaths
|
||||
{
|
||||
return [[self subpaths] count];
|
||||
}
|
||||
|
||||
- (PathNode *)objectInSubpathsAtIndex:(unsigned int)index
|
||||
{
|
||||
return [[self subpaths] objectAtIndex:index];
|
||||
}
|
||||
|
||||
- (void)queryFinished:(NSNotification *)notification
|
||||
{
|
||||
MDQueryRef query = [notification object];
|
||||
|
||||
NSMutableArray *results = [NSMutableArray array];
|
||||
|
||||
int c = MDQueryGetResultCount(query);
|
||||
|
||||
int i;
|
||||
for (i = 0; i < c; i++)
|
||||
{
|
||||
MDItemRef item = (MDItemRef)MDQueryGetResultAtIndex(query, i);
|
||||
|
||||
NSString *itemPath = (NSString*)MDItemCopyAttribute(item, kMDItemPath);
|
||||
NSLog(@"RESULT PATH: %@", itemPath);
|
||||
|
||||
[results addObject:itemPath];
|
||||
|
||||
[itemPath release];
|
||||
}
|
||||
|
||||
[self processContents:results];
|
||||
NSLog(@"CONTENTS PROCESSED");
|
||||
}
|
||||
|
||||
- (void)queryUpdate:(NSNotification *)notification
|
||||
{
|
||||
MDQueryRef query = [notification object];
|
||||
NSLog(@"QUERY UPDATE: %@", notification);
|
||||
}
|
||||
|
||||
|
||||
@end
|
||||
|
Loading…
Reference in New Issue