From d6f1c2bc5725333b2158ea27f91ebae498831b0b Mon Sep 17 00:00:00 2001 From: Aparajita Fishman Date: Mon, 12 Aug 2013 15:17:48 -0400 Subject: [PATCH] Fixed: attempting to use an unsupported built in image in IB would generate an error, but not explain why. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously, attempting to use an unsupported built in image such as NSActionTemplate would generate an error message that said, "The image “NSActionTemplate” cannot be found." This would lead the user to think that there was something wrong with nib2cib, instead of understanding that only certain built in images are supported (currently NSAddTemplate and NSRemoveTemplate). With this commit, an attempt to use an unsupported built in image (where built in is assumed to be any name that matches /^NS[A-Z][A-Za-z]+$/) results in the error message "The built in image “” is not supported." --- AppKit/Cib/_CPCibCustomResource.j | 25 +++++++++++++++++++------ Tools/XcodeCapp/XcodeCapp/Info.plist | 4 ++-- Tools/nib2cib/NSCustomResource.j | 19 +++++++++++++++---- 3 files changed, 36 insertions(+), 12 deletions(-) diff --git a/AppKit/Cib/_CPCibCustomResource.j b/AppKit/Cib/_CPCibCustomResource.j index 413e888cb..63bb24a4f 100644 --- a/AppKit/Cib/_CPCibCustomResource.j +++ b/AppKit/Cib/_CPCibCustomResource.j @@ -35,7 +35,10 @@ var _CPCibCustomResourceClassNameKey = @"_CPCibCustomResourceClassNameKey", _CPCibCustomResourceResourceNameKey = @"_CPCibCustomResourceResourceNameKey", - _CPCibCustomResourcePropertiesKey = @"_CPCibCustomResourcePropertiesKey"; + _CPCibCustomResourcePropertiesKey = @"_CPCibCustomResourcePropertiesKey", + + _CPCibCustomResourceTemplateImageMap = nil; + @implementation _CPCibCustomResource : CPObject { @@ -45,6 +48,16 @@ var _CPCibCustomResourceClassNameKey = @"_CPCibCustomResourceClassNameKey", CPBundle _bundle; } ++ (void)initialize +{ + if (self !== [_CPCibCustomResource class]) + return; + + _CPCibCustomResourceTemplateImageMap = @{ + "CPAddTemplate": "button-image-plus", + "CPRemoveTemplate": "button-image-minus" + }; +} + (id)imageResourceWithName:(CPString)aResourceName size:(CGSize)aSize { return [[self alloc] initWithClassName:@"CPImage" resourceName:aResourceName properties:@{ @"size": aSize }]; @@ -98,12 +111,12 @@ var _CPCibCustomResourceClassNameKey = @"_CPCibCustomResourceClassNameKey", (![aCoder respondsToSelector:@selector(awakenCustomResources)] || [aCoder awakenCustomResources])) if (_className === @"CPImage") { - if (_resourceName == "CPAddTemplate") - return [[CPTheme defaultTheme] valueForAttributeWithName:@"button-image-plus" forClass:[CPButtonBar class]]; - else if (_resourceName == "CPRemoveTemplate") - return [[CPTheme defaultTheme] valueForAttributeWithName:@"button-image-minus" forClass:[CPButtonBar class]]; + var templateImage = [_CPCibCustomResourceTemplateImageMap objectForKey:_resourceName]; - return [self imageFromCoder:aCoder]; + if (templateImage) + return [[CPTheme defaultTheme] valueForAttributeWithName:templateImage forClass:[CPButtonBar class]]; + else + return [self imageFromCoder:aCoder]; } return self; diff --git a/Tools/XcodeCapp/XcodeCapp/Info.plist b/Tools/XcodeCapp/XcodeCapp/Info.plist index 0467742ec..2ac7f472c 100644 --- a/Tools/XcodeCapp/XcodeCapp/Info.plist +++ b/Tools/XcodeCapp/XcodeCapp/Info.plist @@ -17,11 +17,11 @@ CFBundlePackageType APPL CFBundleShortVersionString - 3.0.5 + 3.0.6 CFBundleSignature ???? CFBundleVersion - 3.0.5 + 3.0.6 LSApplicationCategoryType public.app-category.developer-tools LSUIElement diff --git a/Tools/nib2cib/NSCustomResource.j b/Tools/nib2cib/NSCustomResource.j index 090c3d07e..d97d2a1b9 100644 --- a/Tools/nib2cib/NSCustomResource.j +++ b/Tools/nib2cib/NSCustomResource.j @@ -25,10 +25,16 @@ @import +@import "Nib2CibException.j" + @global CP_NSMapClassName var FILE = require("file"), - imageSize = require("cappuccino/imagesize").imagesize; + imageSize = require("cappuccino/imagesize").imagesize, + supportedTemplateImages = [ + "NSAddTemplate", + "NSRemoveTemplate" + ]; @implementation _CPCibCustomResource (NSCoding) @@ -47,10 +53,15 @@ var FILE = require("file"), if (_resourceName == "NSSwitch") return nil; - else if (_resourceName == "NSAddTemplate" || _resourceName == "NSRemoveTemplate") + else if (/^NS[A-Z][A-Za-z]+$/.test(_resourceName)) { - // Defer resolving this path until runtime. - _resourceName = _resourceName.replace("NS", "CP"); + if (supportedTemplateImages.indexOf(_resourceName) >= 0) + { + // Defer resolving this path until runtime. + _resourceName = _resourceName.replace("NS", "CP"); + } + else + [CPException raise:Nib2CibException format:@"The built in image “%@” is not supported.", _resourceName]; } else {