Search in sources :

Example 6 with CodeInsightActionHandler

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

the class CodeInsightAction method actionPerformedImpl.

public void actionPerformedImpl(@NotNull final Project project, final Editor editor) {
    if (editor == null)
        return;
    //final PsiFile psiFile = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument());
    final PsiFile psiFile = PsiUtilBase.getPsiFileInEditor(editor, project);
    if (psiFile == null)
        return;
    final CodeInsightActionHandler handler = getHandler();
    PsiElement elementToMakeWritable = handler.getElementToMakeWritable(psiFile);
    if (elementToMakeWritable != null && !(EditorModificationUtil.checkModificationAllowed(editor) && FileModificationService.getInstance().preparePsiElementsForWrite(elementToMakeWritable))) {
        return;
    }
    CommandProcessor.getInstance().executeCommand(project, () -> {
        final Runnable action = () -> {
            if (!ApplicationManager.getApplication().isUnitTestMode() && !editor.getContentComponent().isShowing())
                return;
            handler.invoke(project, editor, psiFile);
        };
        if (handler.startInWriteAction()) {
            ApplicationManager.getApplication().runWriteAction(action);
        } else {
            action.run();
        }
    }, getCommandName(), DocCommandGroupId.noneGroupId(editor.getDocument()));
}
Also used : CodeInsightActionHandler(com.intellij.codeInsight.CodeInsightActionHandler) PsiFile(com.intellij.psi.PsiFile) PsiElement(com.intellij.psi.PsiElement)

Example 7 with CodeInsightActionHandler

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

the class GroovyGoToSuperTest method doTest.

private void doTest() throws Throwable {
    final List<String> data = TestUtils.readInput(getTestDataPath() + getTestName(true) + ".test");
    myFixture.configureByText(GroovyFileType.GROOVY_FILE_TYPE, data.get(0));
    final CodeInsightActionHandler handler = CodeInsightActions.GOTO_SUPER.forLanguage(GroovyLanguage.INSTANCE);
    handler.invoke(getProject(), myFixture.getEditor(), myFixture.getFile());
    myFixture.checkResult(data.get(1));
}
Also used : CodeInsightActionHandler(com.intellij.codeInsight.CodeInsightActionHandler)

Example 8 with CodeInsightActionHandler

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

the class GenerateDTDAction method getHandler.

@Override
@NotNull
protected CodeInsightActionHandler getHandler() {
    return new CodeInsightActionHandler() {

        @Override
        public void invoke(@NotNull Project project, @NotNull Editor editor, @NotNull PsiFile file) {
            final XmlDocument document = findSuitableXmlDocument(file);
            if (document != null) {
                @NonNls final StringBuilder buffer = new StringBuilder();
                buffer.append("<!DOCTYPE " + document.getRootTag().getName() + " [\n");
                buffer.append(XmlUtil.generateDocumentDTD(document, true));
                buffer.append("]>\n");
                XmlFile tempFile;
                try {
                    final XmlProlog prolog = document.getProlog();
                    final PsiElement childOfType = PsiTreeUtil.getChildOfType(prolog, XmlProcessingInstruction.class);
                    if (childOfType != null) {
                        final String text = childOfType.getText();
                        buffer.insert(0, text);
                        final PsiElement nextSibling = childOfType.getNextSibling();
                        if (nextSibling instanceof PsiWhiteSpace) {
                            buffer.insert(text.length(), nextSibling.getText());
                        }
                    }
                    tempFile = (XmlFile) PsiFileFactory.getInstance(file.getProject()).createFileFromText("dummy.xml", buffer.toString());
                    prolog.replace(tempFile.getDocument().getProlog());
                } catch (IncorrectOperationException e) {
                    LOG.error(e);
                }
            }
        }
    };
}
Also used : NonNls(org.jetbrains.annotations.NonNls) XmlFile(com.intellij.psi.xml.XmlFile) CodeInsightActionHandler(com.intellij.codeInsight.CodeInsightActionHandler) XmlDocument(com.intellij.psi.xml.XmlDocument) XmlProlog(com.intellij.psi.xml.XmlProlog) NotNull(org.jetbrains.annotations.NotNull) Project(com.intellij.openapi.project.Project) PsiFile(com.intellij.psi.PsiFile) IncorrectOperationException(com.intellij.util.IncorrectOperationException) Editor(com.intellij.openapi.editor.Editor) PsiElement(com.intellij.psi.PsiElement) PsiWhiteSpace(com.intellij.psi.PsiWhiteSpace) NotNull(org.jetbrains.annotations.NotNull)

Example 9 with CodeInsightActionHandler

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

the class DartServerGotoSuperHandlerTest method doTest.

private void doTest() throws Throwable {
    myFixture.configureByFile(getTestName(false) + ".dart");
    initServer();
    final CodeInsightActionHandler handler = CodeInsightActions.GOTO_SUPER.forLanguage(DartLanguage.INSTANCE);
    handler.invoke(getProject(), myFixture.getEditor(), myFixture.getFile());
    myFixture.checkResultByFile(getTestName(false) + ".after.dart");
}
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