Search in sources :

Example 16 with EditorImpl

use of com.intellij.openapi.editor.impl.EditorImpl in project intellij-community by JetBrains.

the class FormatterTestCase method checkDocument.

protected void checkDocument(final PsiFile file, final String text, String textAfter) {
    final Document document = PsiDocumentManager.getInstance(getProject()).getDocument(file);
    final EditorImpl editor;
    if (doCheckDocumentUpdate()) {
        editor = (EditorImpl) FileEditorManager.getInstance(getProject()).openTextEditor(new OpenFileDescriptor(getProject(), file.getVirtualFile(), 0), false);
        editor.putUserData(EditorImpl.DO_DOCUMENT_UPDATE_TEST, Boolean.TRUE);
        if (myFile != null) {
            FileEditorManager.getInstance(getProject()).closeFile(myFile.getVirtualFile());
        }
        myEditor = editor;
        myFile = file;
    } else {
        editor = null;
    }
    WriteCommandAction.runWriteCommandAction(getProject(), () -> {
        document.replaceString(0, document.getTextLength(), text);
        PsiDocumentManager.getInstance(getProject()).commitDocument(document);
        assertEquals(file.getText(), document.getText());
        try {
            if (doReformatRangeTest) {
                CodeStyleManager.getInstance(getProject()).reformatRange(file, file.getTextRange().getStartOffset(), file.getTextRange().getEndOffset());
            } else if (myTextRange != null) {
                CodeStyleManager.getInstance(getProject()).reformatText(file, myTextRange.getStartOffset(), myTextRange.getEndOffset());
            } else {
                CodeStyleManager.getInstance(getProject()).reformatText(file, file.getTextRange().getStartOffset(), file.getTextRange().getEndOffset());
            }
        } catch (IncorrectOperationException e) {
            fail();
        }
    });
    assertEquals(textAfter, document.getText());
    PsiDocumentManager.getInstance(getProject()).commitDocument(document);
    assertEquals(textAfter, file.getText());
}
Also used : EditorImpl(com.intellij.openapi.editor.impl.EditorImpl) OpenFileDescriptor(com.intellij.openapi.fileEditor.OpenFileDescriptor) IncorrectOperationException(com.intellij.util.IncorrectOperationException) Document(com.intellij.openapi.editor.Document)

Example 17 with EditorImpl

use of com.intellij.openapi.editor.impl.EditorImpl in project intellij-community by JetBrains.

the class AbstractValueHint method showHint.

protected boolean showHint(final JComponent component) {
    myInsideShow = true;
    if (myCurrentHint != null) {
        myCurrentHint.hide();
    }
    myCurrentHint = new LightweightHint(component) {

        @Override
        protected boolean canAutoHideOn(TooltipEvent event) {
            InputEvent inputEvent = event.getInputEvent();
            if (inputEvent instanceof MouseEvent) {
                Component comp = inputEvent.getComponent();
                if (comp instanceof EditorComponentImpl) {
                    EditorImpl editor = ((EditorComponentImpl) comp).getEditor();
                    return !isInsideCurrentRange(editor, ((MouseEvent) inputEvent).getPoint());
                }
            }
            return true;
        }
    };
    myCurrentHint.addHintListener(new HintListener() {

        @Override
        public void hintHidden(EventObject event) {
            if (myHideRunnable != null && !myInsideShow) {
                myHideRunnable.run();
            }
            onHintHidden();
        }
    });
    // editor may be disposed before later invokator process this action
    if (myEditor.isDisposed() || myEditor.getComponent().getRootPane() == null) {
        return false;
    }
    Point p = HintManagerImpl.getHintPosition(myCurrentHint, myEditor, myEditor.xyToLogicalPosition(myPoint), HintManager.UNDER);
    HintHint hint = HintManagerImpl.createHintHint(myEditor, p, myCurrentHint, HintManager.UNDER, true);
    hint.setShowImmediately(true);
    HintManagerImpl.getInstanceImpl().showEditorHint(myCurrentHint, myEditor, p, HintManager.HIDE_BY_ANY_KEY | HintManager.HIDE_BY_TEXT_CHANGE | HintManager.HIDE_BY_SCROLLING, 0, false, hint);
    myInsideShow = false;
    return true;
}
Also used : EditorMouseEvent(com.intellij.openapi.editor.event.EditorMouseEvent) TooltipEvent(com.intellij.ide.TooltipEvent) EditorComponentImpl(com.intellij.openapi.editor.impl.EditorComponentImpl) EditorImpl(com.intellij.openapi.editor.impl.EditorImpl) RelativePoint(com.intellij.ui.awt.RelativePoint) EventObject(java.util.EventObject)

Example 18 with EditorImpl

use of com.intellij.openapi.editor.impl.EditorImpl in project intellij-community by JetBrains.

the class CoverageLineMarkerRenderer method showHint.

