public IEnumerable <MapNode> ExcludeNodesAlreadyPartOfHierarchy() { SelectedNodes nodes = this; int[] depth = new int[nodes.Count]; bool[] exclude = new bool[nodes.Count]; // default value is false for (int i = 0; i < nodes.Count; i++) { depth[i] = nodes[i].GetNodeDepth(); } for (int i = 0; i < nodes.Count; i++) { if (exclude[i]) { continue; } MapNode node1 = nodes[i]; for (int j = i + 1; j < nodes.Count; j++) { MapNode node2 = nodes[j]; if (depth[i] == depth[j] || exclude[j]) { continue; } else if (depth[i] < depth[j] && node2.IsDescendent(node1)) { exclude[j] = true; } else if (node1.IsDescendent(node2)) { exclude[i] = true; } } if (!exclude[i]) { yield return(node1); } } }
public static void Copy(SelectedNodes nodes) { if (nodes.Count > 0) { internalClipboard.Clear(); foreach (var n in nodes.ExcludeNodesAlreadyPartOfHierarchy()) { internalClipboard.Add(n.CloneAsDetached()); } var cbData = new MindMateClipboardDataObject(internalClipboard); Clipboard.SetDataObject(cbData); hasCutNode = false; StatusChanged?.Invoke(); } }
public static void Cut(SelectedNodes nodes) { if (nodes.Count > 0) { internalClipboard.Clear(); foreach (var n in nodes.ExcludeNodesAlreadyPartOfHierarchy()) { internalClipboard.Add(n); } internalClipboard.ForEach(n => n.Detach()); var cbData = new MindMateClipboardDataObject(internalClipboard); Clipboard.SetDataObject(cbData); hasCutNode = true; StatusChanged?.Invoke(); } }
public MapTree() { selectedNodes = new SelectedNodes(); }