- (id) initWithFileName: (NSString *) name path: (NSString *) path size: (uint64_t) size index: (int) index;
- (void) insertChild: (FileListNode *) child;
-- (void) insertIndex: (NSUInteger) index;
+- (void) insertIndex: (NSUInteger) index withSize: (uint64_t) size;
- (BOOL) isFolder;
- (NSString *) name;
if ((self = [self initWithFolder: YES name: name path: path]))
{
fChildren = [[NSMutableArray alloc] init];
+ fSize = 0;
}
return self;
- (void) insertChild: (FileListNode *) child
{
+ NSAssert(fIsFolder, @"method can only be invoked on files");
+
[fChildren addObject: child];
}
-- (void) insertIndex: (NSUInteger) index
+- (void) insertIndex: (NSUInteger) index withSize: (uint64_t) size
{
+ NSAssert(fIsFolder, @"method can only be invoked on files");
+
[fIndexes addIndex: index];
+ fSize += size;
}
- (id) copyWithZone: (NSZone *) zone
{
+ //this object is essentially immutable after initial setup
return [self retain];
}
- (uint64_t) size
{
- NSAssert(!fIsFolder, @"method can only be invoked on files currently");
-
return fSize;
}
- (NSImage *) icon
{
- NSAssert(!fIsFolder, @"method can only be invoked on files currently");
-
- if (!fIcon)
+ if (!fIsFolder && !fIcon)
{
fIcon = [[[NSWorkspace sharedWorkspace] iconForFileType: [fName pathExtension]] retain];
[fIcon setFlipped: YES];
- (NSArray *) children
{
- NSAssert(fIsFolder, @"method can only be invoked on folders");
-
return fChildren;
}
if ([pathComponents count] > 0)
{
- //determine if node already exists
+ //determine if folder node already exists
NSEnumerator * enumerator = [fileList objectEnumerator];
FileListNode * node;
while ((node = [enumerator nextObject]))
- if ([[node name] isEqualToString: name])
+ if ([[node name] isEqualToString: name] && [node isFolder])
break;
if (!node)
[node release];
}
- [node insertIndex: i];
+ [node insertIndex: i withSize: file->length];
[self insertPath: pathComponents forParent: node fileSize: file->length index: i];
}
else
if (isFolder)
{
- [node insertIndex: index];
+ [node insertIndex: index withSize: size];
[components removeObjectAtIndex: 0];
[self insertPath: components forParent: node fileSize: size index: index];