From c48d9a01c6a50fdf63c1b80fab6a80a9df138197 Mon Sep 17 00:00:00 2001 From: Francisco Ryan Tolmasky I Date: Thu, 29 Oct 2009 00:53:13 -0700 Subject: [PATCH 1/2] Removed some remaining cell "influences" in nib2cib'ed cib. There are references to NSCells in the object graph which should be removed, their children promoted to their parent's children. Reviewed by me. --- Tools/nib2cib/NSCell.j | 1 + Tools/nib2cib/NSIBObjectData.j | 64 ++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+) diff --git a/Tools/nib2cib/NSCell.j b/Tools/nib2cib/NSCell.j index a25a3f25f..604afeadf 100644 --- a/Tools/nib2cib/NSCell.j +++ b/Tools/nib2cib/NSCell.j @@ -27,6 +27,7 @@ @import "NSFont.j" + @implementation NSCell : CPObject { int _state @accessors(readonly, getter=state); diff --git a/Tools/nib2cib/NSIBObjectData.j b/Tools/nib2cib/NSIBObjectData.j index 6c7214bbb..e19f4ce78 100644 --- a/Tools/nib2cib/NSIBObjectData.j +++ b/Tools/nib2cib/NSIBObjectData.j @@ -58,6 +58,8 @@ _objectsKeys = [aCoder decodeObjectForKey:@"NSObjectsKeys"]; _objectsValues = [aCoder decodeObjectForKey:@"NSObjectsValues"]; + [self removeCellsFromObjectGraph]; + //_oidKeys = [aCoder decodeObjectForKey:@"NSOidsKeys"]; //_oidValues = [aCoder decodeObjectForKey:@"NSOidsValues"]; @@ -68,6 +70,68 @@ return self; } +- (void)removeCellsFromObjectGraph +{ + // FIXME: Remove from top level objects and connections? + + // Most cell references should be naturally removed by the fact that we don't manually + // encode them anywhere, however, they remain in our object graph. For each cell found, + // take its children and promote them to our parent object's children. + var count = _objectsKeys.length, + parentForCellUIDs = { }, + promotedChildrenForCellUIDs = { }; + + while (count--) + { + var child = _objectsKeys[count]; + + if (!child) + continue; + + var parent = _objectsValues[count]; + + // If this object is a cell, remember it's parent. + if ([child isKindOfClass:[NSCell class]]) + { + parentForCellUIDs[[child UID]] = parent; + continue; + } + + // If parent also isn't a cell, we don't care about it. + if (![parent isKindOfClass:[NSCell class]]) + continue; + + // Remember this child for later promotion. + var parentUID = [parent UID], + children = promotedChildrenForCellUIDs[parentUID]; + + if (!children) + { + children = []; + promotedChildrenForCellUIDs[parentUID] = children; + } + + children.push(child); + + _objectsKeys.splice(count, 1); + _objectsValues.splice(count, 1); + } + + for (var cellUID in promotedChildrenForCellUIDs) + if (promotedChildrenForCellUIDs.hasOwnProperty(cellUID)) + { + var children = promotedChildrenForCellUIDs[cellUID], + parent = parentForCellUIDs[cellUID]; + + children.forEach(function(aChild) + { + CPLog.warn("Promoted " + aChild + " to child of " + parent); + _objectsKeys.push(aChild); + _objectsValues.push(parent); + }); + } +} + @end @implementation NSIBObjectData : _CPCibObjectData From 8da4ea08236fd38a14851352535e4f5a9beaae04 Mon Sep 17 00:00:00 2001 From: Francisco Ryan Tolmasky I Date: Thu, 29 Oct 2009 16:25:05 -0700 Subject: [PATCH 2/2] Added import just in case. Reviewed by me. --- Tools/nib2cib/NSIBObjectData.j | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Tools/nib2cib/NSIBObjectData.j b/Tools/nib2cib/NSIBObjectData.j index e19f4ce78..26d2e5481 100644 --- a/Tools/nib2cib/NSIBObjectData.j +++ b/Tools/nib2cib/NSIBObjectData.j @@ -22,6 +22,8 @@ @import +@import "NSCell.j" + @implementation _CPCibObjectData (NSCoding)