public InplaceRefactoringInfo GetInplaceRefactoringType(IDocument document, int caretOffset)
        {
            if (GetRefactoringAvailable == null)
            {
                return(InplaceRefactoringInfo.None);
            }

            using (CommitCookie.Commit(solution))
            {
                Func <object> callGetRefactoringAvailable = () => GetRefactoringAvailable(manager, document.GetPsiSourceFile(solution), caretOffset);
                var           refactoringInfo             = callGetRefactoringAvailable();
                if (refactoringInfo == null)
                {
                    return(InplaceRefactoringInfo.None);
                }

                switch (refactoringInfo.GetType().Name)
                {
                case "RenameInfo":
                    return(new InplaceRefactoringInfo(callGetRefactoringAvailable, InplaceRefactoringType.Rename));

                case "ChangeSignatureInfo":
                    return(new InplaceRefactoringInfo(callGetRefactoringAvailable, InplaceRefactoringType.ChangeSignature));

                case "MoveStaticMembersInfo":
                    return(new InplaceRefactoringInfo(callGetRefactoringAvailable, InplaceRefactoringType.MoveStaticMembers));
                }
            }

            return(InplaceRefactoringInfo.None);
        }
示例#2
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);
            }
        }
        protected override bool ExecuteItem(JetPopupMenuItem item)
        {
            var occurence = item.Key as IOccurence;

            using (CommitCookie.Commit(Solution))
            {
                var elementOccurence = occurence as DeclaredElementOccurence;
                if (elementOccurence != null)
                {
                    var validDeclaredElement = elementOccurence.DisplayElement.GetValidDeclaredElement();
                    if (validDeclaredElement != null)
                    {
                        var action = new FindUsagesOfElementAction(validDeclaredElement);
                        threading.ExecuteOrQueue("FindUsagesOfSymbolController",
                                                 () => Lifetimes.Using(lifetime => action.Execute(dataContexts.CreateOnActiveControl(lifetime), () => { })));
                        return(true);
                    }
                }

                return(false);
            }
        }