private void showHint(final Editor editor, final Point point, final int lineNumber) {
    final JPanel panel = new JPanel(new BorderLayout());
    panel.add(createActionsToolbar(editor, lineNumber), BorderLayout.NORTH);
    final LineData lineData = getLineData(lineNumber);
    final EditorImpl uEditor;
    if (lineData != null && lineData.getStatus() != LineCoverage.NONE && !mySubCoverageActive) {
        final EditorFactory factory = EditorFactory.getInstance();
        final Document doc = factory.createDocument(getReport(editor, lineNumber));
        doc.setReadOnly(true);
        uEditor = (EditorImpl) factory.createEditor(doc, editor.getProject());
        panel.add(EditorFragmentComponent.createEditorFragmentComponent(uEditor, 0, doc.getLineCount(), false, false), BorderLayout.CENTER);
    } else {
        uEditor = null;
    }
    final LightweightHint hint = new LightweightHint(panel) {

        @Override
        public void hide() {
            if (uEditor != null)
                EditorFactory.getInstance().releaseEditor(uEditor);
            super.hide();
        }
    };
    HintManagerImpl.getInstanceImpl().showEditorHint(hint, editor, point, HintManagerImpl.HIDE_BY_ANY_KEY | HintManagerImpl.HIDE_BY_TEXT_CHANGE | HintManagerImpl.HIDE_BY_OTHER_HINT | HintManagerImpl.HIDE_BY_SCROLLING, -1, false, new HintHint(editor, point));
}
Also used : LineData(com.intellij.rt.coverage.data.LineData) EditorFactory(com.intellij.openapi.editor.EditorFactory) HintHint(com.intellij.ui.HintHint) EditorImpl(com.intellij.openapi.editor.impl.EditorImpl) LightweightHint(com.intellij.ui.LightweightHint) Document(com.intellij.openapi.editor.Document)

Example 19 with EditorImpl

use of com.intellij.openapi.editor.impl.EditorImpl in project intellij-plugins by JetBrains.

the class SwfHighlightingTest method testLineMarkersInSwf.

@JSTestOptions({ JSTestOption.WithFlexFacet, JSTestOption.WithLineMarkers })
public void testLineMarkersInSwf() throws Exception {
    final String testName = getTestName(false);
    myAfterCommitRunnable = () -> FlexTestUtils.addLibrary(myModule, "lib", getTestDataPath() + getBasePath() + "/", testName + ".swc", null, null);
    // actual test data is in library.swf; this file is here just because we need any file
    configureByFile("/" + testName + ".as");
    VirtualFile vFile = LocalFileSystem.getInstance().findFileByPath(getTestDataPath() + getBasePath() + "/" + testName + ".swc");
    vFile = JarFileSystem.getInstance().getJarRootForLocalFile(vFile).findChild("library.swf");
    myEditor = FileEditorManager.getInstance(myProject).openTextEditor(new OpenFileDescriptor(myProject, vFile, 0), false);
    PsiDocumentManager.getInstance(getProject()).commitAllDocuments();
    myFile = myPsiManager.findFile(vFile);
    ((EditorImpl) myEditor).setCaretActive();
    vFile = LocalFileSystem.getInstance().findFileByPath(getTestDataPath() + getBasePath() + "/" + testName + ".as");
    final String verificationText = StreamUtil.convertSeparators(VfsUtilCore.loadText(vFile));
    checkHighlighting(new ExpectedHighlightingData(new DocumentImpl(verificationText), false, false, true, myFile));
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ExpectedHighlightingData(com.intellij.testFramework.ExpectedHighlightingData) EditorImpl(com.intellij.openapi.editor.impl.EditorImpl) OpenFileDescriptor(com.intellij.openapi.fileEditor.OpenFileDescriptor) DocumentImpl(com.intellij.openapi.editor.impl.DocumentImpl) JSTestOptions(com.intellij.lang.javascript.JSTestOptions)

Example 20 with EditorImpl

use of com.intellij.openapi.editor.impl.EditorImpl in project intellij-plugins by JetBrains.

the class SwfHighlightingTest method testProtectSwf.

public void testProtectSwf() throws Exception {
    configureByFiles((String) null);
    VirtualFile vFile = LocalFileSystem.getInstance().findFileByPath(getTestDataPath() + getBasePath() + "/" + getTestName(false) + ".swf");
    myEditor = FileEditorManager.getInstance(myProject).openTextEditor(new OpenFileDescriptor(myProject, vFile, 0), false);
    PsiDocumentManager.getInstance(getProject()).commitAllDocuments();
    myFile = myPsiManager.findFile(vFile);
    ((EditorImpl) myEditor).setCaretActive();
    assertFalse(FileDocumentManager.getInstance().requestWriting(myEditor.getDocument(), myProject));
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) EditorImpl(com.intellij.openapi.editor.impl.EditorImpl) OpenFileDescriptor(com.intellij.openapi.fileEditor.OpenFileDescriptor)

Aggregations

EditorImpl (com.intellij.openapi.editor.impl.EditorImpl)34 OpenFileDescriptor (com.intellij.openapi.fileEditor.OpenFileDescriptor)8 Editor (com.intellij.openapi.editor.Editor)7 LightweightHint (com.intellij.ui.LightweightHint)6 Document (com.intellij.openapi.editor.Document)5 VirtualFile (com.intellij.openapi.vfs.VirtualFile)4 EditorMouseFixture (com.intellij.testFramework.fixtures.EditorMouseFixture)3 NotNull (org.jetbrains.annotations.NotNull)3 IntentionHintComponent (com.intellij.codeInsight.intention.impl.IntentionHintComponent)2 Result (com.intellij.openapi.application.Result)2 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)2 SoftWrap (com.intellij.openapi.editor.SoftWrap)2 EditorEx (com.intellij.openapi.editor.ex.EditorEx)2 FoldingModelEx (com.intellij.openapi.editor.ex.FoldingModelEx)2 SoftWrapModelImpl (com.intellij.openapi.editor.impl.SoftWrapModelImpl)2 FileEditorManager (com.intellij.openapi.fileEditor.FileEditorManager)2 TextEditor (com.intellij.openapi.fileEditor.TextEditor)2 Project (com.intellij.openapi.project.Project)2 HintHint (com.intellij.ui.HintHint)2 EditorHintListener (com.intellij.codeInsight.hint.EditorHintListener)1