Fixed: attempting to use an unsupported built in image in IB would generate an error, but not explain why.

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 “<name>” is not supported."
This commit is contained in:
Aparajita Fishman committed 2013-08-12 15:18:07 -04:00
1 parent d40449c469
commit d6f1c2bc57
3 files changed
+36 -12

No files matched your search

+19 -6
View File
@@ -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;
+2 -2
View File
@@ -17,11 +17,11 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>3.0.5</string>
<string>3.0.6</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>3.0.5</string>
<string>3.0.6</string>
<key>LSApplicationCategoryType</key>
<string>public.app-category.developer-tools</string>
<key>LSUIElement</key>
+15 -4
View File
@@ -25,10 +25,16 @@
@import <AppKit/_CPCibCustomResource.j>
@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
{