public static INiHierarchy FindNext(this INiHierarchy self) { // Descend into children. var firstChild = (INiHierarchy)self.GetPropertyEx(NiHierarchyProperty.FirstChild); if (firstChild != null) { return(firstChild); } // Find the next sibling. var nextSibling = (INiHierarchy)self.GetPropertyEx(NiHierarchyProperty.NextSibling); if (nextSibling != null) { return(nextSibling); } // Look at the parents. var root = self; var parent = (INiHierarchy)self.GetPropertyEx(NiHierarchyProperty.Parent); while (parent != null) { // If the parent has a next sibling, return that. nextSibling = (INiHierarchy)parent.GetPropertyEx(NiHierarchyProperty.NextSibling); if (nextSibling != null) { return(nextSibling); } // Else, look at the parent of the parent. root = parent; parent = (INiHierarchy)parent.GetPropertyEx(NiHierarchyProperty.Parent); } // If the root didn't have a next sibling, we re-start from the root. // If we started at the root (i.e. the root is the only hierarchy), // we don't return it. if (root != self) { return(root); } return(null); }
public virtual HResult OpenItem(INiHierarchy hier, out INiWindowFrame windowFrame) { windowFrame = null; try { if ((NiHierarchyType?)hier.GetPropertyEx(NiHierarchyProperty.ItemType) == NiHierarchyType.File) { string fileName; ErrorUtil.ThrowOnFailure(((INiProjectItem)hier).GetFileName(out fileName)); return(((INiOpenDocumentManager)GetService(typeof(INiOpenDocumentManager))).OpenStandardEditor( null, fileName, hier, this, out windowFrame )); } return(HResult.False); } catch (Exception ex) { return(ErrorUtil.GetHResult(ex)); } }
public void OnPropertyChanged(INiHierarchy hier, int property) { try { switch ((NiHierarchyProperty)property) { case NiHierarchyProperty.Name: _manager.TreeNode.Text = (string)hier.GetPropertyEx(NiHierarchyProperty.Name); _manager.Reorder(); break; case NiHierarchyProperty.SortPriority: _manager.Reorder(); break; case NiHierarchyProperty.Image: case NiHierarchyProperty.OverlayImage: case NiHierarchyProperty.ItemType: _manager.UpdateImage(); break; } } catch (Exception ex) { Log.Warn("Failed to process hierarchy property change", ex); } }
public virtual HResult OpenItem(INiHierarchy hier, out INiWindowFrame windowFrame) { windowFrame = null; try { if ((NiHierarchyType?)hier.GetPropertyEx(NiHierarchyProperty.ItemType) == NiHierarchyType.File) { string fileName; ErrorUtil.ThrowOnFailure(((INiProjectItem)hier).GetFileName(out fileName)); return ((INiOpenDocumentManager)GetService(typeof(INiOpenDocumentManager))).OpenStandardEditor( null, fileName, hier, this, out windowFrame ); } return HResult.False; } catch (Exception ex) { return ErrorUtil.GetHResult(ex); } }
public Node(INiHierarchy hierarchy) { if (hierarchy != null) { Name = (string)hierarchy.GetPropertyEx(NiHierarchyProperty.Name); } Children = new Dictionary <INiHierarchy, Node>(); }
public static INiHierarchy FindPrevious(this INiHierarchy self) { var parent = (INiHierarchy)self.GetPropertyEx(NiHierarchyProperty.Parent); // Look at the parent. if (parent != null) { // Find the previous sibling of the parent. INiHierarchy previousSibling = null; foreach (var child in parent.GetChildren()) { if (child == self) { break; } previousSibling = child; } // If the parent had a previous sibling, find the last child // if that sibling. if (previousSibling != null) { return(GetLastChild(previousSibling)); } // Else, return the parent. return(parent); } // We're at the root. In that case, descend into the last child of the root. var lastChild = GetLastChild(self); // Don't return the last child if it's the same as the root // (i.e. is the only node). if (self == lastChild) { return(null); } return(lastChild); }
public TreeNodeManager(ProjectExplorerControl owner, INiHierarchy item) { _owner = owner; Item = item; _listener = new Listener(this); TreeNode = new TreeNode { Text = (string)Item.GetPropertyEx(NiHierarchyProperty.Name), Tag = this }; UpdateImage(); }
public static IEnumerable <INiHierarchy> GetChildren(this INiHierarchy self) { if (self == null) { throw new ArgumentNullException("self"); } var child = (INiHierarchy)self.GetPropertyEx(NiHierarchyProperty.FirstChild); while (child != null) { yield return(child); child = (INiHierarchy)child.GetPropertyEx(NiHierarchyProperty.NextSibling); } }
private static Node InsertNode(Node node, INiHierarchy hier) { var parent = (INiHierarchy)hier.GetPropertyEx(NiHierarchyProperty.Parent); if (parent != null) { node = InsertNode(node, parent); } Node result; if (!node.Children.TryGetValue(hier, out result)) { result = new Node(hier); node.Children.Add(hier, result); } return(result); }
protected override bool FindNext() { if (_current == null) { _current = GetCurrentHierarchy(_serviceProvider); // If we're finding all items, start from the root. if ( _findState.Options.HasFlag(NiFindOptions.FindAll) || _findState.Options.HasFlag(NiFindOptions.ReplaceAll) ) { _current = (INiHierarchy)_current.GetPropertyEx(NiHierarchyProperty.Root); } if (_current == null) { return(false); } } else { _current = _findState.Options.HasFlag(NiFindOptions.Backwards) ? _current.FindPrevious() : _current.FindNext(); if (_current == null || _seen.Contains(_current)) { _current = null; return(false); } } _seen.Add(_current); return(true); }
public void OnPropertyChanged(INiHierarchy hier, int property) { try { switch ((NiHierarchyProperty)property) { case NiHierarchyProperty.Name: _manager.TreeNode.Text = (string)hier.GetPropertyEx(NiHierarchyProperty.Name); _manager.Reorder(); break; case NiHierarchyProperty.SortPriority: _manager.Reorder(); break; case NiHierarchyProperty.Image: case NiHierarchyProperty.OverlayImage: case NiHierarchyProperty.ItemType: _manager.UpdateImage(); break; } } catch (Exception ex) { Log.Warn("Failed to process hierarchy property change", ex); } }
public TreeNodeManager(ProjectExplorerControl owner, INiHierarchy item) { _owner = owner; Item = item; _listener = new Listener(this); TreeNode = new TreeNode { Text = (string)Item.GetPropertyEx(NiHierarchyProperty.Name), Tag = this }; UpdateImage(); }
protected override bool FindNext() { if (_current == null) { _current = GetCurrentHierarchy(_serviceProvider); // If we're finding all items, start from the root. if ( _findState.Options.HasFlag(NiFindOptions.FindAll) || _findState.Options.HasFlag(NiFindOptions.ReplaceAll) ) _current = (INiHierarchy)_current.GetPropertyEx(NiHierarchyProperty.Root); if (_current == null) return false; } else { _current = _findState.Options.HasFlag(NiFindOptions.Backwards) ? _current.FindPrevious() : _current.FindNext(); if (_current == null || _seen.Contains(_current)) { _current = null; return false; } } _seen.Add(_current); return true; }