Deleting a link recursively deletes all nodes below


#1

I am wondering how I would select a link, delete that link and delete everything that comes underneath that link. So if I have A—>B-----C----->D and I deleted the link from B–C, then the nodes C and D and the link between them would get deleted.

Right now I am using the SelectionDeleting Event handler

Jake fixed, thanks.


#2

See the TreeApp sample. Exactly what you want.


#3

This only deletes links when nodes are deleted, or am I using the wrong one?


#4

What I would like is for basically any node that does not have any incoming links after a link is deleted, to also be deleted. So a random floating node with no links attached to it will never be on screen.


#5

OK, exactly what you want, except it starts with a node instead of a link. Shouldn’t be difficult extension.

Just follow the IGoNode toIGoNode = link.ToPort.Node;

if the selected item is a link and not a node.


#6

Is there a way to remove everything? Like, if I remove a link, remove everything that stems from that link or removing the node, everything is removed, like how the Tree App works? Basically handling both cases?


#7

ok… replace AddSubtrees in TreeDraggingTool with this:

// extend the collection by recursively adding all of the destination links and nodes
// of all of the collection's nodes and links
public static void AddSubtrees(IGoCollection sel) {
  Hashtable coll = new Hashtable();
  foreach (GoObject o in sel) {
    GoObject obj = o;
    IGoLink link = obj as IGoLink;
    if (link != null)
    {
      obj = (GoObject)link.ToNode;
    }
    AddReachable(coll, obj as IGoNode);
  }
  foreach (GoObject obj in coll.Keys) {
    sel.Add(obj);
  }
}

#8

Really nice, I managed to figure it out but your code is much cleaner. Thank you for the help.