def _create_manager_recurse(self, schema, additions, path=""): """ Recursively builds the manager for with the specified additions map. """ # Compute the new action path. if path: path += "/" path += schema.id # Determine the order of the items at this path. items = schema.items if additions[path]: items = before_after_sort(items + additions[path]) # Create the actual children by calling factory items. children = [] for item in items: # Unpack additions first, since they may themselves be schemas. if isinstance(item, SchemaAddition): item = item.factory() if isinstance(item, Schema): item = self._create_manager_recurse(item, additions, path) if isinstance(item, ActionManager): # Give even non-root action managers a reference to the # controller so that custom Groups, MenuManagers, etc. can get # access to their Tasks. item.controller = self.controller children.append(item) # Finally, create the pyface.action instance for this schema. return schema.create(children)
def test_before_after_sort_2(self): """ Does the before-after sort work when both 'before' and 'after' are set? """ items = [ TestItem(1), TestItem(2), TestItem(3), TestItem(4, after=2, before=3) ] actual = before_after_sort(items) desired = [ TestItem(1), TestItem(2), TestItem(4), TestItem(3) ] self.assertEquals(actual, desired)
def test_before_after_sort_1(self): """ Does the before-after sort work? """ items = [ TestItem(1), TestItem(2), TestItem(3, before=2), TestItem(4, after=1), TestItem(5) ] actual = before_after_sort(items) desired = [ TestItem(1), TestItem(3), TestItem(4), TestItem(2), TestItem(5) ] self.assertEquals(actual, desired)
def test_before_after_sort_3(self): """ Does the degenerate case for the before-after sort work? """ actual = before_after_sort([ TestItem(1) ]) desired = [ TestItem(1) ] self.assertEquals(actual, desired)