aboutsummaryrefslogtreecommitdiffstats
path: root/Source/SPSplitView.m
diff options
context:
space:
mode:
authorrowanbeentje <rowan@beent.je>2012-08-15 07:50:14 +0000
committerrowanbeentje <rowan@beent.je>2012-08-15 07:50:14 +0000
commitd64a6e48f61486a105314707ce0b4df24f6f8fd4 (patch)
tree91404f241d3e9a0d4e4a3d03431d96846e6fb1ef /Source/SPSplitView.m
parentbd475802f1cea9690bad0a46459fdf8120b51df4 (diff)
downloadsequelpro-d64a6e48f61486a105314707ce0b4df24f6f8fd4.tar.gz
sequelpro-d64a6e48f61486a105314707ce0b4df24f6f8fd4.tar.bz2
sequelpro-d64a6e48f61486a105314707ce0b4df24f6f8fd4.zip
- Tweak SPSplitView to support autosave names, extending the default autosave behaviour which seems to have problems
- Use that to fix the database view splitter/connection view splitter not saving position correctly
Diffstat (limited to 'Source/SPSplitView.m')
-rw-r--r--Source/SPSplitView.m49
1 files changed, 49 insertions, 0 deletions
diff --git a/Source/SPSplitView.m b/Source/SPSplitView.m
index d8b6f8de..49097d41 100644
--- a/Source/SPSplitView.m
+++ b/Source/SPSplitView.m
@@ -38,6 +38,9 @@
- (void)_initCustomProperties;
- (void)_ensureDefaultSubviewSizesToIndex:(NSUInteger)anIndex;
+- (void)_saveAutoSaveSizes;
+- (void)_restoreAutoSaveSizes;
+
- (NSArray *)_suggestedSizesForTargetSize:(CGFloat)targetSize respectingSpringsAndStruts:(BOOL)respectStruts respectingConstraints:(BOOL)respectConstraints;
- (CGFloat)_startPositionOfView:(NSView *)aView;
@@ -96,6 +99,9 @@
[super awakeFromNib];
}
+ // Normal splitview autosave appears to have problems on Lion - handle it ourselves as well.
+ [self _restoreAutoSaveSizes];
+
[collapseToggleButton setState:(collapsibleSubviewCollapsed?NSOnState:NSOffState)];
}
@@ -604,6 +610,8 @@
}
}
+ [self _saveAutoSaveSizes];
+
// Do the same for expansions
if (collapsibleSubviewIndex != NSNotFound && collapsibleSubviewCollapsed) {
if (!animationTimer && [self _lengthOfView:[[self subviews] objectAtIndex:collapsibleSubviewIndex]]) {
@@ -713,6 +721,47 @@
#pragma mark -
/**
+ * Save the current dimensions of each subview if there is an autosaveName set on
+ * the splitview. This seems to be required on Lion (or when certain versions of
+ * Xcode build?) where the normal autosave behaviour overwrites itself with the
+ * original startup position, possibly due to a race condition.
+ */
+- (void)_saveAutoSaveSizes
+{
+ if (![self autosaveName]) {
+ return;
+ }
+
+ NSMutableArray *viewDetails = [NSMutableArray arrayWithCapacity:[[self subviews] count]];
+ for (NSView *eachView in [self subviews]) {
+ [viewDetails addObject:[NSNumber numberWithFloat:[self _lengthOfView:eachView]]];
+ }
+ [[NSUserDefaults standardUserDefaults] setObject:viewDetails forKey:[NSString stringWithFormat:@"SPSplitView Lengths %@", [self autosaveName]]];
+}
+
+/**
+ * Restore the current dimensions of each subview if there is an autosaveName and
+ * if there is a saved position; see _saveAutoSaveSizes.
+ */
+- (void)_restoreAutoSaveSizes
+{
+ if (![self autosaveName]) {
+ return;
+ }
+
+ NSArray *viewDetails = [[NSUserDefaults standardUserDefaults] objectForKey:[NSString stringWithFormat:@"SPSplitView Lengths %@", [self autosaveName]]];
+ if (!viewDetails) {
+ return;
+ }
+
+ for (NSUInteger i = 0; i < [[self subviews] count] - 1; i++) {
+ [self setPosition:[[viewDetails objectAtIndex:i] floatValue] ofDividerAtIndex:i];
+ }
+}
+
+#pragma mark -
+
+/**
* Generate an array of suggested view lengths along the split view lengthwise axis,
* respecting spring/strut or min/max size constraints as appropriate.
* If the supplied constraints cannot be respected, returns nil.