From 288ec78c3e7a20f8d2665c3da1788eff3567f87e Mon Sep 17 00:00:00 2001 From: Alexander Ljungberg Date: Sat, 26 May 2012 00:04:12 +0100 Subject: [PATCH] Fixed: split view autosave. The fix to prevent incorrect autosaving prevented correct autosaving as well. --- AppKit/CPSplitView.j | 2 +- Tests/AppKit/CPSplitViewTest.j | 42 ++++++++++++++++++++++++++++++++-- 2 files changed, 41 insertions(+), 3 deletions(-) diff --git a/AppKit/CPSplitView.j b/AppKit/CPSplitView.j index 35058b37a..02b1e06f9 100644 --- a/AppKit/CPSplitView.j +++ b/AppKit/CPSplitView.j @@ -1065,7 +1065,7 @@ The sum of the views and the sum of the dividers should be equal to the size of */ - (void)_autosave { - if (!_shouldAutosave || !autosaveName) + if (!_shouldAutosave || !_autosaveName) return; var userDefaults = [CPUserDefaults standardUserDefaults], diff --git a/Tests/AppKit/CPSplitViewTest.j b/Tests/AppKit/CPSplitViewTest.j index bb05b417e..04a99b9be 100644 --- a/Tests/AppKit/CPSplitViewTest.j +++ b/Tests/AppKit/CPSplitViewTest.j @@ -111,11 +111,27 @@ { // Verify that the split view does not attempt to auto save without an auto save name. + // This storage class will cause a crash if a save is attempted. [[CPUserDefaults standardUserDefaults] setPersistentStoreClass:CPUserDefaultsFailingStore forDomain:CPApplicationDomain reloadData:NO]; - [splitView setPosition:50 ofDividerAtIndex:0]; - [[CPRunLoop currentRunLoop] limitDateForMode:CPDefaultRunLoopMode]; + + // Now test that it does work normally. + [[CPUserDefaults standardUserDefaults] setPersistentStoreClass:CPUserDefaultsTestStore forDomain:CPApplicationDomain reloadData:NO]; + [splitView setAutosaveName:@"Charles"]; + [splitView setPosition:25 ofDividerAtIndex:0]; + [[CPRunLoop currentRunLoop] limitDateForMode:CPDefaultRunLoopMode]; + + // Recreate the split view. + [self setUp]; + [splitView setAutosaveName:@"Charles"]; + // FIXME At the moment restore from autosave only happens if the split view is loaded from a + // coder. It seems like it should happen when initialising in code too, but some research of + // Cocoa's behaviour will need to be done first. + splitView._needsRestoreFromAutosave = YES; + // Trigger autosave restore. + [splitView setFrameSize:CGSizeMake(110, 100)]; + [self assert:25 equals:[viewA frameSize].height message:@"divider position restored"]; } @end @@ -131,6 +147,7 @@ } @end + /*! This store always fails. */ @@ -149,3 +166,24 @@ } @end + +/*! + This is a temporary store. +*/ +@implementation CPUserDefaultsTestStore : CPUserDefaultsStore +{ + CPData _data; +} + +- (CPData)data +{ + return _data; +} + +- (void)setData:(CPData)aData +{ + _data = aData; +} + +@end +