From d64a6e48f61486a105314707ce0b4df24f6f8fd4 Mon Sep 17 00:00:00 2001 From: rowanbeentje Date: Wed, 15 Aug 2012 07:50:14 +0000 Subject: - 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 --- Source/SPSplitView.m | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) (limited to 'Source') 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]]) { @@ -712,6 +720,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. -- cgit v1.2.3