mamburu: Expandedness state of file drawer is now persisted over app restarts

CQTexperiment
Chris Moeller 2013-10-11 03:03:23 -07:00
parent 0ad3106355
commit 3f35b5e07f
6 changed files with 234 additions and 1214 deletions

View File

@ -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

View File

@ -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 <CogAudio/Status.h>
@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

File diff suppressed because it is too large Load Diff

View File

@ -82,7 +82,7 @@
<color key="textColor" name="headerTextColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="headerColor" catalog="System" colorSpace="catalog"/>
</tableHeaderCell>
<imageCell key="dataCell" controlSize="small" refusesFirstResponder="YES" alignment="left" imageScaling="proportionallyDown" image="139EAE20-7EF7-4D8B-B72A-E18459698F54" id="1801">
<imageCell key="dataCell" controlSize="small" refusesFirstResponder="YES" alignment="left" imageScaling="proportionallyDown" image="9E1EC36B-776F-41F6-84BA-3BCF9937C65D" id="1801">
<font key="font" metaFont="system"/>
</imageCell>
<tableColumnResizingMask key="resizingMask" resizeWithTable="YES" userResizable="YES"/>
@ -1365,6 +1365,7 @@ Gw
<connections>
<outlet property="currentEntryController" destination="1897" id="49h-Dv-ved"/>
<outlet property="fileButton" destination="1631" id="1661"/>
<outlet property="fileTreeViewController" destination="2172" id="4Zw-gB-Lmo"/>
<outlet property="infoButton" destination="1627" id="1663"/>
<outlet property="mainView" destination="2123" id="1rG-oa-1Yy"/>
<outlet property="mainWindow" destination="21" id="359"/>
@ -1650,7 +1651,7 @@ Gw
<customObject id="2434" customClass="FeedbackController"/>
</objects>
<resources>
<image name="139EAE20-7EF7-4D8B-B72A-E18459698F54" width="17" height="17">
<image name="9E1EC36B-776F-41F6-84BA-3BCF9937C65D" width="17" height="17">
<mutableData key="keyedArchiveRepresentation">
YnBsaXN0MDDUAQIDBAUGRkdYJHZlcnNpb25YJG9iamVjdHNZJGFyY2hpdmVyVCR0b3ASAAGGoK8QDwcI
ExQZHh8qKyw0NzpAQ1UkbnVsbNUJCgsMDQ4PEBESVk5TU2l6ZVYkY2xhc3NcTlNJbWFnZUZsYWdzVk5T

View File

@ -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

View File

@ -32,4 +32,9 @@
[playbackController playPauseResume:id];
}
- (FileTreeOutlineView*)outlineView
{
return fileTreeOutlineView;
}
@end