2006-09-02 16:09:20 +00:00
|
|
|
//
|
|
|
|
// FileTreeController.m
|
|
|
|
// Cog
|
|
|
|
//
|
|
|
|
// Created by Vincent Spader on 8/20/2006.
|
|
|
|
// Copyright 2006 Vincent Spader. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
#import "FileTreeController.h"
|
2007-03-09 01:16:06 +00:00
|
|
|
#import "FileTreeWatcher.h"
|
2006-09-02 16:09:20 +00:00
|
|
|
#import "DirectoryNode.h"
|
|
|
|
#import "ImageTextCell.h"
|
2007-02-18 17:35:28 +00:00
|
|
|
#import "KFTypeSelectTableView.h"
|
2007-03-09 01:16:06 +00:00
|
|
|
#import "PlaylistLoader.h"
|
2006-09-02 16:09:20 +00:00
|
|
|
|
|
|
|
@implementation FileTreeController
|
|
|
|
|
|
|
|
- (void)awakeFromNib
|
|
|
|
{
|
|
|
|
watcher = [[FileTreeWatcher alloc] init];
|
|
|
|
[watcher setDelegate:self];
|
|
|
|
|
2006-09-17 18:11:29 +00:00
|
|
|
[self setRootPath: [[[NSUserDefaultsController sharedUserDefaultsController] defaults] objectForKey:@"fileDrawerRootPath"] ];
|
2006-09-02 16:09:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)dealloc
|
|
|
|
{
|
|
|
|
[rootPath release];
|
2006-09-17 18:11:29 +00:00
|
|
|
[watcher release];
|
|
|
|
|
|
|
|
NSLog(@"DEALLOCATING CONTROLLER");
|
|
|
|
|
2006-09-02 16:09:20 +00:00
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (id)rootPath
|
|
|
|
{
|
|
|
|
return rootPath;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setRootPath:(id)r
|
|
|
|
{
|
|
|
|
[r retain];
|
|
|
|
[rootPath release];
|
|
|
|
rootPath = r;
|
2006-09-26 22:22:56 +00:00
|
|
|
|
|
|
|
[watcher removePath:r];
|
|
|
|
[watcher addPath:rootPath];
|
2006-09-02 16:09:20 +00:00
|
|
|
|
|
|
|
[self refreshRoot];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) refreshRoot
|
|
|
|
{
|
|
|
|
DirectoryNode *base = [[DirectoryNode alloc] initWithPath:rootPath controller:self];
|
2006-09-17 18:11:29 +00:00
|
|
|
NSLog(@"Subpaths: %i", [[base subpaths] count]);
|
2006-09-02 16:09:20 +00:00
|
|
|
[self setContent: [base subpaths]];
|
2006-09-17 18:11:29 +00:00
|
|
|
NSLog(@"Test: %i", [[self content] retainCount]);
|
|
|
|
|
2006-09-02 16:09:20 +00:00
|
|
|
[base release];
|
|
|
|
}
|
|
|
|
|
2006-09-17 18:11:29 +00:00
|
|
|
//BUG IN NSTREECONTROLLER'S SETCONTENT. FIX YOUR SHIT, APPLE!
|
|
|
|
- (void)setContent:(id)content
|
|
|
|
{
|
|
|
|
if(![content isEqual:[self content]])
|
|
|
|
{
|
|
|
|
NSArray *paths = [[self selectionIndexPaths] retain];
|
|
|
|
[super setContent:nil];
|
|
|
|
[super setContent:content];
|
|
|
|
[self setSelectionIndexPaths:paths];
|
|
|
|
[paths release];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-09-02 16:09:20 +00:00
|
|
|
- (void)refreshPath:(NSString *)path
|
|
|
|
{
|
|
|
|
if ([path compare:rootPath] == NSOrderedSame) {
|
|
|
|
[self refreshRoot];
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
NSArray *pathComponents = [path pathComponents];
|
|
|
|
NSArray *rootComponents = [rootPath pathComponents];
|
|
|
|
int i = 0;
|
|
|
|
while (i < [rootComponents count] && i < [pathComponents count] &&
|
|
|
|
NSOrderedSame == [[rootComponents objectAtIndex: i] compare:[pathComponents objectAtIndex: i]])
|
|
|
|
{
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
id p;
|
|
|
|
NSEnumerator *e = [[self content] objectEnumerator];
|
|
|
|
while ((p = [e nextObject]))
|
|
|
|
{
|
|
|
|
id c = [pathComponents objectAtIndex:i];
|
|
|
|
if (NSOrderedSame == [[[p path] lastPathComponent] compare:c]) {
|
|
|
|
if (i == [pathComponents count] - 1) {
|
|
|
|
[p setSubpaths:nil];
|
|
|
|
// [self rearrangeObjects];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
e = [[c subpaths] objectEnumerator];
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSArray *)acceptableFileTypes
|
|
|
|
{
|
2007-03-09 01:16:06 +00:00
|
|
|
return [playlistLoader acceptableFileTypes];
|
2006-09-02 16:09:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (FileTreeWatcher *)watcher
|
|
|
|
{
|
|
|
|
return watcher;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)outlineView:(NSOutlineView *)olv writeItems:(NSArray*)items toPasteboard:(NSPasteboard*)pboard {
|
|
|
|
//Get selected paths
|
|
|
|
NSMutableArray *paths = [NSMutableArray arrayWithCapacity:[items count]];
|
|
|
|
NSEnumerator *e = [items objectEnumerator];
|
2007-03-09 01:16:06 +00:00
|
|
|
id p;
|
2006-09-02 16:09:20 +00:00
|
|
|
|
|
|
|
while (p = [e nextObject]) {
|
|
|
|
int i;
|
|
|
|
PathNode *n = nil;
|
|
|
|
NSIndexPath *ip = [p indexPath];
|
2007-03-09 01:16:06 +00:00
|
|
|
|
2006-09-02 16:09:20 +00:00
|
|
|
for (i = 0; i < [ip length]; i++)
|
|
|
|
{
|
|
|
|
NSArray *a = (n == nil) ? [self content] : [n subpaths];
|
|
|
|
n = [a objectAtIndex:[ip indexAtPosition:i]];
|
|
|
|
}
|
2007-03-09 01:16:06 +00:00
|
|
|
|
2006-09-02 16:09:20 +00:00
|
|
|
[paths addObject:[n path]];
|
|
|
|
}
|
|
|
|
|
|
|
|
[pboard declareTypes:[NSArray arrayWithObjects:NSFilenamesPboardType,nil] owner:nil]; //add it to pboard
|
|
|
|
[pboard setPropertyList:paths forType:NSFilenamesPboardType];
|
|
|
|
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
2007-02-18 18:59:23 +00:00
|
|
|
|
|
|
|
// Required Protocol Bullshit (RPB) This is neccessary so it can be used as a datasource for drag/drop things.
|
|
|
|
|
|
|
|
- (id)outlineView:(NSOutlineView *)outlineView child:(int)index ofItem:(id)item
|
|
|
|
{
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item
|
|
|
|
{
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (int)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
- (id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTableColumn *)tableColumn byItem:(id)item
|
|
|
|
{
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
//End of RPB
|
|
|
|
|
|
|
|
|
2007-02-18 17:35:28 +00:00
|
|
|
//For type-select
|
|
|
|
|
|
|
|
- (void)configureTypeSelectTableView:(KFTypeSelectTableView *)tableView
|
|
|
|
{
|
|
|
|
[tableView setSearchWraps:YES];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (int)typeSelectTableViewInitialSearchRow:(id)tableView
|
|
|
|
{
|
|
|
|
return [tableView selectedRow];
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return the string value used for type selection
|
|
|
|
- (NSString *)typeSelectTableView:(KFTypeSelectTableView *)tableView stringValueForTableColumn:(NSTableColumn *)col row:(int)row
|
|
|
|
{
|
|
|
|
id item = [tableView itemAtRow:row];
|
|
|
|
|
|
|
|
//Reaching down into NSTreeController...yikes
|
|
|
|
return [[[item observedObject] path] lastPathComponent];
|
|
|
|
}
|
|
|
|
|
|
|
|
//End type-select
|
2006-09-02 16:09:20 +00:00
|
|
|
|
2007-02-18 18:59:23 +00:00
|
|
|
- (void)addSelectedToPlaylist {
|
2007-03-09 01:16:06 +00:00
|
|
|
NSMutableArray *urls = [[NSMutableArray alloc] init];
|
2007-02-18 18:59:23 +00:00
|
|
|
NSArray *nodes = [self selectedObjects];
|
|
|
|
NSEnumerator *e = [nodes objectEnumerator];
|
|
|
|
|
|
|
|
id n;
|
|
|
|
while (n = [e nextObject]) {
|
2007-03-09 01:16:06 +00:00
|
|
|
NSURL *url = [[NSURL alloc] initFileURLWithPath:[n path]];
|
|
|
|
[urls addObject:url];
|
|
|
|
[url release];
|
2007-02-18 18:59:23 +00:00
|
|
|
}
|
|
|
|
|
2007-03-09 01:16:06 +00:00
|
|
|
NSLog(@"Adding URLs: %@", urls);
|
|
|
|
[playlistLoader addURLs:urls sort:YES];
|
|
|
|
[urls release];
|
2007-02-18 18:59:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-09-02 16:09:20 +00:00
|
|
|
@end
|