From e686fbc0a884555fac02fb886723d7145bc2fb0c Mon Sep 17 00:00:00 2001 From: Martin Carlberg Date: Fri, 1 Mar 2013 10:50:00 +0100 Subject: [PATCH] Fixed: Handle deprecated setObject:forKey: calls with nil object on CPDictionary --- AppKit/CPMenu/CPMenu.j | 21 ++++++++++++++------- AppKit/CPSplitView.j | 10 ++++++++-- Foundation/CPUserDefaults.j | 5 ++++- 3 files changed, 26 insertions(+), 10 deletions(-) diff --git a/AppKit/CPMenu/CPMenu.j b/AppKit/CPMenu/CPMenu.j index 8c00006d9..26ae6da2b 100644 --- a/AppKit/CPMenu/CPMenu.j +++ b/AppKit/CPMenu/CPMenu.j @@ -148,6 +148,13 @@ var _CPMenuBarVisible = NO, return _CPMenuBarImage; } ++ (void)_setOrRemoveMenuBarAttribute:(id)aValue forKey:(id)aKey +{ + if (aValue === nil) + [_CPMenuBarAttributes removeObjectForKey:aKey]; + else + [_CPMenuBarAttributes setObject:aValue forKey:aKey]; +} + (void)setMenuBarAttributes:(CPDictionary)attributes { @@ -172,8 +179,8 @@ var _CPMenuBarVisible = NO, else if (!textColor && !titleColor) { - [_CPMenuBarAttributes setObject:[[CPTheme defaultTheme] valueForAttributeWithName:@"menu-bar-text-color" forClass:_CPMenuView] forKey:@"CPMenuBarTextColor"]; - [_CPMenuBarAttributes setObject:[[CPTheme defaultTheme] valueForAttributeWithName:@"menu-bar-title-color" forClass:_CPMenuView] forKey:@"CPMenuBarTitleColor"]; + [self _setOrRemoveMenuBarAttribute:[[CPTheme defaultTheme] valueForAttributeWithName:@"menu-bar-text-color" forClass:_CPMenuView] forKey:@"CPMenuBarTextColor"]; + [self _setOrRemoveMenuBarAttribute:[[CPTheme defaultTheme] valueForAttributeWithName:@"menu-bar-title-color" forClass:_CPMenuView] forKey:@"CPMenuBarTitleColor"]; } if (!textShadowColor && titleShadowColor) @@ -184,18 +191,18 @@ var _CPMenuBarVisible = NO, else if (!textShadowColor && !titleShadowColor) { - [_CPMenuBarAttributes setObject:[[CPTheme defaultTheme] valueForAttributeWithName:@"menu-bar-text-shadow-color" forClass:_CPMenuView] forKey:@"CPMenuBarTextShadowColor"]; - [_CPMenuBarAttributes setObject:[[CPTheme defaultTheme] valueForAttributeWithName:@"menu-bar-title-shadow-color" forClass:_CPMenuView] forKey:@"CPMenuBarTitleShadowColor"]; + [self _setOrRemoveMenuBarAttribute:[[CPTheme defaultTheme] valueForAttributeWithName:@"menu-bar-text-shadow-color" forClass:_CPMenuView] forKey:@"CPMenuBarTextShadowColor"]; + [self _setOrRemoveMenuBarAttribute:[[CPTheme defaultTheme] valueForAttributeWithName:@"menu-bar-title-shadow-color" forClass:_CPMenuView] forKey:@"CPMenuBarTitleShadowColor"]; } if (!highlightColor) - [_CPMenuBarAttributes setObject:[[CPTheme defaultTheme] valueForAttributeWithName:@"menu-bar-highlight-color" forClass:_CPMenuView] forKey:@"CPMenuBarHighlightColor"]; + [self _setOrRemoveMenuBarAttribute:[[CPTheme defaultTheme] valueForAttributeWithName:@"menu-bar-highlight-color" forClass:_CPMenuView] forKey:@"CPMenuBarHighlightColor"]; if (!highlightTextColor) - [_CPMenuBarAttributes setObject:[[CPTheme defaultTheme] valueForAttributeWithName:@"menu-bar-highlight-text-color" forClass:_CPMenuView] forKey:@"CPMenuBarHighlightTextColor"]; + [self _setOrRemoveMenuBarAttribute:[[CPTheme defaultTheme] valueForAttributeWithName:@"menu-bar-highlight-text-color" forClass:_CPMenuView] forKey:@"CPMenuBarHighlightTextColor"]; if (!highlightTextShadowColor) - [_CPMenuBarAttributes setObject:[[CPTheme defaultTheme] valueForAttributeWithName:@"menu-bar-highlight-text-shadow-color" forClass:_CPMenuView] forKey:@"CPMenuBarHighlightTextShadowColor"]; + [self _setOrRemoveMenuBarAttribute:[[CPTheme defaultTheme] valueForAttributeWithName:@"menu-bar-highlight-text-shadow-color" forClass:_CPMenuView] forKey:@"CPMenuBarHighlightTextShadowColor"]; if (_CPMenuBarSharedWindow) { diff --git a/AppKit/CPSplitView.j b/AppKit/CPSplitView.j index 3aedfa2e7..53b90ee1d 100644 --- a/AppKit/CPSplitView.j +++ b/AppKit/CPSplitView.j @@ -1156,8 +1156,14 @@ The sum of the views and the sum of the dividers should be equal to the size of { _preCollapsePositions = [CPMutableDictionary new]; - for (var i = 0, count = [preCollapseArray count]; i < count; i++) - [_preCollapsePositions setObject:preCollapseArray[i] forKey:i + ""]; + for (var i = 0, count = [preCollapseArray count]; i < count; i++) { + var item = preCollapseArray[i]; + + if (item === nil) + [_preCollapsePositions removeObjectForKey:i + ""]; + else + [_preCollapsePositions setObject:item forKey:i + ""]; + } } } diff --git a/Foundation/CPUserDefaults.j b/Foundation/CPUserDefaults.j index 967ae83a7..205330d35 100644 --- a/Foundation/CPUserDefaults.j +++ b/Foundation/CPUserDefaults.j @@ -342,7 +342,10 @@ var StandardUserDefaults; var data = [[self persistentStoreForDomain:aDomain] data], domain = data ? [CPKeyedUnarchiver unarchiveObjectWithData:data] : nil; - [_domains setObject:domain forKey:aDomain]; + if (domain === nil) + [_domains removeObjectForKey:aDomain]; + else + [_domains setObject:domain forKey:aDomain]; _searchListNeedsReload = YES; }