From 3f35b5e07f5aa120c853398532ed03949b1c72c0 Mon Sep 17 00:00:00 2001 From: Chris Moeller Date: Fri, 11 Oct 2013 03:03:23 -0700 Subject: [PATCH] mamburu: Expandedness state of file drawer is now persisted over app restarts --- Application/AppController.h | 8 + Application/AppController.m | 70 +- English.lproj/FileTree.xib | 1356 +++-------------------------- English.lproj/MainMenu.xib | 5 +- FileTree/FileTreeViewController.h | 4 + FileTree/FileTreeViewController.m | 5 + 6 files changed, 234 insertions(+), 1214 deletions(-) diff --git a/Application/AppController.h b/Application/AppController.h index 76ef7f598..16b0b779a 100644 --- a/Application/AppController.h +++ b/Application/AppController.h @@ -5,6 +5,7 @@ #import "NDHotKeyEvent.h" #import "NowPlayingBarController.h" +@class FileTreeViewController; @class PlaybackController; @class PlaylistController; @class PlaylistView; @@ -45,6 +46,8 @@ IBOutlet NSMenuItem *showYearColumn; IBOutlet NSWindowController *spotlightWindowController; + + IBOutlet FileTreeViewController *fileTreeViewController; NDHotKeyEvent *playHotKey; NDHotKeyEvent *prevHotKey; @@ -57,6 +60,8 @@ BOOL remoteButtonHeld; /* true as long as the user holds the left,right,plus or minus on the remote control */ NSOperationQueue *queue; // Since we are the app delegate, we take care of the op queue + + NSMutableSet* expandedNodes; } - (IBAction)openURL:(id)sender; @@ -91,4 +96,7 @@ OSStatus handleHotKey(EventHandlerCallRef nextHandler,EventRef theEvent,void *us - (IBAction)decreaseFontSize:(id)sender; - (void)changeFontSize:(float)size; +- (void)nodeExpanded:(NSNotification*)notification; +- (void)nodeCollapsed:(NSNotification*)notification; + @end diff --git a/Application/AppController.m b/Application/AppController.m index ffdd7a010..a226edd81 100644 --- a/Application/AppController.m +++ b/Application/AppController.m @@ -1,4 +1,5 @@ #import "AppController.h" +#import "FileTreeViewController.h" #import "PlaybackController.h" #import "PlaylistController.h" #import "PlaylistView.h" @@ -10,6 +11,7 @@ #import "SpotlightWindowController.h" #import "StringToURLTransformer.h" #import "FontSizetoLineHeightTransformer.h" +#import "PathNode.h" #import @implementation AppController @@ -47,6 +49,7 @@ - (void)dealloc { [queue release]; + [expandedNodes release]; [super dealloc]; } @@ -57,7 +60,7 @@ [remote startListening: self]; } } -- (void)applicationDidResignActive:(NSNotification *)motification +- (void)applicationDidResignActive:(NSNotification *)notification { if ([[NSUserDefaults standardUserDefaults] boolForKey:@"remoteEnabled"] && [[NSUserDefaults standardUserDefaults] boolForKey:@"remoteOnlyOnActive"]) { [remote stopListening: self]; @@ -274,6 +277,67 @@ increase/decrease as long as the user holds the left/right, plus/minus button */ [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(enterFullscreen) name:NSWindowDidEnterFullScreenNotification object:mainWindow]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(exitFullscreen) name:NSWindowDidExitFullScreenNotification object:mainWindow]; + + // 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]; + + NSArray *expandedNodesArray = [[NSUserDefaults standardUserDefaults] valueForKey:@"fileTreeViewExpandedNodes"]; + + if (expandedNodesArray) + { + expandedNodes = [[NSMutableSet alloc] initWithArray:expandedNodesArray]; + } + else + { + expandedNodes = [[NSMutableSet alloc] init]; + } + + NSLog(@"Nodes to expand: %@", [expandedNodes description]); + + NSLog(@"Num of rows: %ld", [outlineView numberOfRows]); + + if (!outlineView) + { + NSLog(@"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]; + } + } +} + +- (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]; } - (void)applicationWillTerminate:(NSNotification *)aNotification @@ -314,6 +378,10 @@ increase/decrease as long as the user holds the left/right, plus/minus button */ NSError *error; [[NSFileManager defaultManager] removeItemAtPath:[folder stringByAppendingPathComponent:fileName] error:&error]; + + NSLog(@"Saving expanded nodes: %@", [expandedNodes description]); + + [[NSUserDefaults standardUserDefaults] setValue:[expandedNodes allObjects] forKey:@"fileTreeViewExpandedNodes"]; } - (BOOL)applicationShouldHandleReopen:(NSApplication *)theApplication hasVisibleWindows:(BOOL)flag diff --git a/English.lproj/FileTree.xib b/English.lproj/FileTree.xib index f416eb02f..555f29871 100644 --- a/English.lproj/FileTree.xib +++ b/English.lproj/FileTree.xib @@ -1,1211 +1,145 @@ - - - - 1050 - 9L30 - 677 - 949.54 - 353.00 - - YES - - - - - YES - com.apple.InterfaceBuilder.CocoaPlugin - - - YES - - YES - - - YES - - - - YES - - FileTreeViewController - - - FirstResponder - - - NSApplication - - - FileTreeDataSource - - - YES - - - PathWatcher - - - - 274 - - YES - - - 274 - - YES - - - 2304 - - YES - - - 4352 - {306, 377} - - YES - - - -2147483392 - {{-26, 0}, {16, 17}} - - - YES - - 3.030000e+02 - 1.600000e+01 - 1.000000e+03 - - 75628032 - 0 - - - LucidaGrande - 1.100000e+01 - 3100 - - - 3 - MC4zMzMzMzI5OQA - - - 6 - System - headerTextColor - - 3 - MAA - - - - - 337772097 - 2048 - Text Cell - - LucidaGrande - 1.300000e+01 - 1044 - - - - 6 - System - controlBackgroundColor - - 3 - MC42NjY2NjY2OQA - - - - 6 - System - controlTextColor - - - - 3 - YES - - - - 3.000000e+00 - - 2 - MC44MzkyMTU3NiAwLjg2NjY2NjczIDAuODk4MDM5MjgAA - - - 6 - System - gridColor - - 3 - MC41AA - - - 2.000000e+01 - 1514143744 - FileTree - 4 - 15 - 0 - YES - 1 - 1.400000e+01 - - - {306, 377} - - - - - 3 - MQA - - 6 - - - - -2147483392 - {{261, 0}, {15, 363}} - - - _doScroller: - 9.973615e-01 - - - - -2147483392 - {{0, 363}, {261, 15}} - - 1 - - _doScroller: - 9.963899e-01 - - - {{1, 0}, {306, 377}} - - - 560 - - - - QSAAAEEgAABBoAAAQaAAAA - - - - 270 - - YES - - YES - Apple URL pasteboard type - NSFilenamesPboardType - - - {{0, 377}, {307, 22}} - - YES - - 337772033 - 163840 - - - - 2 - MC44MzkyMTU3NiAwLjg2NjY2NjczIDAuODk4MDM5MjgAA - - - YES - - 2 - - - - - {307, 399} - - NSView - - - FileTreeController - - - Menu - - YES - - - Add to Playlist - - 1048576 - 2147483647 - - NSImage - NSMenuCheckmark - - - NSImage - NSMenuMixedState - - 1 - - - - Set as Playlist - - 1048576 - 2147483647 - - - 2 - - - - YES - YES - - - 2147483647 - - - - - - Show in Finder - - 1048576 - 2147483647 - - - 3 - - - - YES - YES - - - 2147483647 - - - - - - Set as Root - - 1048576 - 2147483647 - - - 4 - - - - - - - YES - - - delegate - - - - 33 - - - - watcher - - - - 34 - - - - rowHeight: values.fontSize - - - - - - rowHeight: values.fontSize - rowHeight - values.fontSize - - NSValueTransformerName - FontSizetoLineHeightTransformer - - 2 - - - 86 - - - - dataSource - - - - 87 - - - - outlineView - - - - 88 - - - - fontSize: values.fontSize - - - - - - fontSize: values.fontSize - fontSize - values.fontSize - 2 - - - 93 - - - - outlineView - - - - 95 - - - - delegate - - - - 98 - - - - view - - - - 103 - - - - nextKeyView - - - - 104 - - - - firstResponder - - - - 105 - - - - controller - - - - 106 - - - - value: values.fileTreeRootURL - - - - - - value: values.fileTreeRootURL - value - values.fileTreeRootURL - - NSValueTransformerName - StringToURLTransformer - - 2 - - - 108 - - - - pathControl - - - - 109 - - - - menu - - - - 121 - - - - addToPlaylist: - - - - 122 - - - - showEntryInFinder: - - - - 123 - - - - setAsRoot: - - - - 125 - - - - setAsPlaylist: - - - - 130 - - - - dataSource - - - - 137 - - - - delegate - - - - 139 - - - - - YES - - 0 - - YES - - - - - - -2 - - - RmlsZSdzIE93bmVyA - - - -1 - - - First Responder - - - -3 - - - Application - - - 9 - - - FileTreeDataSource - - - 27 - - - - - 31 - - - - - 55 - - - YES - - - - - File Tree View - - - 64 - - - YES - - - - - - - - 65 - - - YES - - - - - - 66 - - - - - 67 - - - - - 68 - - - - - 69 - - - YES - - - - - - 70 - - - YES - - - - - - 71 - - - - - 94 - - - - - 110 - - - YES - - - - - - - - - ContextualMenu - - - 112 - - - - - 119 - - - - - 124 - - - - - 126 - - - - - 128 - - - - - 129 - - - - - - - YES - - YES - -1.IBPluginDependency - -2.IBPluginDependency - -3.IBPluginDependency - 110.IBEditorWindowLastContentRect - 110.IBPluginDependency - 110.ImportedFromIB2 - 110.editorWindowContentRectSynchronizationRect - 112.IBPluginDependency - 112.ImportedFromIB2 - 119.IBPluginDependency - 124.IBPluginDependency - 126.IBPluginDependency - 128.IBPluginDependency - 129.IBPluginDependency - 27.IBPluginDependency - 31.IBPluginDependency - 55.IBEditorWindowLastContentRect - 55.IBPluginDependency - 64.IBPluginDependency - 64.ImportedFromIB2 - 65.IBPluginDependency - 66.IBPluginDependency - 67.IBPluginDependency - 67.ImportedFromIB2 - 68.IBPluginDependency - 68.ImportedFromIB2 - 69.CustomClassName - 69.IBPluginDependency - 69.ImportedFromIB2 - 70.IBPluginDependency - 70.ImportedFromIB2 - 71.CustomClassName - 71.IBPluginDependency - 71.ImportedFromIB2 - 9.IBPluginDependency - 9.ImportedFromIB2 - 94.IBPluginDependency - - - YES - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - {{310, 530}, {169, 103}} - com.apple.InterfaceBuilder.CocoaPlugin - - {{482, 640}, {187, 133}} - com.apple.InterfaceBuilder.CocoaPlugin - - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - {{582, 558}, {307, 399}} - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin - - com.apple.InterfaceBuilder.CocoaPlugin - - FileTreeOutlineView - com.apple.InterfaceBuilder.CocoaPlugin - - com.apple.InterfaceBuilder.CocoaPlugin - - FileIconCell - com.apple.InterfaceBuilder.CocoaPlugin - - com.apple.InterfaceBuilder.CocoaPlugin - - com.apple.InterfaceBuilder.CocoaPlugin - - - - YES - - YES - - - YES - - - - - YES - - YES - - - YES - - - - 139 - - - - YES - - DNDArrayController - NSArrayController - - tableView - NSTableView - - - IBProjectSource - Playlist/DNDArrayController.h - - - - EntriesController - NSObject - - IBProjectSource - Playlist/EntriesController.h - - - - FileIconCell - ImageTextCell - - IBProjectSource - FileTree/FileIconCell.h - - - - FileTreeController - NSObject - - YES - - YES - addToPlaylist: - setAsPlaylist: - setAsRoot: - showEntryInFinder: - - - YES - id - id - id - id - - - - YES - - YES - controller - dataSource - outlineView - - - YES - SideViewController - FileTreeDataSource - NSOutlineView - - - - IBProjectSource - FileTree/FileTreeController.h - - - - FileTreeDataSource - NSObject - - YES - - YES - outlineView - pathControl - watcher - - - YES - NSOutlineView - NSPathControl - PathWatcher - - - - IBProjectSource - FileTree/FileTreeDataSource.h - - - - FileTreeDataSource - NSObject - - IBUserSource - - - - - FileTreeOutlineView - NSOutlineView - - IBProjectSource - FileTree/FileTreeOutlineView.h - - - - FileTreeViewController - SideViewController - - YES - - YES - playbackController - playlistLoader - - - YES - PlaybackController - PlaylistLoader - - - - IBProjectSource - FileTree/FileTreeViewController.h - - - - ImageTextCell - NSTextFieldCell - - IBProjectSource - ThirdParty/ImageTextCell/ImageTextCell.h - - - - NSObject - - IBProjectSource - ThirdParty/AppleRemote/AppleRemote.h - - - - NSObject - - IBProjectSource - ThirdParty/GCWindowMenu/GCOneShotEffectTimer.h - - - - NSObject - - IBProjectSource - ThirdParty/NDHotKeys/NDHotKeyEvent.h - - - - PathWatcher - NSObject - - delegate - id - - - IBProjectSource - FileTree/PathWatcher.h - - - - PlaybackController - NSObject - - YES - - YES - changeVolume: - eventSeekBackward: - eventSeekForward: - fade: - next: - pause: - pauseResume: - play: - playPauseResume: - prev: - resume: - seek: - skipToNextAlbum: - skipToPreviousAlbum: - stop: - volumeDown: - volumeUp: - - - YES - id - id - id - id - id - id - id - id - id - id - id - id - id - id - id - id - id - - - - YES - - YES - outputDevices - playlistController - playlistView - volumeSlider - - - YES - NSArrayController - PlaylistController - PlaylistView - NSSlider - - - - IBProjectSource - Application/PlaybackController.h - - - - PlaylistController - DNDArrayController - - YES - - YES - clear: - clearFilterPredicate: - emptyQueueList: - searchByAlbum: - searchByArtist: - showEntryInFinder: - stopAfterCurrent: - toggleQueued: - toggleRepeat: - toggleShuffle: - - - YES - id - id - id - id - id - id - id - id - id - id - - - - YES - - YES - entriesController - playbackController - playlistLoader - spotlightWindowController - - - YES - EntriesController - PlaybackController - PlaylistLoader - SpotlightWindowController - - - - IBProjectSource - Playlist/PlaylistController.h - - - - PlaylistLoader - NSObject - - clear: - id - - - playlistController - PlaylistController - - - IBProjectSource - Playlist/PlaylistLoader.h - - - - PlaylistView - NSTableView - - YES - - YES - scrollToCurrentEntry: - shufflePlaylist: - sortByPath: - toggleColumn: - - - YES - id - id - id - id - - - - YES - - YES - playbackController - playlistController - - - YES - PlaybackController - PlaylistController - - - - IBProjectSource - Playlist/PlaylistView.h - - - - SideViewController - NSViewController - - YES - - YES - toggleSideView: - toggleVertical: - - - YES - id - id - - - - YES - - YES - firstResponder - mainView - splitView - - - YES - NSView - NSView - NSSplitView - - - - IBProjectSource - Utils/SideViewController.h - - - - SpotlightWindowController - NSWindowController - - YES - - YES - addToPlaylist: - toggleWindow: - - - YES - id - id - - - - YES - - YES - pathControl - playlistController - playlistLoader - searchField - - - YES - NSPathControl - NSArrayController - PlaylistLoader - NSSearchField - - - - IBProjectSource - Spotlight/SpotlightWindowController.h - - - - - 0 - ../Cog.xcodeproj - 3 - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + StringToURLTransformer + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + FontSizetoLineHeightTransformer + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/English.lproj/MainMenu.xib b/English.lproj/MainMenu.xib index 62fa75f36..154348499 100644 --- a/English.lproj/MainMenu.xib +++ b/English.lproj/MainMenu.xib @@ -82,7 +82,7 @@ - + @@ -1365,6 +1365,7 @@ Gw + @@ -1650,7 +1651,7 @@ Gw - + YnBsaXN0MDDUAQIDBAUGRkdYJHZlcnNpb25YJG9iamVjdHNZJGFyY2hpdmVyVCR0b3ASAAGGoK8QDwcI ExQZHh8qKyw0NzpAQ1UkbnVsbNUJCgsMDQ4PEBESVk5TU2l6ZVYkY2xhc3NcTlNJbWFnZUZsYWdzVk5T diff --git a/FileTree/FileTreeViewController.h b/FileTree/FileTreeViewController.h index c7bc651f5..55cd97280 100644 --- a/FileTree/FileTreeViewController.h +++ b/FileTree/FileTreeViewController.h @@ -11,9 +11,13 @@ @class PlaylistLoader; @class PlaybackController; +@class FileTreeOutlineView; @interface FileTreeViewController : SideViewController { IBOutlet PlaylistLoader *playlistLoader; IBOutlet PlaybackController *playbackController; + IBOutlet FileTreeOutlineView *fileTreeOutlineView; } +- (FileTreeOutlineView*)outlineView; + @end diff --git a/FileTree/FileTreeViewController.m b/FileTree/FileTreeViewController.m index 7f60047cb..b9e12f831 100644 --- a/FileTree/FileTreeViewController.m +++ b/FileTree/FileTreeViewController.m @@ -32,4 +32,9 @@ [playbackController playPauseResume:id]; } +- (FileTreeOutlineView*)outlineView +{ + return fileTreeOutlineView; +} + @end