cog/FileDrawer/DirectoryNode.m

116 lines
2.1 KiB
Matlab
Raw Normal View History

2006-09-02 16:09:20 +00:00
//
// DirectoryNode.m
// Cog
//
// Created by Vincent Spader on 8/20/2006.
// Copyright 2006 Vincent Spader. All rights reserved.
//
#import "DirectoryNode.h"
#import "FileNode.h"
#import "SmartFolderNode.h"
2006-09-02 16:09:20 +00:00
@implementation DirectoryNode
-(id)initWithPath:(NSString *)p controller:(id) c
{
self = [super initWithPath:p];
if (self)
{
controller = [c retain];
}
return self;
}
- (void)dealloc {
[[controller watcher] removePath:[self path]];
if (subpaths)
[subpaths release];
2006-09-02 16:09:20 +00:00
[controller release];
2006-09-02 16:09:20 +00:00
[super dealloc];
}
- (BOOL)isLeaf
{
return NO;
}
- (void)processContents: (NSArray *)contents
2006-09-02 16:09:20 +00:00
{
NSEnumerator *e = [contents objectEnumerator];
NSString *s;
while ((s = [e nextObject]))
2006-09-02 16:09:20 +00:00
{
if ([s characterAtIndex:0] == '.')
{
continue;
}
PathNode *newNode;
NSString *newSubpath = [path stringByAppendingPathComponent: s];
if ([[s pathExtension] caseInsensitiveCompare:@"savedSearch"] == NSOrderedSame)
{
newNode = [[SmartFolderNode alloc] initWithPath:newSubpath controller:controller];
}
else
2006-09-02 16:09:20 +00:00
{
BOOL isDir;
[[NSFileManager defaultManager] fileExistsAtPath:newSubpath isDirectory:&isDir];
if (!isDir && ![[controller acceptableFileTypes] containsObject:[s pathExtension]])
{
continue;
}
if (isDir)
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] sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];
[self processContents: contents];
2006-09-02 16:09:20 +00:00
[[controller watcher] addPath:[self path]];
}
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];
}
@end