コード例 #1
0
        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);
        }
コード例 #2
0
ファイル: NiProject.cs プロジェクト: vector-man/netide
        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));
            }
        }
コード例 #3
0
                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);
                    }
                }
コード例 #4
0
ファイル: NiProject.cs プロジェクト: netide/netide
        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);
            }
        }
コード例 #5
0
            public Node(INiHierarchy hierarchy)
            {
                if (hierarchy != null)
                {
                    Name = (string)hierarchy.GetPropertyEx(NiHierarchyProperty.Name);
                }

                Children = new Dictionary <INiHierarchy, Node>();
            }
コード例 #6
0
        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);
        }
コード例 #7
0
            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();
            }
コード例 #8
0
        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);
            }
        }
コード例 #9
0
        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);
        }
コード例 #10
0
                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);
                }
コード例 #11
0
                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);
                    }
                }
コード例 #12
0
            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();
            }
コード例 #13
0
                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;
                }