From cc99469638a22d68a01650bf36adc3b99ae817d1 Mon Sep 17 00:00:00 2001 From: rowanbeentje Date: Thu, 9 Sep 2010 01:29:35 +0000 Subject: - Alter the connection view layout, moving the connection details forms into a scrollview. Switch to centering the form in code, which allows better control and automatic scrollview triggering if the window is too small. - Reduce the minimum window size to 700x400, addressing Issue #788, now the connection view is no longer the constraining factor. --- Source/SPConnectionController.h | 3 ++- Source/SPConnectionController.m | 33 ++++++++++++++++++++++++++++++++- 2 files changed, 34 insertions(+), 2 deletions(-) (limited to 'Source') diff --git a/Source/SPConnectionController.h b/Source/SPConnectionController.h index 0a1f8cce..3aac3054 100644 --- a/Source/SPConnectionController.h +++ b/Source/SPConnectionController.h @@ -94,6 +94,7 @@ IBOutlet NSView *connectionView; IBOutlet NSSplitView *connectionSplitView; + IBOutlet NSScrollView *connectionDetailsScrollView; IBOutlet BWAnchoredButtonBar *connectionSplitViewButtonBar; IBOutlet NSTableView *favoritesTable; @@ -180,6 +181,6 @@ - (id)selectedFavorite; - (IBAction)addFavorite:(id)sender; -- (void)splitViewDidResizeSubviews:(NSNotification *)aNotification; +- (void)scrollViewFrameChanged:(NSNotification *)aNotification; @end diff --git a/Source/SPConnectionController.m b/Source/SPConnectionController.m index a0ee7786..258a0b0f 100644 --- a/Source/SPConnectionController.m +++ b/Source/SPConnectionController.m @@ -102,7 +102,8 @@ [databaseConnectionSuperview addSubview:connectionView]; [connectionSplitView setPosition:[[tableDocument valueForKey:@"dbTablesTableView"] frame].size.width-6 ofDividerAtIndex:0]; [connectionSplitViewButtonBar setSplitViewDelegate:self]; - + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(scrollViewFrameChanged:) name:NSViewFrameDidChangeNotification object:nil]; + // Set up a keychain instance and preferences reference, and create the initial favorites list keychain = [[SPKeychain alloc] init]; prefs = [[NSUserDefaults standardUserDefaults] retain]; @@ -143,6 +144,7 @@ - (void) dealloc { [prefs removeObserver:self forKeyPath:SPFavorites]; + [[NSNotificationCenter defaultCenter] removeObserver:self]; [keychain release]; [prefs release]; @@ -572,6 +574,35 @@ previousType = selectedTabView; } +/** + * As the scrollview resizes, keep the details centered within it if + * the detail frame is larger than the scrollview size; otherwise, pin + * the detail frame to the top of the scrollview. + */ +- (void)scrollViewFrameChanged:(NSNotification *)aNotification +{ + NSRect scrollViewFrame = [connectionDetailsScrollView frame]; + NSRect scrollDocumentFrame = [[connectionDetailsScrollView documentView] frame]; + NSRect connectionDetailsFrame = [connectionResizeContainer frame]; + + // Scroll view is smaller than contents - keep positioned at top. + if (scrollViewFrame.size.height < connectionDetailsFrame.size.height + 10) { + if (connectionDetailsFrame.origin.y != 0) { + connectionDetailsFrame.origin.y = 0; + [connectionResizeContainer setFrame:connectionDetailsFrame]; + scrollDocumentFrame.size.height = connectionDetailsFrame.size.height + 10; + [[connectionDetailsScrollView documentView] setFrame:scrollDocumentFrame]; + } + + // Otherwise, center. + } else { + connectionDetailsFrame.origin.y = (scrollViewFrame.size.height - connectionDetailsFrame.size.height)/3; + [connectionResizeContainer setFrame:connectionDetailsFrame]; + scrollDocumentFrame.size.height = scrollViewFrame.size.height; + [[connectionDetailsScrollView documentView] setFrame:scrollDocumentFrame]; + } +} + /** * When a favorite is selected, and the connection details are edited, deselect the favorite; * this is clearer and also prevents a failed connection from being repopulated with the -- cgit v1.2.3