diff --git a/Application/AppController.h b/Application/AppController.h index 24a681e30..4c1282f8d 100644 --- a/Application/AppController.h +++ b/Application/AppController.h @@ -2,6 +2,7 @@ #import +@class FileTreeViewController; @class PlaybackController; @class PlaylistController; @class PlaylistView; @@ -19,6 +20,7 @@ IBOutlet NSWindow *mainWindow; IBOutlet NSWindow *miniWindow; + IBOutlet NSSplitView *mainView; IBOutlet NSSegmentedControl *playbackButtons; IBOutlet NSButton *fileButton; @@ -47,6 +49,8 @@ IBOutlet SUUpdater *updater; + 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 a16da9cf2..fc5728fe3 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" @@ -245,11 +249,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 @@ -337,6 +380,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]; @@ -410,6 +467,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 eb14fd5fc..cb3fb3af2 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 @@ + + + +