diff --git a/Application/AppController.h b/Application/AppController.h index 0193e8ead..14675ad30 100644 --- a/Application/AppController.h +++ b/Application/AppController.h @@ -2,6 +2,7 @@ #import +@class FileTreeViewController; @class PlaybackController; @class PlaylistController; @class PlaylistView; @@ -18,6 +19,7 @@ IBOutlet NSWindow *mainWindow; IBOutlet NSWindow *miniWindow; + IBOutlet NSSplitView *mainView; IBOutlet NSSegmentedControl *playbackButtons; IBOutlet NSButton *fileButton; @@ -44,6 +46,8 @@ IBOutlet NSWindowController *spotlightWindowController; + IBOutlet FileTreeViewController *fileTreeViewController; + IBOutlet PreferencesController *preferencesController; NSOperationQueue *queue; // Since we are the app delegate, we take care of the op queue diff --git a/Application/AppController.m b/Application/AppController.m index d15efbd36..c4d6ef244 100644 --- a/Application/AppController.m +++ b/Application/AppController.m @@ -1,7 +1,11 @@ #import "AppController.h" #import "Cog-Swift.h" +#import "FileTreeController.h" +#import "FileTreeOutlineView.h" +#import "FileTreeViewController.h" #import "FontSizetoLineHeightTransformer.h" #import "OpenURLPanel.h" +#import "PathNode.h" #import "PlaybackController.h" #import "PlaylistController.h" #import "PlaylistEntry.h" @@ -238,11 +242,50 @@ static AppController *kAppController = nil; [self setFloatingMiniWindow:[[NSUserDefaults standardUserDefaults] boolForKey:@"floatingMiniWindow"]]; + // We need file tree view to restore its state here + // so attempt to access file tree view controller's root view + // to force it to read nib and create file tree view for us + // + // TODO: there probably is a more elegant way to do all this + // but i'm too stupid/tired to figure it out now + [fileTreeViewController view]; + + FileTreeOutlineView *outlineView = [fileTreeViewController outlineView]; + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(nodeExpanded:) name:NSOutlineViewItemDidExpandNotification object:outlineView]; + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(nodeCollapsed:) name:NSOutlineViewItemDidCollapseNotification object:outlineView]; + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateDockMenu:) name:CogPlaybackDidBeginNotficiation object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateDockMenu:) name:CogPlaybackDidStopNotficiation object:nil]; [self updateDockMenu:nil]; + NSArray *expandedNodesArray = [[NSUserDefaults standardUserDefaults] valueForKey:@"fileTreeViewExpandedNodes"]; + + if(expandedNodesArray) { + expandedNodes = [[NSMutableSet alloc] initWithArray:expandedNodesArray]; + } else { + expandedNodes = [[NSMutableSet alloc] init]; + } + + DLog(@"Nodes to expand: %@", [expandedNodes description]); + + DLog(@"Num of rows: %ld", [outlineView numberOfRows]); + + if(!outlineView) { + DLog(@"outlineView is NULL!"); + } + + [outlineView reloadData]; + + for(NSInteger i = 0; i < [outlineView numberOfRows]; i++) { + PathNode *pn = [outlineView itemAtRow:i]; + NSString *str = [[pn URL] absoluteString]; + + if([expandedNodes containsObject:str]) { + [outlineView expandItem:pn]; + } + } + [self addObserver:self forKeyPath:@"playlistController.currentEntry" options:NSKeyValueObservingOptionInitial | NSKeyValueObservingOptionNew @@ -330,6 +373,20 @@ static AppController *kAppController = nil; } } +- (void)nodeExpanded:(NSNotification *)notification { + PathNode *node = [[notification userInfo] objectForKey:@"NSObject"]; + NSString *url = [[node URL] absoluteString]; + + [expandedNodes addObject:url]; +} + +- (void)nodeCollapsed:(NSNotification *)notification { + PathNode *node = [[notification userInfo] objectForKey:@"NSObject"]; + NSString *url = [[node URL] absoluteString]; + + [expandedNodes removeObject:url]; +} + - (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender { if(playbackController.progressOverall) { [playbackController.progressOverall addObserver:self forKeyPath:@"finished" options:0 context:kAppControllerContext]; @@ -403,6 +460,7 @@ static AppController *kAppController = nil; DLog(@"Saving expanded nodes: %@", [expandedNodes description]); + [[NSUserDefaults standardUserDefaults] setValue:[expandedNodes allObjects] forKey:@"fileTreeViewExpandedNodes"]; // Workaround window not restoring it's size and position. [miniWindow setContentSize:NSMakeSize(miniWindow.frame.size.width, 1)]; [miniWindow saveFrameUsingName:@"Mini Window"]; diff --git a/Base.lproj/FileTree.xib b/Base.lproj/FileTree.xib new file mode 100644 index 000000000..1d132640b --- /dev/null +++ b/Base.lproj/FileTree.xib @@ -0,0 +1,168 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + StringToURLTransformer + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + FontSizetoLineHeightTransformer + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Base.lproj/MainMenu.xib b/Base.lproj/MainMenu.xib index 55167d2e1..32c128138 100644 --- a/Base.lproj/MainMenu.xib +++ b/Base.lproj/MainMenu.xib @@ -24,657 +24,668 @@ - - - - - - - - - + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + + + + + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - + FontSizetoLineHeightTransformer + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - FontSizetoLineHeightTransformer - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + - + @@ -696,7 +707,9 @@ + + @@ -839,6 +852,20 @@ + + + +