Search in sources :

Example 1 with CodeInsightActionHandler

use of com.intellij.codeInsight.CodeInsightActionHandler in project intellij-community by JetBrains.

the class GotoSuperAction method invoke.

@Override
public void invoke(@NotNull final Project project, @NotNull final Editor editor, @NotNull final PsiFile file) {
    int offset = editor.getCaretModel().getOffset();
    final Language language = PsiUtilCore.getLanguageAtOffset(file, offset);
    final CodeInsightActionHandler codeInsightActionHandler = CodeInsightActions.GOTO_SUPER.forLanguage(language);
    if (codeInsightActionHandler != null) {
        DumbService.getInstance(project).withAlternativeResolveEnabled(() -> codeInsightActionHandler.invoke(project, editor, file));
    }
}
Also used : Language(com.intellij.lang.Language) CodeInsightActionHandler(com.intellij.codeInsight.CodeInsightActionHandler)

Example 2 with CodeInsightActionHandler

use of com.intellij.codeInsight.CodeInsightActionHandler in project intellij-community by JetBrains.

the class OverrideImplementUtil method registerHandlerForComplementaryAction.

private static void registerHandlerForComplementaryAction(final Project project, final Editor editor, final PsiElement aClass, final boolean toImplement, final MemberChooser<PsiMethodMember> chooser) {
    final JComponent preferredFocusedComponent = chooser.getPreferredFocusedComponent();
    final Keymap keymap = KeymapManager.getInstance().getActiveKeymap();
    @NonNls final String s = toImplement ? "OverrideMethods" : "ImplementMethods";
    final Shortcut[] shortcuts = keymap.getShortcuts(s);
    if (shortcuts.length > 0 && shortcuts[0] instanceof KeyboardShortcut) {
        preferredFocusedComponent.getInputMap().put(((KeyboardShortcut) shortcuts[0]).getFirstKeyStroke(), s);
        preferredFocusedComponent.getActionMap().put(s, new AbstractAction() {

            @Override
            public void actionPerformed(final ActionEvent e) {
                chooser.close(DialogWrapper.CANCEL_EXIT_CODE);
                // invoke later in order to close previous modal dialog
                TransactionGuard.getInstance().submitTransactionLater(project, () -> {
                    CodeInsightActionHandler handler = toImplement ? new OverrideMethodsHandler() : new ImplementMethodsHandler();
                    handler.invoke(project, editor, aClass.getContainingFile());
                });
            }
        });
    }
}
Also used : NonNls(org.jetbrains.annotations.NonNls) CodeInsightActionHandler(com.intellij.codeInsight.CodeInsightActionHandler) ActionEvent(java.awt.event.ActionEvent) KeyboardShortcut(com.intellij.openapi.actionSystem.KeyboardShortcut) Shortcut(com.intellij.openapi.actionSystem.Shortcut) KeyboardShortcut(com.intellij.openapi.actionSystem.KeyboardShortcut) Keymap(com.intellij.openapi.keymap.Keymap)

Example 3 with CodeInsightActionHandler

use of com.intellij.codeInsight.CodeInsightActionHandler 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 4 with CodeInsightActionHandler

use of com.intellij.codeInsight.CodeInsightActionHandler in project intellij-community by JetBrains.

the class PresentableActionHandlerBasedAction method getValidHandler.

@Nullable
private CodeInsightActionHandler getValidHandler(@NotNull Editor editor, @NotNull PsiFile file) {
    Language language = PsiUtilCore.getLanguageAtOffset(file, editor.getCaretModel().getOffset());
    final CodeInsightActionHandler codeInsightActionHandler = getLanguageExtension().forLanguage(language);
    if (codeInsightActionHandler != null) {
        if (codeInsightActionHandler instanceof LanguageCodeInsightActionHandler) {
            if (((LanguageCodeInsightActionHandler) codeInsightActionHandler).isValidFor(editor, file)) {
                return codeInsightActionHandler;
            }
        } else {
            return codeInsightActionHandler;
        }
    }
    return null;
}
Also used : Language(com.intellij.lang.Language) CodeInsightActionHandler(com.intellij.codeInsight.CodeInsightActionHandler) LanguageCodeInsightActionHandler(com.intellij.lang.LanguageCodeInsightActionHandler) LanguageCodeInsightActionHandler(com.intellij.lang.LanguageCodeInsightActionHandler) Nullable(org.jetbrains.annotations.Nullable)

Example 5 with CodeInsightActionHandler

use of com.intellij.codeInsight.CodeInsightActionHandler in project intellij-community by JetBrains.

the class JavaGotoSuperTest method doTest.

private void doTest() {
    configureByFile(getBasePath() + getTestName(false) + ".java");
    final CodeInsightActionHandler handler = CodeInsightActions.GOTO_SUPER.forLanguage(JavaLanguage.INSTANCE);
    handler.invoke(getProject(), getEditor(), getFile());
    checkResultByFile(getBasePath() + getTestName(false) + ".after.java");
}
Also used : CodeInsightActionHandler(com.intellij.codeInsight.CodeInsightActionHandler)

Aggregations

CodeInsightActionHandler (com.intellij.codeInsight.CodeInsightActionHandler)9 Language (com.intellij.lang.Language)2 LanguageCodeInsightActionHandler (com.intellij.lang.LanguageCodeInsightActionHandler)2 PsiElement (com.intellij.psi.PsiElement)2 PsiFile (com.intellij.psi.PsiFile)2 NonNls (org.jetbrains.annotations.NonNls)2 ContextAwareActionHandler (com.intellij.lang.ContextAwareActionHandler)1 KeyboardShortcut (com.intellij.openapi.actionSystem.KeyboardShortcut)1 Shortcut (com.intellij.openapi.actionSystem.Shortcut)1 Editor (com.intellij.openapi.editor.Editor)1 Keymap (com.intellij.openapi.keymap.Keymap)1 Project (com.intellij.openapi.project.Project)1 PsiWhiteSpace (com.intellij.psi.PsiWhiteSpace)1 XmlDocument (com.intellij.psi.xml.XmlDocument)1 XmlFile (com.intellij.psi.xml.XmlFile)1 XmlProlog (com.intellij.psi.xml.XmlProlog)1 IncorrectOperationException (com.intellij.util.IncorrectOperationException)1 ActionEvent (java.awt.event.ActionEvent)1 NotNull (org.jetbrains.annotations.NotNull)1 Nullable (org.jetbrains.annotations.Nullable)1