mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-10-07 01:18:02 +00:00
Added support for custom classes on non-customviews in nib2cib.
Reviewed by me.
This commit is contained in:
1 parent
c7823a92f8
commit
3f27fca518
7 files changed
+135
-8
No files matched your search
@@ -24,6 +24,7 @@
|
||||
@import <Foundation/CPURLConnection.j>
|
||||
@import <Foundation/CPURLRequest.j>
|
||||
|
||||
@import "_CPCibClassSwapper.j"
|
||||
@import "_CPCibCustomObject.j"
|
||||
@import "_CPCibCustomResource.j"
|
||||
@import "_CPCibCustomView.j"
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* _CPCibClassSwapper.j
|
||||
* AppKit
|
||||
*
|
||||
* Created by Francisco Tolmasky.
|
||||
* Copyright 2009, 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 <Foundation/CPObject.j>
|
||||
@import <Foundation/CPString.j>
|
||||
|
||||
|
||||
var _CPCibClassSwapperClassNameKey = @"_CPCibClassSwapperClassNameKey",
|
||||
_CPCibClassSwapperOriginalClassNameKey = @"_CPCibClassSwapperOriginalClassNameKey";
|
||||
|
||||
@implementation _CPCibClassSwapper : CPObject
|
||||
{
|
||||
}
|
||||
|
||||
+ (id)allocWithCoder:(CPCoder)aCoder
|
||||
{
|
||||
var theClassName = [aCoder decodeObjectForKey:_CPCibClassSwapperClassNameKey],
|
||||
theClass = objj_lookUpClass(theClassName);
|
||||
|
||||
if (!theClass)
|
||||
{
|
||||
CPLog.error("Unable to find class " + theClassName + " in cib file.");
|
||||
|
||||
theClassName = [aCoder decodeObjectForKey:_CPCibClassSwapperOriginalClassNameKey];
|
||||
theClass = objj_lookUpClass(theClassName);
|
||||
|
||||
if (!theClass)
|
||||
[CPException raise:CPInvalidArgumentException reason:@"Unable to find class " + theClassName + " in cib file."];
|
||||
}
|
||||
|
||||
return [theClass alloc];
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -426,15 +426,16 @@ var _CPKeyedUnarchiverDecodeObjectAtIndex = function(self, anIndex)
|
||||
if (!theClass)
|
||||
theClass = CPClassFromString(className);
|
||||
|
||||
object = [theClass alloc];
|
||||
|
||||
// It is important to do this before calling initWithCoder so that decoding can be self referential (something = self).
|
||||
self._objects[anIndex] = object;
|
||||
|
||||
var savedPlistObject = self._plistObject;
|
||||
|
||||
self._plistObject = plistObject;
|
||||
var string = className;
|
||||
|
||||
// Should we only call this on _CPCibClassSwapper? (currently the only class that makes use of this).
|
||||
object = [theClass allocWithCoder:self];
|
||||
|
||||
// It is important to do this before calling initWithCoder so that decoding can be self referential (something = self).
|
||||
self._objects[anIndex] = object;
|
||||
|
||||
var processedObject = [object initWithCoder:self];
|
||||
|
||||
self._plistObject = savedPlistObject;
|
||||
|
||||
@@ -93,6 +93,11 @@ CPLog(@"Got some class: %@", inst);</pre>
|
||||
return class_createInstance(self);
|
||||
}
|
||||
|
||||
+ (id)allocWithCoder:(CPCoder)aCoder
|
||||
{
|
||||
return [self alloc];
|
||||
}
|
||||
|
||||
/*!
|
||||
Initializes the receiver
|
||||
@return the initialized receiver
|
||||
|
||||
@@ -177,8 +177,8 @@ function class_addMethod(/*Class*/ aClass, /*SEL*/ aName, /*IMP*/ anImplementati
|
||||
// FIXME: Should this be done here?
|
||||
// If this is a root class...
|
||||
if (!ISMETA(aClass) && GETMETA(aClass).isa === GETMETA(aClass))
|
||||
class_addMethods(GETMETA(aClass), methods);
|
||||
|
||||
class_addMethod(GETMETA(aClass), method);
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
|
||||
@import "NSButton.j"
|
||||
@import "NSCell.j"
|
||||
@import "NSClassSwapper.j"
|
||||
@import "NSClipView.j"
|
||||
@import "NSColor.j"
|
||||
@import "NSColorWell.j"
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
|
||||
var NSClassSwapperClassNames = {},
|
||||
NSClassSwapperOriginalClassNames = {};
|
||||
|
||||
var _CPCibClassSwapperClassNameKey = @"_CPCibClassSwapperClassNameKey",
|
||||
_CPCibClassSwapperOriginalClassNameKey = @"_CPCibClassSwapperOriginalClassNameKey";
|
||||
|
||||
@implementation NSClassSwapper : _CPCibClassSwapper
|
||||
{
|
||||
}
|
||||
|
||||
+ (id)swapperClassForClassName:(CPString)aClassName originalClassName:(CPString)anOriginalClassName
|
||||
{
|
||||
var swapperClassName = "$NSClassSwapper_" + aClassName + "_" + anOriginalClassName;
|
||||
swapperClass = objj_lookUpClass(swapperClassName);
|
||||
|
||||
if (!swapperClass)
|
||||
{
|
||||
var originalClass = objj_lookUpClass(anOriginalClassName);
|
||||
|
||||
swapperClass = objj_allocateClassPair(originalClass, swapperClassName);
|
||||
|
||||
objj_registerClassPair(swapperClass);
|
||||
try{
|
||||
class_addMethod(swapperClass, @selector(initWithCoder:), function(self, _cmd, aCoder)
|
||||
{
|
||||
self = objj_msgSendSuper({super_class:originalClass, receiver:self}, _cmd, aCoder);
|
||||
|
||||
if (self)
|
||||
{
|
||||
var UID = [self UID];
|
||||
|
||||
NSClassSwapperClassNames[UID] = aClassName;
|
||||
NSClassSwapperOriginalClassNames[UID] = anOriginalClassName;
|
||||
}
|
||||
|
||||
return self;
|
||||
}, "");
|
||||
}catch(e) { alert("B"); }try{
|
||||
class_addMethod(swapperClass, @selector(classForKeyedArchiver), function(self, _cmd)
|
||||
{
|
||||
return [_CPCibClassSwapper class];
|
||||
}, "");
|
||||
|
||||
class_addMethod(swapperClass, @selector(encodeWithCoder:), function(self, _cmd, aCoder)
|
||||
{
|
||||
objj_msgSendSuper({super_class:originalClass, receiver:self}, _cmd, aCoder);
|
||||
|
||||
// FIXME: map class name as well?
|
||||
[aCoder encodeObject:aClassName forKey:_CPCibClassSwapperClassNameKey];
|
||||
[aCoder encodeObject:CP_NSMapClassName(anOriginalClassName) forKey:_CPCibClassSwapperOriginalClassNameKey];
|
||||
}, "");}catch(e) { alert("C"); }
|
||||
}
|
||||
|
||||
return swapperClass;
|
||||
}
|
||||
|
||||
+ (id)allocWithCoder:(CPCoder)aCoder
|
||||
{
|
||||
var className = [aCoder decodeObjectForKey:@"NSClassName"],
|
||||
originalClassName = [aCoder decodeObjectForKey:@"NSOriginalClassName"];
|
||||
|
||||
return [[self swapperClassForClassName:className originalClassName:originalClassName] alloc];
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in new issue
Block a user