コード例 #1
0
        public override int Compare(CodeExplorerItemViewModel x, CodeExplorerItemViewModel y)
        {
            if (x == y)
            {
                return(0);
            }

            var nodeComparison = new CompareByNodeType().Compare(x, y);

            if (nodeComparison != 0)
            {
                return(nodeComparison);
            }

            if (!x.QualifiedSelection.HasValue && !y.QualifiedSelection.HasValue)
            {
                return(0);
            }

            if (x.QualifiedSelection.HasValue ^ y.QualifiedSelection.HasValue)
            {
                return(x.QualifiedSelection.HasValue ? -1 : 1);
            }

            if (x.QualifiedSelection.Value.Selection == y.QualifiedSelection.Value.Selection)
            {
                return(0);
            }

            return(x.QualifiedSelection.Value.Selection < y.QualifiedSelection.Value.Selection ? -1 : 1);
        }
コード例 #2
0
        public override int Compare(CodeExplorerItemViewModel x, CodeExplorerItemViewModel y)
        {
            if (x == y)
            {
                return(0);
            }

            var nodeComparison = new CompareByNodeType().Compare(x, y);

            if (nodeComparison != 0)
            {
                return(nodeComparison);
            }

            var xNode = (ICodeExplorerDeclarationViewModel)x;
            var yNode = (ICodeExplorerDeclarationViewModel)y;

            // keep separate types separate
            if (xNode.Declaration.DeclarationType != yNode.Declaration.DeclarationType)
            {
                int xValue, yValue;

                if (SortOrder.TryGetValue(xNode.Declaration.DeclarationType, out xValue) &&
                    SortOrder.TryGetValue(yNode.Declaration.DeclarationType, out yValue))
                {
                    if (xValue != yValue)
                    {
                        return(xValue < yValue ? -1 : 1);
                    }
                }
            }

            // The Tree shows Public and Private Subs/Functions with a seperate icon.
            // But Public and Implicit Subs/Functions appear the same, so treat Implicts like Publics.
            var xNodeAcc = xNode.Declaration.Accessibility == Accessibility.Implicit ? Accessibility.Public : xNode.Declaration.Accessibility;
            var yNodeAcc = yNode.Declaration.Accessibility == Accessibility.Implicit ? Accessibility.Public : yNode.Declaration.Accessibility;

            if (xNodeAcc != yNodeAcc)
            {
                return(xNodeAcc > yNodeAcc ? -1 : 1);
            }

            if (x.ExpandedIcon != y.ExpandedIcon)
            {
                // ReSharper disable PossibleInvalidOperationException - this will have a component
                var xComponent = x.QualifiedSelection.Value.QualifiedName.Component;
                var yComponent = y.QualifiedSelection.Value.QualifiedName.Component;

                if (xComponent.Type == ComponentType.Document ^ yComponent.Type == ComponentType.Document)
                {
                    return(xComponent.Type == ComponentType.Document ? -1 : 1);
                }
            }

            return(0);
        }
コード例 #3
0
        public override int Compare(CodeExplorerItemViewModel x, CodeExplorerItemViewModel y)
        {
            if (x == y)
            {
                return(0);
            }

            var nodeComparison = new CompareByNodeType().Compare(x, y);

            return(nodeComparison != 0
                ? nodeComparison
                : string.CompareOrdinal(x.NameWithSignature, y.NameWithSignature));
        }
コード例 #4
0
        public override int Compare(CodeExplorerItemViewModel x, CodeExplorerItemViewModel y)
        {
            if (x == y)
            {
                return(0);
            }

            var nodeComparison = new CompareByNodeType().Compare(x, y);

            if (nodeComparison != 0)
            {
                return(nodeComparison);
            }

            var xNode = (ICodeExplorerDeclarationViewModel)x;
            var yNode = (ICodeExplorerDeclarationViewModel)y;

            // keep separate types separate
            if (xNode.Declaration.DeclarationType != yNode.Declaration.DeclarationType)
            {
                int xValue, yValue;

                if (SortOrder.TryGetValue(xNode.Declaration.DeclarationType, out xValue) &&
                    SortOrder.TryGetValue(yNode.Declaration.DeclarationType, out yValue))
                {
                    return(xValue < yValue ? -1 : 1);
                }

                return(xNode.Declaration.DeclarationType < yNode.Declaration.DeclarationType ? -1 : 1);
            }

            if (xNode.Declaration.Accessibility != yNode.Declaration.Accessibility)
            {
                return(xNode.Declaration.Accessibility < yNode.Declaration.Accessibility ? -1 : 1);
            }

            if (x.ExpandedIcon != y.ExpandedIcon)
            {
                // ReSharper disable PossibleInvalidOperationException - this will have a component
                var xComponent = x.QualifiedSelection.Value.QualifiedName.Component;
                var yComponent = y.QualifiedSelection.Value.QualifiedName.Component;

                if (xComponent.Type == vbext_ComponentType.vbext_ct_Document ^
                    yComponent.Type == vbext_ComponentType.vbext_ct_Document)
                {
                    return(xComponent.Type == vbext_ComponentType.vbext_ct_Document ? -1 : 1);
                }
            }

            return(0);
        }
コード例 #5
0
        public override int Compare(CodeExplorerItemViewModel x, CodeExplorerItemViewModel y)
        {
            if (x == y)
            {
                return(0);
            }

            var nodeComparison = new CompareByNodeType().Compare(x, y);

            if (nodeComparison != 0)
            {
                return(nodeComparison);
            }

            var xNode = (ICodeExplorerDeclarationViewModel)x;
            var yNode = (ICodeExplorerDeclarationViewModel)y;

            // keep separate types separate
            if (xNode.Declaration.DeclarationType != yNode.Declaration.DeclarationType)
            {
                int xValue, yValue;

                if (SortOrder.TryGetValue(xNode.Declaration.DeclarationType, out xValue) &&
                    SortOrder.TryGetValue(yNode.Declaration.DeclarationType, out yValue))
                {
                    return(xValue < yValue ? -1 : 1);
                }

                return(xNode.Declaration.DeclarationType < yNode.Declaration.DeclarationType ? -1 : 1);
            }

            // keep types with different icons and the same declaration type (document/class module) separate
            // documents come first
            if (x.ExpandedIcon != y.ExpandedIcon)
            {
                // ReSharper disable once PossibleInvalidOperationException - this will have a component
                return(x.QualifiedSelection.Value.QualifiedName.Component.Type ==
                       Microsoft.Vbe.Interop.vbext_ComponentType.vbext_ct_Document
                    ? -1
                    : 1);
            }

            return(0);
        }