From 699550c879b813bc6553bbccda26bc5172f2404a Mon Sep 17 00:00:00 2001 From: Francisco Tolmasky Date: Fri, 13 Feb 2009 14:45:18 -0800 Subject: [PATCH] Fixes to Cib support. Reviewed by me. --- AppKit/CPControl.j | 2 +- AppKit/Cib/CPCib.j | 13 ++++--- AppKit/Cib/_CPCibConnector.j | 16 +++++---- AppKit/Cib/_CPCibCustomObject.j | 5 +++ AppKit/Cib/_CPCibObjectData.j | 61 +++++++++++++++++++-------------- 5 files changed, 57 insertions(+), 40 deletions(-) diff --git a/AppKit/CPControl.j b/AppKit/CPControl.j index 5279749e4..5a18147cb 100644 --- a/AppKit/CPControl.j +++ b/AppKit/CPControl.j @@ -376,7 +376,7 @@ var CPControlBlackColor = [CPColor blackColor]; */ - (CPString)stringValue { - return _value ? String(_value) : ""; + return (_value === undefined || _value === nil) ? "" : String(_value); } /*! diff --git a/AppKit/Cib/CPCib.j b/AppKit/Cib/CPCib.j index 8d9a1dd55..2edaf4b19 100644 --- a/AppKit/Cib/CPCib.j +++ b/AppKit/Cib/CPCib.j @@ -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]; diff --git a/AppKit/Cib/_CPCibConnector.j b/AppKit/Cib/_CPCibConnector.j index 324f75cfe..27675ba11 100644 --- a/AppKit/Cib/_CPCibConnector.j +++ b/AppKit/Cib/_CPCibConnector.j @@ -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 diff --git a/AppKit/Cib/_CPCibCustomObject.j b/AppKit/Cib/_CPCibCustomObject.j index 847c12f28..debbe95d7 100644 --- a/AppKit/Cib/_CPCibCustomObject.j +++ b/AppKit/Cib/_CPCibCustomObject.j @@ -14,6 +14,11 @@ var _CPCibCustomObjectClassName = @"_CPCibCustomObjectClassName"; return _className; } +- (CPString)description +{ + return [super description] + " (" + [self customClassName] + ')'; +} + @end @implementation _CPCibCustomObject (CPCoding) diff --git a/AppKit/Cib/_CPCibObjectData.j b/AppKit/Cib/_CPCibObjectData.j index 7b8791220..a24b33e99 100644 --- a/AppKit/Cib/_CPCibObjectData.j +++ b/AppKit/Cib/_CPCibObjectData.j @@ -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]; } }