mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-09-04 09:53:41 +00:00
* State * Previously the Converter class needlessly copied a whole bunch of state from the Nib2Cib class, which was not only poor factoring, but made for easy omissions of state when instantiating a new Converter, such as was done in NSNib.j. This commit pushes all state not specific to Converter up to Nib2Cib. This allowed removal of redundant code in NSNib -NS_initWithCoder. * Resources * Previously it was not possible to use custom images that were located in a framework, because only the app's Resources directory was searched. This commit automatically searches all frameworks for Resources directories. When a custom image is specified in Xcode, first the app's Resources directory is searched, then all framework Resource directories. Alternately, the specific framework to use can be specified in Xcode by using the form framework@image. At runtime, the framework is loaded by its identifier (as specified in Info.plist), and if there is no identifier, by searching next to the current AppKit framework. All of this renders the nib2cib -R option completely obsolete, so it was removed from the NibApplication/Jakefile template.
120 lines
3.7 KiB
Plaintext
120 lines
3.7 KiB
Plaintext
/*
|
|
* NSCustomResource.j
|
|
* nib2cib
|
|
*
|
|
* Portions based on NSCustomResource.m (01/08/2009) in Cocotron (http://www.cocotron.org/)
|
|
* Copyright (c) 2006-2007 Christopher J. W. Lloyd
|
|
*
|
|
* Created by Francisco Tolmasky.
|
|
* Copyright 2008, 280 North, Inc.
|
|
*
|
|
* This library is free software; you can redistribute it and/or
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
* License as published by the Free Software Foundation; either
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
*
|
|
* This library is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
* Lesser General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
* License along with this library; if not, write to the Free Software
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
*/
|
|
|
|
@import <AppKit/_CPCibCustomResource.j>
|
|
|
|
@global CP_NSMapClassName
|
|
|
|
var FILE = require("file"),
|
|
imageSize = require("cappuccino/imagesize").imagesize;
|
|
|
|
@implementation _CPCibCustomResource (NSCoding)
|
|
|
|
- (id)NS_initWithCoder:(CPCoder)aCoder
|
|
{
|
|
self = [super init];
|
|
|
|
if (self)
|
|
{
|
|
_className = CP_NSMapClassName([aCoder decodeObjectForKey:@"NSClassName"]);
|
|
_resourceName = [aCoder decodeObjectForKey:@"NSResourceName"];
|
|
|
|
var size = CGSizeMakeZero(),
|
|
framework = @"";
|
|
|
|
if (_resourceName == "NSSwitch")
|
|
return nil;
|
|
else if (_resourceName == "NSAddTemplate" || _resourceName == "NSRemoveTemplate")
|
|
{
|
|
// Defer resolving this path until runtime.
|
|
_resourceName = _resourceName.replace("NS", "CP");
|
|
}
|
|
else
|
|
{
|
|
var match = /^(.+)@(.+)$/.exec(_resourceName),
|
|
framework = @"",
|
|
bundleIdentifier = @"";
|
|
|
|
if (match)
|
|
{
|
|
framework = match[1];
|
|
_resourceName = match[2];
|
|
}
|
|
|
|
var resourceInfo = [aCoder resourceInfoForName:_resourceName inFramework:framework];
|
|
|
|
if (!resourceInfo)
|
|
CPLog.warn("Resource \"" + _resourceName + "\" not found in the Resources directories");
|
|
else
|
|
{
|
|
size = imageSize(FILE.canonical(resourceInfo.path)) || CGSizeMakeZero();
|
|
framework = resourceInfo.framework;
|
|
}
|
|
|
|
// Account for the fact that an extension may have been inferred.
|
|
if (resourceInfo &&
|
|
resourceInfo.path &&
|
|
FILE.extension(resourceInfo.path) !== FILE.extension(_resourceName))
|
|
{
|
|
_resourceName += FILE.extension(resourceInfo.path);
|
|
}
|
|
|
|
CPLog.debug(" Resource: %s\n Framework: %s\n Path: %s\n Size: %d x %d", _resourceName, framework, resourceInfo ? FILE.canonical(resourceInfo.path) : "", size.width, size.height);
|
|
}
|
|
|
|
if (resourceInfo && resourceInfo.path && resourceInfo.framework)
|
|
{
|
|
var frameworkPath = FILE.dirname(FILE.dirname(resourceInfo.path)),
|
|
bundle = [CPBundle bundleWithPath:frameworkPath];
|
|
|
|
[bundle loadWithDelegate:nil];
|
|
bundleIdentifier = [bundle bundleIdentifier] || @"";
|
|
}
|
|
|
|
_properties = @{ @"size":size, @"bundleIdentifier":bundleIdentifier, @"framework":framework };
|
|
}
|
|
|
|
return self;
|
|
}
|
|
|
|
@end
|
|
|
|
|
|
@implementation NSCustomResource : _CPCibCustomResource
|
|
{
|
|
}
|
|
|
|
- (id)initWithCoder:(CPCoder)aCoder
|
|
{
|
|
return [self NS_initWithCoder:aCoder];
|
|
}
|
|
|
|
- (Class)classForKeyedArchiver
|
|
{
|
|
return [_CPCibCustomResource class];
|
|
}
|
|
|
|
@end
|