diff options
Diffstat (limited to 'Source')
-rw-r--r-- | Source/SPConnectionController.h | 3 | ||||
-rw-r--r-- | Source/SPConnectionController.m | 33 |
2 files changed, 34 insertions, 2 deletions
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]; @@ -573,6 +575,35 @@ } /** + * 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 * favorite's details instead of the last used details. |