Search in sources :

Example 1 with ContextAwareActionHandler

use of com.intellij.lang.ContextAwareActionHandler in project intellij-community by JetBrains.

the class BaseRefactoringAction method hasAvailableHandler.

protected boolean hasAvailableHandler(@NotNull DataContext dataContext) {
    final RefactoringActionHandler handler = getHandler(dataContext);
    if (handler != null) {
        if (handler instanceof ContextAwareActionHandler) {
            final Editor editor = CommonDataKeys.EDITOR.getData(dataContext);
            final PsiFile file = CommonDataKeys.PSI_FILE.getData(dataContext);
            if (editor != null && file != null && !((ContextAwareActionHandler) handler).isAvailableForQuickList(editor, file, dataContext)) {
                return false;
            }
        }
        return true;
    }
    return false;
}
Also used : RefactoringActionHandler(com.intellij.refactoring.RefactoringActionHandler) Editor(com.intellij.openapi.editor.Editor) ContextAwareActionHandler(com.intellij.lang.ContextAwareActionHandler)

Example 2 with ContextAwareActionHandler

use of com.intellij.lang.ContextAwareActionHandler in project intellij-community by JetBrains.

the class PresentableActionHandlerBasedAction method update.

@Override
protected void update(@NotNull Presentation presentation, @NotNull Project project, @NotNull Editor editor, @NotNull PsiFile file, @NotNull DataContext dataContext, @Nullable String actionPlace) {
    // avoid evaluating isValidFor several times unnecessary
    CodeInsightActionHandler handler = getValidHandler(editor, file);
    presentation.setEnabled(handler != null);
    if (handler instanceof ContextAwareActionHandler && !ActionPlaces.isMainMenuOrActionSearch(actionPlace)) {
        presentation.setVisible(((ContextAwareActionHandler) handler).isAvailableForQuickList(editor, file, dataContext));
    }
    if (presentation.isVisible() && handler instanceof PresentableCodeInsightActionHandler) {
        ((PresentableCodeInsightActionHandler) handler).update(editor, file, presentation);
    }
}
Also used : CodeInsightActionHandler(com.intellij.codeInsight.CodeInsightActionHandler) LanguageCodeInsightActionHandler(com.intellij.lang.LanguageCodeInsightActionHandler) ContextAwareActionHandler(com.intellij.lang.ContextAwareActionHandler)

Example 3 with ContextAwareActionHandler

use of com.intellij.lang.ContextAwareActionHandler in project intellij-community by JetBrains.

the class ChangeSignatureAction method getRefactoringHandler.

@Nullable
@Override
protected RefactoringActionHandler getRefactoringHandler(@NotNull RefactoringSupportProvider provider, final PsiElement element) {
    abstract class ContextAwareChangeSignatureHandler implements RefactoringActionHandler, ContextAwareActionHandler {
    }
    return new ContextAwareChangeSignatureHandler() {

        @Override
        public boolean isAvailableForQuickList(@NotNull Editor editor, @NotNull PsiFile file, @NotNull DataContext dataContext) {
            return findTargetMember(element) != null;
        }

        @Override
        public void invoke(@NotNull Project project, Editor editor, PsiFile file, DataContext dataContext) {
            editor.getScrollingModel().scrollToCaret(ScrollType.MAKE_VISIBLE);
            final PsiElement targetMember = findTargetMember(element);
            if (targetMember == null) {
                final ChangeSignatureHandler handler = getChangeSignatureHandler(file.getLanguage());
                if (handler != null) {
                    final String notFoundMessage = handler.getTargetNotFoundMessage();
                    if (notFoundMessage != null) {
                        CommonRefactoringUtil.showErrorHint(project, editor, notFoundMessage, ChangeSignatureHandler.REFACTORING_NAME, null);
                    }
                }
                return;
            }
            final ChangeSignatureHandler handler = getChangeSignatureHandler(targetMember.getLanguage());
            if (handler == null)
                return;
            handler.invoke(project, new PsiElement[] { targetMember }, dataContext);
        }

        @Override
        public void invoke(@NotNull Project project, @NotNull PsiElement[] elements, DataContext dataContext) {
            if (elements.length != 1)
                return;
            final PsiElement targetMember = findTargetMember(elements[0]);
            if (targetMember == null)
                return;
            final ChangeSignatureHandler handler = getChangeSignatureHandler(targetMember.getLanguage());
            if (handler == null)
                return;
            handler.invoke(project, new PsiElement[] { targetMember }, dataContext);
        }
    };
}
Also used : Project(com.intellij.openapi.project.Project) DataContext(com.intellij.openapi.actionSystem.DataContext) ChangeSignatureHandler(com.intellij.refactoring.changeSignature.ChangeSignatureHandler) PsiFile(com.intellij.psi.PsiFile) RefactoringActionHandler(com.intellij.refactoring.RefactoringActionHandler) Editor(com.intellij.openapi.editor.Editor) ContextAwareActionHandler(com.intellij.lang.ContextAwareActionHandler) NotNull(org.jetbrains.annotations.NotNull) PsiElement(com.intellij.psi.PsiElement) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

ContextAwareActionHandler (com.intellij.lang.ContextAwareActionHandler)3 Editor (com.intellij.openapi.editor.Editor)2 RefactoringActionHandler (com.intellij.refactoring.RefactoringActionHandler)2 CodeInsightActionHandler (com.intellij.codeInsight.CodeInsightActionHandler)1 LanguageCodeInsightActionHandler (com.intellij.lang.LanguageCodeInsightActionHandler)1 DataContext (com.intellij.openapi.actionSystem.DataContext)1 Project (com.intellij.openapi.project.Project)1 PsiElement (com.intellij.psi.PsiElement)1 PsiFile (com.intellij.psi.PsiFile)1 ChangeSignatureHandler (com.intellij.refactoring.changeSignature.ChangeSignatureHandler)1 NotNull (org.jetbrains.annotations.NotNull)1 Nullable (org.jetbrains.annotations.Nullable)1