Fixes to Cib support.

Reviewed by me.
This commit is contained in:
Francisco Tolmasky
2009-02-13 14:45:18 -08:00
parent 58111b3ba1
commit 699550c879
5 changed files with 57 additions and 40 deletions
+1 -1
View File
@@ -376,7 +376,7 @@ var CPControlBlackColor = [CPColor blackColor];
*/
- (CPString)stringValue
{
return _value ? String(_value) : "";
return (_value === undefined || _value === nil) ? "" : String(_value);
}
/*!
+6 -7
View File
@@ -72,22 +72,21 @@ var CPCibObjectDataKey = @"CPCibObjectDataKey";
if (!objectData || ![objectData isKindOfClass:[_CPCibObjectData class]])
return NO;
[objectData establishConnectionsWithExternalNameTable:anExternalNameTable];
var owner = [anExternalNameTable objectForKey:CPCibOwner],
topLevelObjects = [anExternalNameTable objectForKey:CPCibTopLevelObjects];
[objectData instantiateWithOwner:owner topLevelObjects:topLevelObjects]
[objectData establishConnectionsWithOwner:owner topLevelObjects:topLevelObjects];
var menu;
if ((menu = [objectData mainMenu]) != nil)
{
[CPApp setMainMenu:menu];
[CPMenu setMenuBarVisible:YES];
}
if (topLevelObjects)
[topLevelObjects addObjectsFromArray:[objectData topLevelObjects]];
// Display Visible Windows.
[[objectData visibleWindows] makeObjectsPerformSelector:@selector(makeKeyAndOrderFront:) withObject:self];
+10 -6
View File
@@ -14,13 +14,17 @@ var _CPCibConnectorSourceKey = @"_CPCibConnectorSourceKey",
CPString _label;
}
- (void)replaceObject:(id)anObject withObject:(id)anotherObject
- (void)replaceObjects:(JSObject)replacementObjects
{
if (_source == anObject)
_source = anotherObject;
else if (_destination == anObject)
_destination = anotherObject;
var replacement = replacementObjects[[_source hash]];
if (replacement !== undefined)
_source = replacement;
replacement = replacementObjects[[_destination hash]];
if (replacement !== undefined)
_destination = replacement;
}
@end
+5
View File
@@ -14,6 +14,11 @@ var _CPCibCustomObjectClassName = @"_CPCibCustomObjectClassName";
return _className;
}
- (CPString)description
{
return [super description] + " (" + [self customClassName] + ')';
}
@end
@implementation _CPCibCustomObject (CPCoding)
+35 -26
View File
@@ -57,35 +57,17 @@
_CPCibCustomObject _fileOwner;
CPSet _visibleWindows;
}
- (CPArray)topLevelObjects
{
var count = [_objectsValues count],
topLevelObjects = [];
while (count--)
{
var eachObject = _objectsValues[count];
if (eachObject == _fileOwner)
{
var anObject = _objectsKeys[count];
if (anObject != _fileOwner)
topLevelObjects.push(anObject);
}
}
return topLevelObjects;
JSObject _replacementObjects;
}
- (CPMenu)mainMenu
{
var index = [_namesValues indexOfObjectIdenticalTo:"MainMenu"];
if (index === CPNotFound)
return nil;
return _namesKeys[index];
}
@@ -131,6 +113,8 @@ var _CPCibObjectDataNamesKeysKey = @"_CPCibObjectDataNamesKeysKey
if (self)
{
_replacementObjects = {};
_namesKeys = [aCoder decodeObjectForKey:_CPCibObjectDataNamesKeysKey];
_namesValues = [aCoder decodeObjectForKey:_CPCibObjectDataNamesValuesKey];
@@ -194,17 +178,42 @@ var _CPCibObjectDataNamesKeysKey = @"_CPCibObjectDataNamesKeysKey
[aCoder encodeObject:_visibleWindows forKey:_CPCibObjectDataVisibleWindowsKey];
}
- (void)establishConnectionsWithExternalNameTable:(CPDictionary)anExternalNameTable
- (void)instantiateWithOwner:(id)anOwner topLevelObjects:(CPMutableArray)topLevelObjects
{
// _objectsValues -> parent
// _objectsKeys -> child
var count = [_objectsKeys count];
while (count--)
{
var object = _objectsKeys[count],
parent = _objectsValues[count];
if ([object respondsToSelector:@selector(_cibInstantiate)])
{
var instantiatedObject = [object _cibInstantiate];
if (instantiatedObject !== object)
_replacementObjects[[object hash]] = instantiatedObject;
}
if (topLevelObjects && parent === _fileOwner && object !== _fileOwner)
topLevelObjects.push(object);
}
}
- (void)establishConnectionsWithOwner:(id)anOwner topLevelObjects:(CPMutableArray)topLevelObjects
{
_replacementObjects[[_fileOwner hash]] = anOwner;
var index = 0,
count = _connections.length,
cibOwner = [anExternalNameTable objectForKey:CPCibOwner];
count = _connections.length;
for (; index < count; ++index)
{
var connection = _connections[index];
[connection replaceObject:_fileOwner withObject:cibOwner];
[connection replaceObjects:_replacementObjects];
[connection establishConnection];
}
}