/// <summary> /// Constructor /// </summary> /// <param name="targetNode">Target node that will be the parent of the new nodes</param> protected AsyncNodeProvider(TreeNodeData targetNode) { lockObj = new object(); this.targetNode = targetNode; dispatcher = Dispatcher.CurrentDispatcher; uiThreadActions = new List <Action>(); cancellationTokenSource = new CancellationTokenSource(); cancellationToken = cancellationTokenSource.Token; thread = new Thread(ThreadMethodImpl); thread.IsBackground = true; }
/// <summary> /// Adds a new node /// </summary> /// <param name="node">New node</param> protected void AddNode(TreeNodeData node) { if (node is null) { throw new ArgumentNullException(nameof(node)); } lock (lockObj) { nodesToAdd.Add(node); if (nodesToAdd.Count == 1) { UI(AddNodes_UI); } } }
/// <summary> /// Gets the ancestor of a certain type /// </summary> /// <typeparam name="T">Desired type</typeparam> /// <param name="self">This</param> /// <returns></returns> public static T GetAncestorOrSelf <T>(this TreeNodeData self) where T : TreeNodeData { while (self != null) { if (self is T found) { return(found); } var parent = self.TreeNode.Parent; if (parent == null) { break; } self = parent.Data; } return(null); }
/// <summary> /// Constructor /// </summary> /// <param name="node">Node</param> /// <param name="removed">true if it was removed</param> public TreeViewNodeRemovedEventArgs(TreeNodeData node, bool removed) { Node = node; Removed = removed; }
/// <summary> /// Gets all descendants including itself /// </summary> /// <param name="self">This</param> /// <returns></returns> public static IEnumerable <TreeNodeData> DescendantsAndSelf(this TreeNodeData self) => self.TreeNode.DescendantsAndSelf().Select(a => a.Data);