private void UpdateSelection(bool includeTree, bool highlightOnly) { SelectableTreeNodeData stnd = SelectFromPoint(lastX, lastY); if (highlightOnly) return; if (!Visible) Visible = true; if (!stnd.Equals(lastNode) || includeTree != lastIncludeTree) { DoSelect(stnd, includeTree); lastNode = stnd; lastIncludeTree = includeTree; } }
internal void DoSelect(SelectableTreeNodeData wd, bool includeTree) { selectedChild = wd.Details; selectedChild.Update(wd, allowChanges.Checked, this); UpdateChildControl(); if (!includeTree) return; Application.DoEvents(); TreeNode n = findNode(new WindowCache(), wd); if (n != null) { autoExpand = true; tree.SelectedNode = n; autoExpand = false; } }
private TreeNode findNode(WindowCache wc, SelectableTreeNodeData wd) { if (wd is WindowData) { if (wc.AddUnlisted(((WindowData)wd).Window)) { MessageBox.Show("This Window is not included in EnumWindows"); } } if (!existingNodes.ContainsKey(wd)) { IList<TreeNodeData> parents = wd.PossibleParents; TreeNode curr = tree.Nodes[0]; foreach (TreeNodeData p in parents) { if (existingNodes.ContainsKey(p)) { curr = existingNodes[p]; break; } } while (!curr.Tag.Equals(wd)) { if (curr.Nodes.Count == 1 && curr.Nodes[0].Tag is string) { curr.Nodes.Clear(); refreshNode(wc, curr, true); } bool found = false; foreach (TreeNodeData parent in parents) { foreach (TreeNode n in curr.Nodes) { if (n.Tag.Equals(parent)) { curr = n; found = true; break; } } if (found) break; } if (!found) { refreshNode(wc, curr, true); foreach (TreeNodeData parent in parents) { foreach (TreeNode n in curr.Nodes) { if (n.Tag.Equals(parent)) { curr = n; found = true; break; } } if (found) break; } } if (!found) { MessageBox.Show("Could not find window below " + curr.Text); return curr; } } if (existingNodes[wd] != curr) throw new Exception(); } return existingNodes[wd]; }