From 2606a20020ca3fe2e4c54208080e830186b43287 Mon Sep 17 00:00:00 2001 From: vspader Date: Sat, 21 Jun 2008 19:54:01 +0000 Subject: [PATCH] Updated SideView, split into SideBar and SideWindow. --- Cog.xcodeproj/project.pbxproj | 16 +- English.lproj/MainMenu.xib | 218 ++++++++++++++++++-------- SideView/SideBarController.h | 34 +++++ SideView/SideBarController.m | 261 ++++++++++++++++++++++++++++++++ SideView/SideView.m | 4 +- SideView/SideViewController.h | 20 +-- SideView/SideViewController.m | 221 +-------------------------- SideView/SideWindowController.h | 17 +++ SideView/SideWindowController.m | 54 +++++++ 9 files changed, 545 insertions(+), 300 deletions(-) create mode 100644 SideView/SideBarController.h create mode 100644 SideView/SideBarController.m create mode 100644 SideView/SideWindowController.h create mode 100644 SideView/SideWindowController.m diff --git a/Cog.xcodeproj/project.pbxproj b/Cog.xcodeproj/project.pbxproj index 10cca8af7..68930e41a 100644 --- a/Cog.xcodeproj/project.pbxproj +++ b/Cog.xcodeproj/project.pbxproj @@ -21,6 +21,8 @@ 17342A9A0D5FD20B00E8D854 /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = 17342A980D5FD20B00E8D854 /* MainMenu.xib */; }; 17342ABF0D5FD36400E8D854 /* OpenURLPanel.xib in Resources */ = {isa = PBXBuildFile; fileRef = 17342ABD0D5FD36400E8D854 /* OpenURLPanel.xib */; }; 173855FF0E0CC81F00488CD4 /* FileTreeOutlineView.m in Sources */ = {isa = PBXBuildFile; fileRef = 173855FE0E0CC81F00488CD4 /* FileTreeOutlineView.m */; }; + 1738589B0E0D92DD00488CD4 /* SideBarController.m in Sources */ = {isa = PBXBuildFile; fileRef = 173858950E0D92DD00488CD4 /* SideBarController.m */; }; + 1738589D0E0D92DD00488CD4 /* SideWindowController.m in Sources */ = {isa = PBXBuildFile; fileRef = 173858990E0D92DD00488CD4 /* SideWindowController.m */; }; 1755E1F90BA0D2B600CA3560 /* PlaylistLoader.m in Sources */ = {isa = PBXBuildFile; fileRef = 1755E1F70BA0D2B600CA3560 /* PlaylistLoader.m */; }; 1766C6930B911DF1004A7AE4 /* AudioScrobbler.m in Sources */ = {isa = PBXBuildFile; fileRef = 1766C68F0B911DF1004A7AE4 /* AudioScrobbler.m */; }; 1766C6950B911DF1004A7AE4 /* AudioScrobblerClient.m in Sources */ = {isa = PBXBuildFile; fileRef = 1766C6910B911DF1004A7AE4 /* AudioScrobblerClient.m */; }; @@ -506,6 +508,10 @@ 17342ABE0D5FD36400E8D854 /* English */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = English; path = English.lproj/OpenURLPanel.xib; sourceTree = ""; }; 173855FD0E0CC81F00488CD4 /* FileTreeOutlineView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = FileTreeOutlineView.h; path = FileTree/FileTreeOutlineView.h; sourceTree = ""; }; 173855FE0E0CC81F00488CD4 /* FileTreeOutlineView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = FileTreeOutlineView.m; path = FileTree/FileTreeOutlineView.m; sourceTree = ""; }; + 173858940E0D92DD00488CD4 /* SideBarController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SideBarController.h; path = SideView/SideBarController.h; sourceTree = ""; }; + 173858950E0D92DD00488CD4 /* SideBarController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SideBarController.m; path = SideView/SideBarController.m; sourceTree = ""; }; + 173858980E0D92DD00488CD4 /* SideWindowController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SideWindowController.h; path = SideView/SideWindowController.h; sourceTree = ""; }; + 173858990E0D92DD00488CD4 /* SideWindowController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SideWindowController.m; path = SideView/SideWindowController.m; sourceTree = ""; }; 1755E1F60BA0D2B600CA3560 /* PlaylistLoader.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = PlaylistLoader.h; sourceTree = ""; }; 1755E1F70BA0D2B600CA3560 /* PlaylistLoader.m */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.objc; path = PlaylistLoader.m; sourceTree = ""; }; 1766C68E0B911DF1004A7AE4 /* AudioScrobbler.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = AudioScrobbler.h; sourceTree = ""; }; @@ -907,10 +913,14 @@ 179DFCDF0E0C5A130064A77A /* SideView */ = { isa = PBXGroup; children = ( - 179D02EA0E0CB0B00064A77A /* SideView.h */, - 179D02EB0E0CB0B00064A77A /* SideView.m */, + 173858940E0D92DD00488CD4 /* SideBarController.h */, + 173858950E0D92DD00488CD4 /* SideBarController.m */, + 173858980E0D92DD00488CD4 /* SideWindowController.h */, + 173858990E0D92DD00488CD4 /* SideWindowController.m */, 179D02EC0E0CB0B00064A77A /* SideViewController.h */, 179D02ED0E0CB0B00064A77A /* SideViewController.m */, + 179D02EA0E0CB0B00064A77A /* SideView.h */, + 179D02EB0E0CB0B00064A77A /* SideView.m */, ); name = SideView; sourceTree = ""; @@ -1758,6 +1768,8 @@ 179D03270E0CB2500064A77A /* PathWatcher.m in Sources */, 179D03280E0CB2500064A77A /* SmartFolderNode.m in Sources */, 173855FF0E0CC81F00488CD4 /* FileTreeOutlineView.m in Sources */, + 1738589B0E0D92DD00488CD4 /* SideBarController.m in Sources */, + 1738589D0E0D92DD00488CD4 /* SideWindowController.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/English.lproj/MainMenu.xib b/English.lproj/MainMenu.xib index 9ce2b75c0..ba49e4b49 100644 --- a/English.lproj/MainMenu.xib +++ b/English.lproj/MainMenu.xib @@ -8,12 +8,12 @@ 352.00 YES - - - - + + + + YES @@ -1694,23 +1694,38 @@ ZSwgSW5jLiwgMjAwOAA - Side View + Sidebar 2147483647 submenuAction: - Side View + Sidebar YES YES + + + Window + + 2147483647 + + + submenuAction: + + Window + + YES + + + - Toggle Orientation + Toggle Sidebar Orientation 2147483647 @@ -1718,7 +1733,7 @@ ZSwgSW5jLiwgMjAwOAA - Show/Hide Side View + Show/Hide Sidebar d 1048576 2147483647 @@ -1735,6 +1750,16 @@ ZSwgSW5jLiwgMjAwOAA + + + YES + YES + + + 2147483647 + + + Hide Playlist @@ -3333,8 +3358,11 @@ ZSwgSW5jLiwgMjAwOAA YES - - SideViewController + + SideBarController + + + SideWindowController @@ -5890,59 +5918,67 @@ ZSwgSW5jLiwgMjAwOAA - splitView - - + sideViewMenu + + - 2153 + 2174 sideViewMenu - + - 2159 + 2175 toggleVertical: - + - 2161 - - - - playlistView - - - - 2163 - - - - delegate - - - - 2164 + 2176 - toggleSideView: - + toggleSideBar: + - 2166 + 2177 playlistLoader - + - 2167 + 2178 + + + + playlistLoader + + + + 2179 + + + + playlistView + + + + 2180 + + + + splitView + + + + 2181 @@ -7453,6 +7489,8 @@ ZSwgSW5jLiwgMjAwOAA + + @@ -7807,11 +7845,6 @@ ZSwgSW5jLiwgMjAwOAA - - 2151 - - - 1853 @@ -7854,6 +7887,38 @@ ZSwgSW5jLiwgMjAwOAA + + 2168 + + + + + 2169 + + + YES + + + + + + 2170 + + + YES + + + + + 2172 + + + + + 2173 + + + @@ -8207,13 +8272,18 @@ ZSwgSW5jLiwgMjAwOAA 21.editorWindowContentRectSynchronizationRect 21.windowTemplate.hasMaxSize 21.windowTemplate.maxSize - 2151.IBPluginDependency 2155.IBPluginDependency 2156.IBPluginDependency 2157.IBEditorWindowLastContentRect 2157.IBPluginDependency 2160.IBPluginDependency 2165.IBPluginDependency + 2168.IBPluginDependency + 2169.IBPluginDependency + 2170.IBEditorWindowLastContentRect + 2170.IBPluginDependency + 2172.IBPluginDependency + 2173.IBPluginDependency 218.CustomClassName 218.IBPluginDependency 218.ImportedFromIB2 @@ -8677,7 +8747,7 @@ ZSwgSW5jLiwgMjAwOAA com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - {{342, 763}, {237, 213}} + {{342, 733}, {277, 243}} com.apple.InterfaceBuilder.CocoaPlugin {{257, 573}, {237, 163}} com.apple.InterfaceBuilder.CocoaPlugin @@ -8729,9 +8799,9 @@ ZSwgSW5jLiwgMjAwOAA com.apple.InterfaceBuilder.CocoaPlugin - {{218, 272}, {691, 397}} + {{347, 268}, {691, 397}} com.apple.InterfaceBuilder.CocoaPlugin - {{218, 272}, {691, 397}} + {{347, 268}, {691, 397}} {{25, 14}, {683, 396}} @@ -8739,8 +8809,13 @@ ZSwgSW5jLiwgMjAwOAA {3.40282e+38, 3.40282e+38} com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin + {{619, 920}, {64, 6}} com.apple.InterfaceBuilder.CocoaPlugin - {{579, 920}, {64, 6}} + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + {{619, 900}, {64, 6}} com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin @@ -8939,7 +9014,7 @@ ZSwgSW5jLiwgMjAwOAA - 2167 + 2181 @@ -9513,43 +9588,66 @@ ZSwgSW5jLiwgMjAwOAA - SideViewController - NSObject + SideBarController + SideController YES YES - selectSideView: - toggleSideView: + toggleSideBar: toggleVertical: YES id id - id YES YES - playlistLoader playlistView - sideViewMenu splitView YES - PlaylistLoader NSView - NSMenu NSSplitView IBProjectSource - SideView/SideViewController.h + SideBarController.h + + + + SideController + NSObject + + YES + + YES + playlistLoader + sideViewMenu + + + YES + PlaylistLoader + NSMenu + + + + IBProjectSource + SideView/SideController.h + + + + SideWindowController + SideController + + IBProjectSource + SideWindowController.h diff --git a/SideView/SideBarController.h b/SideView/SideBarController.h new file mode 100644 index 000000000..216e96fd4 --- /dev/null +++ b/SideView/SideBarController.h @@ -0,0 +1,34 @@ +// +// SideBarController.h +// Cog +// +// Created by Vincent Spader on 6/21/08. +// Copyright 2008 __MyCompanyName__. All rights reserved. +// + +#import + +#import "SideViewController.h" + +@class SideView; + +@interface SideBarController : SideViewController { + IBOutlet NSSplitView *splitView; + IBOutlet NSView *playlistView; + SideView *sideView; +} + +- (IBAction)toggleSideBar:(id)sender; +- (IBAction)toggleVertical:(id)sender; + +- (void)showSideBar; +- (void)hideSideBar; +- (BOOL)sideBarIsHidden; + +- (void)setDividerPosition:(float)position; +- (float)dividerPosition; + +- (SideView *)sideView; +- (void)setSideView:(SideView *)sideView; + +@end diff --git a/SideView/SideBarController.m b/SideView/SideBarController.m new file mode 100644 index 000000000..3c7834c22 --- /dev/null +++ b/SideView/SideBarController.m @@ -0,0 +1,261 @@ +// +// SplitViewController.m +// Cog +// +// Created by Vincent Spader on 6/20/08. +// Copyright 2008 __MyCompanyName__. All rights reserved. +// + +#import "SideBarController.h" + +#import "SideView.h" + +@implementation SideBarController + ++ (void)initialize +{ + NSMutableDictionary *userDefaultsValuesDict = [NSMutableDictionary dictionary]; + + [userDefaultsValuesDict setObject:[NSNumber numberWithBool:YES] forKey:@"sideBarVertical"]; + [userDefaultsValuesDict setObject:[NSNumber numberWithBool:NO] forKey:@"showSideBar"]; + [userDefaultsValuesDict setObject:[NSNumber numberWithFloat:100.0] forKey:@"sideBarDividerPosition"]; + [userDefaultsValuesDict setObject:@"File Tree" forKey:@"lastSideBar"]; + + [[NSUserDefaults standardUserDefaults] registerDefaults:userDefaultsValuesDict]; +} + + +- (id)init +{ + self = [super init]; + if (self) + { + [sideViewNibs setObject:@"FileTree" forKey:@"File Tree"]; + [sideViewNibs setObject:@"FileTree" forKey:@"Another File Tree!"]; + + sideView = nil; + } + + return self; +} + +- (void)dealloc +{ + [sideView release]; + + [super dealloc]; +} + +- (void)awakeFromNib +{ + [super awakeFromNib]; + + if ([[NSUserDefaults standardUserDefaults] boolForKey:@"showSideBar"]) + { + [self showSideBar]; + } + + if (![[NSUserDefaults standardUserDefaults] boolForKey:@"sideBarVertical"]) + { + [self toggleVertical:self]; + } +} + +- (void)selectSideViewWithTitle:(NSString *)title +{ + SideView *newSideView = [self sideViewForTitle:title]; + + [[NSUserDefaults standardUserDefaults] setObject:title forKey:@"lastSideBar"]; + + if (newSideView == [self sideView]) + { + [self toggleSideBar:self]; + } + else + { + [self setSideView: newSideView]; + [self showSideBar]; + } + + [splitView adjustSubviews]; +} + +- (IBAction)toggleSideBar:(id)sender +{ + //Show/hide current + if ([self sideBarIsHidden]) + { + [self showSideBar]; + } + else + { + [self hideSideBar]; + } + + [splitView adjustSubviews]; +} + +- (IBAction)toggleVertical:(id)sender +{ + [splitView setVertical:![splitView isVertical]]; + + if (![self sideBarIsHidden]) + { + [self setSideView:[self sideView]]; + [self showSideBar]; + } + + [splitView adjustSubviews]; + + [[NSUserDefaults standardUserDefaults] setBool:[splitView isVertical] forKey:@"sideBarVertical"]; +} + +- (SideView *)sideView +{ + if (sideView == nil) + { + [self setSideView:[self sideViewForTitle:[[NSUserDefaults standardUserDefaults] objectForKey:@"lastSideBar"]]]; + } + + return sideView; +} + +- (void)setSideView:(SideView *)newSideView +{ + [newSideView retain]; + sideView = newSideView; + [sideView release]; +} + +- (void)showSideBar +{ + if ([splitView isVertical]) { + [splitView setSubviews:[NSArray arrayWithObjects:[[self sideView] view], playlistView, nil]]; + } + else { + [splitView setSubviews:[NSArray arrayWithObjects:playlistView, [[self sideView] view], nil]]; + } + + [self setDividerPosition: [[NSUserDefaults standardUserDefaults] floatForKey:@"sideBarDividerPosition"]]; + + [[[sideView view] window] makeFirstResponder:[sideView firstResponder]]; + + [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"showSideBar"]; +} + +- (void)hideSideBar +{ + [splitView setSubviews:[NSArray arrayWithObject:playlistView]]; + [[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"showSideBar"]; + + [[playlistView window] makeFirstResponder:playlistView]; +} + +- (BOOL)sideBarIsHidden +{ + return ([[splitView subviews] count] == 1); +} + +- (BOOL)splitView:(NSSplitView *)aSplitView canCollapseSubview:(NSView *)subview +{ + return (subview != playlistView); +} + + +- (BOOL)splitView:(NSSplitView *)aSplitView shouldCollapseSubview:(NSView *)subview forDoubleClickOnDividerAtIndex:(NSInteger)dividerIndex +{ + return (subview != playlistView); +} + +- (void)splitViewDidResizeSubviews:(NSNotification *)aNotification +{ + //Update default + if (![self sideBarIsHidden]) + { + [[NSUserDefaults standardUserDefaults] setFloat:[self dividerPosition] forKey:@"sideBarDividerPosition"]; + NSLog(@"DIVIDER POSITION: %f", [self dividerPosition]); + } +} + +- (void)splitView:(NSSplitView *)sender resizeSubviewsWithOldSize: (NSSize)oldSize +{ + if ([self sideBarIsHidden]) + { + [splitView adjustSubviews]; + } + else + { + CGFloat dividerThickness = [splitView dividerThickness]; + + NSRect sideRect = [[sideView view] frame]; + NSRect playlistRect = [playlistView frame]; + + NSRect newFrame = [splitView frame]; + + if ([splitView isVertical]) + { + NSLog(@"VERTICAL"); + sideRect.size.width = [[NSUserDefaults standardUserDefaults] floatForKey:@"sideBarDividerPosition"]; + sideRect.size.height = newFrame.size.height; + sideRect.origin = NSMakePoint(0, 0); + + playlistRect.size.width = newFrame.size.width - sideRect.size.width - dividerThickness; + playlistRect.size.height = newFrame.size.height; + playlistRect.origin.x = sideRect.size.width + dividerThickness; + } + else + { + NSLog(@"NOT VERTICAL"); + sideRect.size.height = [[NSUserDefaults standardUserDefaults] floatForKey:@"sideBarDividerPosition"]; + sideRect.size.width = newFrame.size.width; + + playlistRect.origin = NSMakePoint(0, 0); + playlistRect.size.width = newFrame.size.width; + playlistRect.size.height = newFrame.size.height - sideRect.size.height - dividerThickness; + + sideRect.origin.y = playlistRect.size.height + dividerThickness; + } + + + NSLog(@"SIDE: %f,%f %fx%f", sideRect.origin.x, sideRect.origin.y, sideRect.size.width, sideRect.size.height); + NSLog(@"Playlist: %f,%f %fx%f", playlistRect.origin.x, playlistRect.origin.y, playlistRect.size.width, playlistRect.size.height); + + [[sideView view] setFrame:sideRect]; + [playlistView setFrame:playlistRect]; + } +} + +- (float)dividerPosition +{ + if ([splitView isVertical]) + { + return [[sideView view] frame].size.width; + } + + return [[sideView view] frame].size.height; +} + +- (void)setDividerPosition:(float)position +{ + float actualPosition = position; + if (![splitView isVertical]) + { + actualPosition = ([splitView frame].size.height - position); + } + + [splitView adjustSubviews]; + [splitView setPosition:actualPosition ofDividerAtIndex:0]; + + [[NSUserDefaults standardUserDefaults] setFloat:position forKey:@"sideBarDividerPosition"]; + NSLog(@"SETTING POSITION: %f (%f) == %f?", actualPosition, position, [self dividerPosition]); + + NSRect sideRect = [[sideView view] frame]; + NSRect playlistRect = [playlistView frame]; + NSLog(@"SIDE: %f,%f %fx%f", sideRect.origin.x, sideRect.origin.y, sideRect.size.width, sideRect.size.height); + NSLog(@"Playlist: %f,%f %fx%f", playlistRect.origin.x, playlistRect.origin.y, playlistRect.size.width, playlistRect.size.height); +} + + + + +@end diff --git a/SideView/SideView.m b/SideView/SideView.m index 4f7d17500..1054c7b4d 100644 --- a/SideView/SideView.m +++ b/SideView/SideView.m @@ -18,8 +18,7 @@ { controller = c; - BOOL r = [NSBundle loadNibNamed:nibName owner:self]; - NSLog(@"LOADED NIB: %i", r); + [NSBundle loadNibNamed:nibName owner:self]; } return self; @@ -39,4 +38,5 @@ { [controller addToPlaylist:urls]; } + @end diff --git a/SideView/SideViewController.h b/SideView/SideViewController.h index 1a06600b9..a522ddc7d 100644 --- a/SideView/SideViewController.h +++ b/SideView/SideViewController.h @@ -12,33 +12,17 @@ @class PlaylistLoader; @interface SideViewController : NSObject { - IBOutlet NSSplitView *splitView; - IBOutlet NSView *playlistView; IBOutlet NSMenu *sideViewMenu; IBOutlet PlaylistLoader *playlistLoader; NSMutableDictionary *sideViewNibs; NSMutableDictionary *sideViews; - SideView *sideView; } -- (IBAction)toggleVertical:(id)sender; -- (IBAction)selectSideView:(id)sender; -- (IBAction)toggleSideView:(id)sender; - -- (void)showSideView; -- (void)hideSideView; -- (BOOL)sideViewIsHidden; - - - (SideView *)sideViewForTitle:(NSString *)title; - -- (SideView *)sideView; -- (void)setSideView:(SideView *)newSideView; - -- (float)dividerPosition; -- (void)setDividerPosition:(float)position; +- (void)selectSideViewWithTitle:(NSString *)title; //To be overridden by subclass //Helper for adding files to the playlist - (void) addToPlaylist:(NSArray *)urls; + @end diff --git a/SideView/SideViewController.m b/SideView/SideViewController.m index 4e9e263ed..73aae4fdd 100644 --- a/SideView/SideViewController.m +++ b/SideView/SideViewController.m @@ -13,19 +13,6 @@ @implementation SideViewController -+ (void)initialize -{ - NSMutableDictionary *userDefaultsValuesDict = [NSMutableDictionary dictionary]; - - [userDefaultsValuesDict setObject:[NSNumber numberWithBool:YES] forKey:@"sideViewVertical"]; - [userDefaultsValuesDict setObject:[NSNumber numberWithBool:NO] forKey:@"showSideView"]; - [userDefaultsValuesDict setObject:[NSNumber numberWithFloat:100.0] forKey:@"sideViewDividerPosition"]; - [userDefaultsValuesDict setObject:@"File Tree" forKey:@"lastSideViewTitle"]; - - [[NSUserDefaults standardUserDefaults] registerDefaults:userDefaultsValuesDict]; -} - - - (id)init { self = [super init]; @@ -33,8 +20,6 @@ { sideViewNibs = [[NSMutableDictionary alloc] init]; sideViews = [[NSMutableDictionary alloc] init]; - - sideView = nil; } return self; @@ -45,15 +30,11 @@ [sideViews release]; [sideViewNibs release]; - [sideView release]; - [super dealloc]; } - (void)awakeFromNib { - [sideViewNibs setObject:@"FileTree" forKey:@"File Tree"]; - for (NSString *title in sideViewNibs) { //Create menu item @@ -62,19 +43,6 @@ [item setRepresentedObject:title]; [sideViewMenu addItem:item]; } - - - if ([[NSUserDefaults standardUserDefaults] boolForKey:@"showSideView"]) - { - [self showSideView]; - } - - if (![[NSUserDefaults standardUserDefaults] boolForKey:@"sideViewVertical"]) - { - [self toggleVertical:self]; - } - - NSLog(@"TWICE?!"); } - (SideView *)sideViewForTitle:(NSString *)title @@ -89,8 +57,6 @@ [newSideView release]; } - - [[NSUserDefaults standardUserDefaults] setObject:title forKey:@"lastSideViewTitle"]; return newSideView; } @@ -98,194 +64,13 @@ - (IBAction)selectSideView:(id)sender { NSString *title = [sender representedObject]; - SideView *newSideView = [self sideViewForTitle:title]; - if (newSideView == [self sideView]) - { - [self toggleSideView:self]; - } - else - { - [self setSideView: newSideView]; - [self showSideView]; - } - - [splitView adjustSubviews]; + [self selectSideViewWithTitle:title]; } -- (IBAction)toggleSideView:(id)sender +- (void)selectSideViewWithTitle:(NSString *)title { - //Show/hide current - if ([self sideViewIsHidden]) - { - [self showSideView]; - } - else - { - [self hideSideView]; - } - - [splitView adjustSubviews]; -} - -- (IBAction)toggleVertical:(id)sender -{ - [splitView setVertical:![splitView isVertical]]; - - if (![self sideViewIsHidden]) - { - [self setSideView:[self sideView]]; - [self showSideView]; - } - - [splitView adjustSubviews]; - - [[NSUserDefaults standardUserDefaults] setBool:[splitView isVertical] forKey:@"sideViewVertical"]; -} - -- (SideView *)sideView -{ - if (sideView == nil) - { - [self setSideView:[self sideViewForTitle:[[NSUserDefaults standardUserDefaults] objectForKey:@"lastSideViewTitle"]]]; - } - - return sideView; -} - -- (void)setSideView:(SideView *)newSideView -{ - [newSideView retain]; - sideView = newSideView; - [sideView release]; -} - -- (void)showSideView -{ - if ([splitView isVertical]) { - [splitView setSubviews:[NSArray arrayWithObjects:[[self sideView] view], playlistView, nil]]; - } - else { - [splitView setSubviews:[NSArray arrayWithObjects:playlistView, [[self sideView] view], nil]]; - } - - [self setDividerPosition: [[NSUserDefaults standardUserDefaults] floatForKey:@"sideViewDividerPosition"]]; - - [[[sideView view] window] makeFirstResponder:[sideView firstResponder]]; - - [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"showSideView"]; -} - -- (void)hideSideView -{ - [splitView setSubviews:[NSArray arrayWithObject:playlistView]]; - [[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"showSideView"]; - - [[playlistView window] makeFirstResponder:playlistView]; -} - -- (BOOL)sideViewIsHidden -{ - return ([[splitView subviews] count] == 1); -} - -- (BOOL)splitView:(NSSplitView *)aSplitView canCollapseSubview:(NSView *)subview -{ - return (subview != playlistView); -} - - -- (BOOL)splitView:(NSSplitView *)aSplitView shouldCollapseSubview:(NSView *)subview forDoubleClickOnDividerAtIndex:(NSInteger)dividerIndex -{ - return (subview != playlistView); -} - -- (void)splitViewDidResizeSubviews:(NSNotification *)aNotification -{ - //Update default - if (![self sideViewIsHidden]) - { - [[NSUserDefaults standardUserDefaults] setFloat:[self dividerPosition] forKey:@"sideViewDividerPosition"]; - NSLog(@"DIVIDER POSITION: %f", [self dividerPosition]); - } -} - -- (void)splitView:(NSSplitView *)sender resizeSubviewsWithOldSize: (NSSize)oldSize -{ - if ([self sideViewIsHidden]) - { - [splitView adjustSubviews]; - } - else - { - CGFloat dividerThickness = [splitView dividerThickness]; - - NSRect sideRect = [[sideView view] frame]; - NSRect playlistRect = [playlistView frame]; - - NSRect newFrame = [splitView frame]; - - if ([splitView isVertical]) - { - NSLog(@"VERTICAL"); - sideRect.size.width = [[NSUserDefaults standardUserDefaults] floatForKey:@"sideViewDividerPosition"]; - sideRect.size.height = newFrame.size.height; - sideRect.origin = NSMakePoint(0, 0); - - playlistRect.size.width = newFrame.size.width - sideRect.size.width - dividerThickness; - playlistRect.size.height = newFrame.size.height; - playlistRect.origin.x = sideRect.size.width + dividerThickness; - } - else - { - NSLog(@"NOT VERTICAL"); - sideRect.size.height = [[NSUserDefaults standardUserDefaults] floatForKey:@"sideViewDividerPosition"]; - sideRect.size.width = newFrame.size.width; - - playlistRect.origin = NSMakePoint(0, 0); - playlistRect.size.width = newFrame.size.width; - playlistRect.size.height = newFrame.size.height - sideRect.size.height - dividerThickness; - - sideRect.origin.y = playlistRect.size.height + dividerThickness; - } - - - NSLog(@"SIDE: %f,%f %fx%f", sideRect.origin.x, sideRect.origin.y, sideRect.size.width, sideRect.size.height); - NSLog(@"Playlist: %f,%f %fx%f", playlistRect.origin.x, playlistRect.origin.y, playlistRect.size.width, playlistRect.size.height); - - [[sideView view] setFrame:sideRect]; - [playlistView setFrame:playlistRect]; - } -} - -- (float)dividerPosition -{ - if ([splitView isVertical]) - { - return [[sideView view] frame].size.width; - } - - return [[sideView view] frame].size.height; -} - -- (void)setDividerPosition:(float)position -{ - float actualPosition = position; - if (![splitView isVertical]) - { - actualPosition = ([splitView frame].size.height - position); - } - - [splitView adjustSubviews]; - [splitView setPosition:actualPosition ofDividerAtIndex:0]; - - [[NSUserDefaults standardUserDefaults] setFloat:position forKey:@"sideViewDividerPosition"]; - NSLog(@"SETTING POSITION: %f (%f) == %f?", actualPosition, position, [self dividerPosition]); - - NSRect sideRect = [[sideView view] frame]; - NSRect playlistRect = [playlistView frame]; - NSLog(@"SIDE: %f,%f %fx%f", sideRect.origin.x, sideRect.origin.y, sideRect.size.width, sideRect.size.height); - NSLog(@"Playlist: %f,%f %fx%f", playlistRect.origin.x, playlistRect.origin.y, playlistRect.size.width, playlistRect.size.height); + //To be overridden } - (void) addToPlaylist:(NSArray *)urls diff --git a/SideView/SideWindowController.h b/SideView/SideWindowController.h new file mode 100644 index 000000000..c84f4fff0 --- /dev/null +++ b/SideView/SideWindowController.h @@ -0,0 +1,17 @@ +// +// SideWindowController.h +// Cog +// +// Created by Vincent Spader on 6/21/08. +// Copyright 2008 __MyCompanyName__. All rights reserved. +// + +#import + +#import "SideViewController.h" + +@interface SideWindowController : SideViewController { + NSMutableDictionary *windows; +} + +@end diff --git a/SideView/SideWindowController.m b/SideView/SideWindowController.m new file mode 100644 index 000000000..3e877fc05 --- /dev/null +++ b/SideView/SideWindowController.m @@ -0,0 +1,54 @@ +// +// SideWindowController.m +// Cog +// +// Created by Vincent Spader on 6/21/08. +// Copyright 2008 __MyCompanyName__. All rights reserved. +// + +#import "SideWindowController.h" + + +@implementation SideWindowController + +- (id)init +{ + self = [super init]; + if (self) + { + [sideViewNibs setObject:@"FileTree" forKey:@"File Tree In a Window!"]; + [sideViewNibs setObject:@"FileTree" forKey:@"Another File Tree (In a window)!"]; + + windows = [[NSMutableDictionary alloc] init]; + } + + return self; +} + +- (void)dealloc +{ + [windows release]; + + [super dealloc]; +} + +- (void)selectSideViewWithTitle:(NSString *)title +{ + NSPanel *window = [windows objectForKey:title]; + if (window == nil) + { + SideView *newSideView = [self sideViewForTitle:title]; + + NSUInteger styleMask = (NSClosableWindowMask|NSMiniaturizableWindowMask|NSResizableWindowMask|NSTitledWindowMask|NSUtilityWindowMask); + + window = [[NSPanel alloc] initWithContentRect:[[newSideView view] frame] styleMask:styleMask backing:NSBackingStoreBuffered defer:NO]; + [window setContentView:[newSideView view]]; + + [windows setObject:window forKey:title]; + } + + [window makeKeyAndOrderFront:self]; +} + + +@end