From b3c71fef9e88e230e41c8b0dc488411f9f74644b Mon Sep 17 00:00:00 2001 From: Tom Robinson Date: Tue, 6 Jan 2009 17:10:22 +0800 Subject: [PATCH 1/4] Simpler JSON APIs as CPString class/instance methods. Signed-off-by: Tom Robinson --- Foundation/CPString.j | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/Foundation/CPString.j b/Foundation/CPString.j index 3de11401b..da652a73b 100644 --- a/Foundation/CPString.j +++ b/Foundation/CPString.j @@ -23,6 +23,7 @@ @import "CPObject.j" @import "CPException.j" @import "CPSortDescriptor.j" +@import "CPValue.j" /*! @@ -640,4 +641,24 @@ var CPStringHashes = new objj_dictionary(); @end +@implementation CPString (JSON) + +/*! + Returns a string representing the supplied JavaScript object encoded as JSON. +*/ ++ (CPString)encodeJSON:(JSObject)anObject +{ + return CPJSObjectCreateJSON(anObject); +} + +/*! + Returns a JavaScript object decoded from the string's JSON representation. +*/ +- (JSObject)decodeJSON +{ + return CPJSObjectCreateWithJSON(self); +} + +@end + String.prototype.isa = CPString; From 1a56d10bef13929b08132bc81b138b85625cc8ac Mon Sep 17 00:00:00 2001 From: Tom Robinson Date: Wed, 7 Jan 2009 14:40:41 +0800 Subject: [PATCH 2/4] Better JSON method names. Signed-off-by: Tom Robinson --- Foundation/CPString.j | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Foundation/CPString.j b/Foundation/CPString.j index da652a73b..13bc0a889 100644 --- a/Foundation/CPString.j +++ b/Foundation/CPString.j @@ -646,7 +646,7 @@ var CPStringHashes = new objj_dictionary(); /*! Returns a string representing the supplied JavaScript object encoded as JSON. */ -+ (CPString)encodeJSON:(JSObject)anObject ++ (CPString)JSONFromObject:(JSObject)anObject { return CPJSObjectCreateJSON(anObject); } @@ -654,7 +654,7 @@ var CPStringHashes = new objj_dictionary(); /*! Returns a JavaScript object decoded from the string's JSON representation. */ -- (JSObject)decodeJSON +- (JSObject)objectFromJSON { return CPJSObjectCreateWithJSON(self); } From 89476fb54e37e286e5da5aa78e2d5f51721cfe14 Mon Sep 17 00:00:00 2001 From: Francisco Ryan Tolmasky I Date: Tue, 6 Jan 2009 09:20:14 +0800 Subject: [PATCH 3/4] Fix for tags not being encoded/decoded in CPMenuItems. [#132 state:resolved]. Signed-off-by: Tom Robinson --- AppKit/CPMenuItem.j | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/AppKit/CPMenuItem.j b/AppKit/CPMenuItem.j index 995d121bc..a934f7a23 100644 --- a/AppKit/CPMenuItem.j +++ b/AppKit/CPMenuItem.j @@ -92,6 +92,7 @@ _isEnabled = YES; + _tag = 0; _state = CPOffState; _keyEquivalent = aKeyEquivalent || @""; @@ -749,6 +750,8 @@ var CPMenuItemTitleKey = @"CPMenuItemTitleKey", CPMenuItemIsEnabledKey = @"CPMenuItemIsEnabledKey", CPMenuItemIsHiddenKey = @"CPMenuItemIsHiddenKey", + CPMenuItemTagKey = @"CPMenuItemTagKey", + CPMenuItemImageKey = @"CPMenuItemImageKey", CPMenuItemAlternateImageKey = @"CPMenuItemAlternateImageKey", @@ -779,7 +782,8 @@ var CPMenuItemTitleKey = @"CPMenuItemTitleKey", _isEnabled = [aCoder decodeObjectForKey:CPMenuItemIsEnabledKey]; _isHidden = [aCoder decodeObjectForKey:CPMenuItemIsHiddenKey]; -// int _tag; + _tag = [aCoder containsObjectForKey:CPMenuItemTagKey] ? [aCoder objectForKey:CPMenuItemTagKey] : 0; + // int _state; _image = [aCoder decodeObjectForKey:CPMenuItemImageKey]; @@ -823,6 +827,9 @@ var CPMenuItemTitleKey = @"CPMenuItemTitleKey", [aCoder encodeObject:_isEnabled forKey:CPMenuItemIsEnabledKey]; [aCoder encodeObject:_isHidden forKey:CPMenuItemIsHiddenKey]; + if (_tag !== 0) + [aCoder encodeObject:_tag forKey:CPMenuItemTagKey]; + [aCoder encodeObject:_image forKey:CPMenuItemImageKey]; [aCoder encodeObject:_alternateImage forKey:CPMenuItemAlternateImageKey]; From 541b73e322d2002e86a30a12db3c5e864c4a647f Mon Sep 17 00:00:00 2001 From: Francisco Ryan Tolmasky I Date: Tue, 6 Jan 2009 09:26:14 +0800 Subject: [PATCH 4/4] Fixed typos. Signed-off-by: Tom Robinson --- AppKit/CPMenuItem.j | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AppKit/CPMenuItem.j b/AppKit/CPMenuItem.j index a934f7a23..75d52da19 100644 --- a/AppKit/CPMenuItem.j +++ b/AppKit/CPMenuItem.j @@ -782,7 +782,7 @@ var CPMenuItemTitleKey = @"CPMenuItemTitleKey", _isEnabled = [aCoder decodeObjectForKey:CPMenuItemIsEnabledKey]; _isHidden = [aCoder decodeObjectForKey:CPMenuItemIsHiddenKey]; - _tag = [aCoder containsObjectForKey:CPMenuItemTagKey] ? [aCoder objectForKey:CPMenuItemTagKey] : 0; + _tag = [aCoder containsValueForKey:CPMenuItemTagKey] ? [aCoder decodeObjectForKey:CPMenuItemTagKey] : 0; // int _state;