protected override IEnumerable GetChildren(TreeModelNode modelNode)
        {
            // dataValue is null when requesting root elements, we have only one
            if (modelNode == null)
            {
                return new[] { myTypeElementEnvoy }
            }
            ;

            var envoy = modelNode.DataValue as IDeclaredElementEnvoy;

            if (envoy == null)
            {
                return(EmptyArray <IDeclaredElementEnvoy> .Instance);
            }

            bool             instanceVisible = envoy != myTypeElementEnvoy || myInstanceOnly;
            IDeclaredElement declaredElement = envoy.GetValidDeclaredElement();

            // Get type which is expanded for the node
            var typeElement = declaredElement as ITypeElement;

            if (typeElement == null)
            {
                var typeOwner = declaredElement as ITypeOwner;
                if (typeOwner != null && !(typeOwner is IEvent))
                {
                    typeElement = TypeInterfaceUtil.GetTypeElement(typeOwner.Type);
                }
                else
                {
                    var method = declaredElement as IMethod;
                    if (method != null)
                    {
                        typeElement = TypeInterfaceUtil.GetTypeElement(method.ReturnType);
                    }
                }
            }
            if (typeElement == null)
            {
                return(EmptyArray <DeclaredElementEnvoy <ITypeElement> > .Instance);
            }

            return(GetChildren(typeElement, instanceVisible));
        }
        // Quickly determine if node has children
        // Can return true and then return no children, but not the opposite
        protected override bool HasChildren(TreeModelNode modelNode)
        {
            // Get value associated with node
            object dataValue = modelNode.DataValue;

            if (dataValue == null)
            {
                return(true);
            }

            var envoy = dataValue as IDeclaredElementEnvoy;

            if (envoy != null)
            {
                // Get type which will be expanded for the node
                IDeclaredElement declaredElement = envoy.GetValidDeclaredElement();
                var typeElement = declaredElement as ITypeElement;
                if (typeElement == null)
                {
                    var typeOwner = declaredElement as ITypeOwner;
                    if (typeOwner != null && !(typeOwner is IEvent))
                    {
                        typeElement = TypeInterfaceUtil.GetTypeElement(typeOwner.Type);
                    }
                    else
                    {
                        var method = declaredElement as IMethod;
                        if (method != null)
                        {
                            typeElement = TypeInterfaceUtil.GetTypeElement(method.ReturnType);
                        }
                    }
                }
                // Type cannot be determined (or void)
                if (typeElement == null)
                {
                    return(false);
                }

                // Do we have members for type?
                return(!typeElement.GetMembers().IsEmpty());
            }
            return(false);
        }
Exemplo n.º 3
0
        public void Execute(IDataContext context, DelegateExecute nextExecute)
        {
            // Get solution from context in which action is executed
            ISolution solution = context.GetData(ProjectModel.DataContext.DataConstants.SOLUTION);

            if (solution == null)
            {
                return;
            }

            // Get PsiManager for solution, from which we will obtain code elements
            var services = solution.GetPsiServices();

            if (!services.PsiManager.AllDocumentsAreCommited)
            {
                return;
            }

            using (CommitCookie caches = CommitCookie.Commit(solution).WaitForCaches(this))
            {
                if (caches.Cancelled)
                {
                    return;
                }

                bool         instanceOnly;
                ITypeElement typeElement = TypeInterfaceUtil.GetTypeElement(context, out instanceOnly);
                if (typeElement == null)
                {
                    MessageBox.ShowExclamation("Cannot get type from current location", "Explore Type Interface");
                    return;
                }

                // Create descriptor and ask TreeModelBrowser to show it in the HierarchyResults view.
                // Same view, where type hierarchy is shown
                var descriptor      = new TypeInterfaceDescriptor(typeElement, instanceOnly);
                var windowRegistrar = solution.GetComponent <TypeInterfaceToolWindowRegistrar>();
                windowRegistrar.Show(descriptor);
            }
        }