mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-08-25 04:57:03 +00:00
Made CPCibConnector, CPCibOutletConnector, and CPCibControlConnector public classes.
Reviewed by me.
This commit is contained in:
@@ -29,7 +29,10 @@
|
||||
@import "CPButtonBar.j"
|
||||
@import "CPCheckBox.j"
|
||||
@import "CPCib.j"
|
||||
@import "CPCibConnector.j"
|
||||
@import "CPCibControlConnector.j"
|
||||
@import "CPCibLoading.j"
|
||||
@import "CPCibOutletConnector.j"
|
||||
@import "CPClipView.j"
|
||||
@import "CPCollectionView.j"
|
||||
@import "CPColor.j"
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
/*
|
||||
* CPCibConnector.j
|
||||
* AppKit
|
||||
*
|
||||
* 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 <Foundation/CPObject.j>
|
||||
@import <Foundation/CPKeyValueCoding.j>
|
||||
|
||||
|
||||
var _CPCibConnectorSourceKey = @"_CPCibConnectorSourceKey",
|
||||
_CPCibConnectorDestinationKey = @"_CPCibConnectorDestinationKey",
|
||||
_CPCibConnectorLabelKey = @"_CPCibConnectorLabelKey";
|
||||
|
||||
@implementation CPCibConnector : CPObject
|
||||
{
|
||||
id _source @accessors(property=source);
|
||||
id _destination @accessors(property=destination);
|
||||
CPString _label @accessors(property=label);
|
||||
}
|
||||
|
||||
- (void)replaceObject:(id)anObject withObject:(id)anotherObject
|
||||
{
|
||||
if (_source === anObject)
|
||||
_source = anotherObject;
|
||||
|
||||
if (_destination === anObject)
|
||||
_destination = anotherObject;
|
||||
}
|
||||
|
||||
- (void)replaceObjects:(Object)replacementObjects
|
||||
{
|
||||
var replacement = replacementObjects[[_source UID]];
|
||||
|
||||
if (replacement !== undefined)
|
||||
_source = replacement;
|
||||
|
||||
replacement = replacementObjects[[_destination UID]];
|
||||
|
||||
if (replacement !== undefined)
|
||||
_destination = replacement;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation CPCibConnector (CPCoding)
|
||||
|
||||
- (id)initWithCoder:(CPCoder)aCoder
|
||||
{
|
||||
self = [super init];
|
||||
|
||||
if (self)
|
||||
{
|
||||
_source = [aCoder decodeObjectForKey:_CPCibConnectorSourceKey];
|
||||
_destination = [aCoder decodeObjectForKey:_CPCibConnectorDestinationKey];
|
||||
_label = [aCoder decodeObjectForKey:_CPCibConnectorLabelKey];
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)encodeWithCoder:(CPCoder)aCoder
|
||||
{
|
||||
[aCoder encodeObject:_source forKey:_CPCibConnectorSourceKey];
|
||||
[aCoder encodeObject:_destination forKey:_CPCibConnectorDestinationKey];
|
||||
[aCoder encodeObject:_label forKey:_CPCibConnectorLabelKey];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
// For backwards compatibility.
|
||||
@implementation _CPCibConnector : CPCibConnector { } @end
|
||||
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* CPCibControlConnector.j
|
||||
* AppKit
|
||||
*
|
||||
* 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 "CPCibConnector.j"
|
||||
|
||||
|
||||
@implementation CPCibControlConnector : CPCibConnector
|
||||
{
|
||||
}
|
||||
|
||||
- (void)establishConnection
|
||||
{
|
||||
var selectorName = _label,
|
||||
selectorNameLength = [selectorName length];
|
||||
|
||||
if (selectorNameLength && selectorName[selectorNameLength - 1] !== ':')
|
||||
selectorName += ':';
|
||||
|
||||
var selector = CPSelectorFromString(selectorName);
|
||||
|
||||
// Not having a selector is a fatal error.
|
||||
if (!selector)
|
||||
[CPException
|
||||
raise:CPInvalidArgumentException
|
||||
reason:@"-[" + [self className] + ' ' + _cmd + @"] selector " + selectorName + @" does not exist."];
|
||||
|
||||
// If the destination doesn't respond to this selector, warn but don't die.
|
||||
if (_destination && ![_destination respondsToSelector:selector])
|
||||
{
|
||||
CPLog.warn(@"Could not connect the action " + selector + @" to target of class " + [_destination className]);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Not being able to set the action is a fatal error.
|
||||
if ([_source respondsToSelector:@selector(setAction:)])
|
||||
objj_msgSend(_source, @selector(setAction:), selector);
|
||||
|
||||
else
|
||||
[CPException
|
||||
raise:CPInvalidArgumentException
|
||||
reason:@"-[" + [self className] + ' ' + _cmd + @"] " + [_source description] + " does not respond to setAction:"];
|
||||
|
||||
// Not being able to set the target is a fatal error.
|
||||
if ([_source respondsToSelector:@selector(setTarget:)])
|
||||
objj_msgSend(_source, @selector(setTarget:), _destination);
|
||||
|
||||
else
|
||||
[CPException
|
||||
raise:CPInvalidArgumentException
|
||||
reason:@"-[" + [self className] + ' ' + _cmd + @"] " + [_source description] + " does not respond to setTarget:"];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation _CPCibControlConnector : CPCibControlConnector { } @end
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* CPCibOutletConnector.j
|
||||
* AppKit
|
||||
*
|
||||
* 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 "CPCibConnector.j"
|
||||
|
||||
|
||||
@implementation CPCibOutletConnector : CPCibConnector
|
||||
{
|
||||
}
|
||||
|
||||
- (void)establishConnection
|
||||
{
|
||||
try
|
||||
{
|
||||
[_source setValue:_destination forKey:_label];
|
||||
}
|
||||
catch (anException)
|
||||
{
|
||||
if ([anException name] === CPUndefinedKeyException)
|
||||
CPLog.warn(@"Could not connect the outlet " + _label + @" of target of class " + [_source className]);
|
||||
|
||||
else
|
||||
throw anException;
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation _CPCibOutletConnector : CPCibOutletConnector { } @end
|
||||
@@ -1,126 +0,0 @@
|
||||
|
||||
@import <Foundation/CPObject.j>
|
||||
@import <Foundation/CPKeyValueCoding.j>
|
||||
|
||||
|
||||
var _CPCibConnectorSourceKey = @"_CPCibConnectorSourceKey",
|
||||
_CPCibConnectorDestinationKey = @"_CPCibConnectorDestinationKey",
|
||||
_CPCibConnectorLabelKey = @"_CPCibConnectorLabelKey";
|
||||
|
||||
@implementation _CPCibConnector : CPObject
|
||||
{
|
||||
id _source;
|
||||
id _destination;
|
||||
CPString _label;
|
||||
}
|
||||
|
||||
- (void)replaceObjects:(JSObject)replacementObjects
|
||||
{
|
||||
var replacement = replacementObjects[[_source UID]];
|
||||
|
||||
if (replacement !== undefined)
|
||||
_source = replacement;
|
||||
|
||||
replacement = replacementObjects[[_destination UID]];
|
||||
|
||||
if (replacement !== undefined)
|
||||
_destination = replacement;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation _CPCibConnector (CPCoding)
|
||||
|
||||
- (id)initWithCoder:(CPCoder)aCoder
|
||||
{
|
||||
self = [super init];
|
||||
|
||||
if (self)
|
||||
{
|
||||
_source = [aCoder decodeObjectForKey:_CPCibConnectorSourceKey];
|
||||
_destination = [aCoder decodeObjectForKey:_CPCibConnectorDestinationKey];
|
||||
_label = [aCoder decodeObjectForKey:_CPCibConnectorLabelKey];
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)encodeWithCoder:(CPCoder)aCoder
|
||||
{
|
||||
[aCoder encodeObject:_source forKey:_CPCibConnectorSourceKey];
|
||||
[aCoder encodeObject:_destination forKey:_CPCibConnectorDestinationKey];
|
||||
[aCoder encodeObject:_label forKey:_CPCibConnectorLabelKey];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation _CPCibControlConnector : _CPCibConnector
|
||||
{
|
||||
}
|
||||
|
||||
- (void)establishConnection
|
||||
{
|
||||
var selectorName = _label,
|
||||
selectorNameLength = [selectorName length];
|
||||
|
||||
if (selectorNameLength && selectorName[selectorNameLength - 1] !== ':')
|
||||
selectorName += ':';
|
||||
|
||||
var selector = CPSelectorFromString(selectorName);
|
||||
|
||||
// Not having a selector is a fatal error.
|
||||
if (!selector)
|
||||
[CPException
|
||||
raise:CPInvalidArgumentException
|
||||
reason:@"-[" + [self className] + ' ' + _cmd + @"] selector " + selectorName + @" does not exist."];
|
||||
|
||||
// If the destination doesn't respond to this selector, warn but don't die.
|
||||
if (_destination && ![_destination respondsToSelector:selector])
|
||||
{
|
||||
CPLog.warn(@"Could not connect the action " + selector + @" to target of class " + [_destination className]);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Not being able to set the action is a fatal error.
|
||||
if ([_source respondsToSelector:@selector(setAction:)])
|
||||
objj_msgSend(_source, @selector(setAction:), selector);
|
||||
|
||||
else
|
||||
[CPException
|
||||
raise:CPInvalidArgumentException
|
||||
reason:@"-[" + [self className] + ' ' + _cmd + @"] " + [_source description] + " does not respond to setAction:"];
|
||||
|
||||
// Not being able to set the target is a fatal error.
|
||||
if ([_source respondsToSelector:@selector(setTarget:)])
|
||||
objj_msgSend(_source, @selector(setTarget:), _destination);
|
||||
|
||||
else
|
||||
[CPException
|
||||
raise:CPInvalidArgumentException
|
||||
reason:@"-[" + [self className] + ' ' + _cmd + @"] " + [_source description] + " does not respond to setTarget:"];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation _CPCibOutletConnector : _CPCibConnector
|
||||
{
|
||||
}
|
||||
|
||||
- (void)establishConnection
|
||||
{
|
||||
try
|
||||
{
|
||||
[_source setValue:_destination forKey:_label];
|
||||
}
|
||||
catch (anException)
|
||||
{
|
||||
if ([anException name] === CPUndefinedKeyException)
|
||||
CPLog.warn(@"Could not connect the outlet " + _label + @" of target of class " + [_source className]);
|
||||
|
||||
else
|
||||
throw anException;
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -16,11 +16,6 @@ CPLogRegister(CPLogConsole);
|
||||
|
||||
- (void)applicationDidFinishLaunching:(CPNotification)aNotification
|
||||
{
|
||||
indexes = [CPMutableIndexSet indexSetWithIndex:5];
|
||||
|
||||
[indexes addIndexesInRange:CPMakeRange(4, 1)];
|
||||
alert(indexes);
|
||||
return;
|
||||
var view = [[CPView alloc] initWithFrame:CGRectMake(0.0, 0.0, 100.0, 100.0)];
|
||||
|
||||
[view setBackgroundColor:[CPColor whiteColor]];
|
||||
|
||||
Reference in New Issue
Block a user