From 099588b7bd69e86663f591f04dc8f0142910ea5d Mon Sep 17 00:00:00 2001 From: Christopher Snowhill Date: Thu, 30 Jun 2022 16:57:51 -0700 Subject: [PATCH] Restore the File Tree, now with a chooser button Revert "Remove the file tree, as Sandbox does not permit" This reverts commit 35400e13208258f6b6cf07e24a621dde0c2bf4a0. This also changes how the File Tree choosing works. Signed-off-by: Christopher Snowhill --- Application/AppController.h | 4 + Application/AppController.m | 58 + Base.lproj/FileTree.xib | 168 +++ Base.lproj/MainMenu.xib | 1335 ++++++++++++----------- Cog.xcodeproj/project.pbxproj | 102 ++ FileTree/ContainedNode.h | 16 + FileTree/ContainedNode.m | 42 + FileTree/ContainerNode.h | 16 + FileTree/ContainerNode.m | 35 + FileTree/DirectoryNode.h | 15 + FileTree/DirectoryNode.m | 40 + FileTree/FileIconCell.h | 15 + FileTree/FileIconCell.m | 23 + FileTree/FileNode.h | 15 + FileTree/FileNode.m | 17 + FileTree/FileTreeController.h | 26 + FileTree/FileTreeController.m | 85 ++ FileTree/FileTreeDataSource.h | 24 + FileTree/FileTreeDataSource.m | 201 ++++ FileTree/FileTreeOutlineView.h | 16 + FileTree/FileTreeOutlineView.m | 66 ++ FileTree/FileTreeViewController.h | 25 + FileTree/FileTreeViewController.m | 64 ++ FileTree/PathNode.h | 43 + FileTree/PathNode.m | 155 +++ FileTree/PathWatcher.h | 30 + FileTree/PathWatcher.m | 84 ++ FileTree/SmartFolderNode.h | 17 + FileTree/SmartFolderNode.m | 90 ++ Preferences/Preferences/PathSuggester.m | 6 + Utils/SideViewController.h | 34 + Utils/SideViewController.m | 183 ++++ en.lproj/FileTree.strings | 21 + en.lproj/MainMenu.strings | 12 + es.lproj/FileTree.strings | 21 + es.lproj/MainMenu.strings | 12 + 36 files changed, 2474 insertions(+), 642 deletions(-) create mode 100644 Base.lproj/FileTree.xib create mode 100644 FileTree/ContainedNode.h create mode 100644 FileTree/ContainedNode.m create mode 100644 FileTree/ContainerNode.h create mode 100644 FileTree/ContainerNode.m create mode 100644 FileTree/DirectoryNode.h create mode 100644 FileTree/DirectoryNode.m create mode 100644 FileTree/FileIconCell.h create mode 100644 FileTree/FileIconCell.m create mode 100644 FileTree/FileNode.h create mode 100644 FileTree/FileNode.m create mode 100644 FileTree/FileTreeController.h create mode 100644 FileTree/FileTreeController.m create mode 100644 FileTree/FileTreeDataSource.h create mode 100644 FileTree/FileTreeDataSource.m create mode 100644 FileTree/FileTreeOutlineView.h create mode 100644 FileTree/FileTreeOutlineView.m create mode 100644 FileTree/FileTreeViewController.h create mode 100644 FileTree/FileTreeViewController.m create mode 100644 FileTree/PathNode.h create mode 100644 FileTree/PathNode.m create mode 100644 FileTree/PathWatcher.h create mode 100644 FileTree/PathWatcher.m create mode 100644 FileTree/SmartFolderNode.h create mode 100644 FileTree/SmartFolderNode.m create mode 100644 Utils/SideViewController.h create mode 100644 Utils/SideViewController.m create mode 100644 en.lproj/FileTree.strings create mode 100644 es.lproj/FileTree.strings 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 @@ + + + +