Search in sources :

Example 31 with TextEditor

use of com.intellij.openapi.fileEditor.TextEditor in project intellij-community by JetBrains.

the class CreateFileFix method openFile.

protected void openFile(@NotNull Project project, PsiDirectory directory, PsiFile newFile, String text) {
    final FileEditorManager editorManager = FileEditorManager.getInstance(directory.getProject());
    final FileEditor[] fileEditors = editorManager.openFile(newFile.getVirtualFile(), true);
    if (text != null) {
        for (FileEditor fileEditor : fileEditors) {
            if (fileEditor instanceof TextEditor) {
                // JSP is not safe to edit via Psi
                final Document document = ((TextEditor) fileEditor).getEditor().getDocument();
                document.setText(text);
                if (ApplicationManager.getApplication().isUnitTestMode()) {
                    FileDocumentManager.getInstance().saveDocument(document);
                }
                PsiDocumentManager.getInstance(project).commitDocument(document);
                break;
            }
        }
    }
}
Also used : FileEditorManager(com.intellij.openapi.fileEditor.FileEditorManager) FileEditor(com.intellij.openapi.fileEditor.FileEditor) TextEditor(com.intellij.openapi.fileEditor.TextEditor) Document(com.intellij.openapi.editor.Document)

Example 32 with TextEditor

use of com.intellij.openapi.fileEditor.TextEditor in project intellij-community by JetBrains.

the class DaemonRespondToChangesTest method testInterruptOnTyping.

public void testInterruptOnTyping() throws Throwable {
    @NonNls String filePath = "/psi/resolve/Thinlet.java";
    configureByFile(filePath);
    highlightErrors();
    final DaemonCodeAnalyzerImpl codeAnalyzer = (DaemonCodeAnalyzerImpl) DaemonCodeAnalyzer.getInstance(getProject());
    codeAnalyzer.restart();
    try {
        PsiDocumentManager.getInstance(myProject).commitAllDocuments();
        PsiFile file = getFile();
        Editor editor = getEditor();
        Project project = file.getProject();
        CodeInsightTestFixtureImpl.ensureIndexesUpToDate(project);
        TextEditor textEditor = TextEditorProvider.getInstance().getTextEditor(editor);
        codeAnalyzer.runPasses(file, editor.getDocument(), textEditor, ArrayUtil.EMPTY_INT_ARRAY, true, () -> type(' '));
    } catch (ProcessCanceledException ignored) {
        return;
    }
    fail("PCE must have been thrown");
}
Also used : NonNls(org.jetbrains.annotations.NonNls) Project(com.intellij.openapi.project.Project) TextEditor(com.intellij.openapi.fileEditor.TextEditor) TextEditor(com.intellij.openapi.fileEditor.TextEditor) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException)

Example 33 with TextEditor

use of com.intellij.openapi.fileEditor.TextEditor in project intellij-community by JetBrains.

the class DaemonRespondToChangesTest method checkDaemonReaction.

private void checkDaemonReaction(boolean mustCancelItself, @NotNull final Runnable action) {
    PsiDocumentManager.getInstance(getProject()).commitAllDocuments();
    highlightErrors();
    myDaemonCodeAnalyzer.waitForTermination();
    TextEditor textEditor = TextEditorProvider.getInstance().getTextEditor(getEditor());
    final AtomicBoolean run = new AtomicBoolean();
    Disposable disposable = Disposer.newDisposable();
    final AtomicReference<RuntimeException> stopDaemonReason = new AtomicReference<>();
    StorageUtilKt.setDEBUG_LOG("");
    getProject().getMessageBus().connect(disposable).subscribe(DaemonCodeAnalyzer.DAEMON_EVENT_TOPIC, new DaemonCodeAnalyzer.DaemonListenerAdapter() {

        @Override
        public void daemonCancelEventOccurred(@NotNull String reason) {
            RuntimeException e = new RuntimeException("Some bastard's restarted daemon: " + reason + "\nStorage write log: ----------\n" + StorageUtilKt.getDEBUG_LOG() + "\n--------------");
            stopDaemonReason.compareAndSet(null, e);
        }
    });
    try {
        while (true) {
            try {
                myDaemonCodeAnalyzer.runPasses(getFile(), getDocument(getFile()), textEditor, new int[0], true, () -> {
                    if (!run.getAndSet(true)) {
                        action.run();
                    }
                });
                break;
            } catch (ProcessCanceledException ignored) {
            }
        }
        if (mustCancelItself) {
            assertNotNull(stopDaemonReason.get());
        } else {
            if (stopDaemonReason.get() != null)
                throw stopDaemonReason.get();
        }
    } finally {
        StorageUtilKt.setDEBUG_LOG(null);
        Disposer.dispose(disposable);
    }
}
Also used : Disposable(com.intellij.openapi.Disposable) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TextEditor(com.intellij.openapi.fileEditor.TextEditor) AtomicReference(java.util.concurrent.atomic.AtomicReference) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException)

Example 34 with TextEditor

use of com.intellij.openapi.fileEditor.TextEditor in project intellij-community by JetBrains.

the class DvcsUtil method getSelectedFile.

/**
   * Returns the currently selected file, based on which VcsBranch or StatusBar components will identify the current repository root.
   */
@Nullable
@CalledInAwt
public static VirtualFile getSelectedFile(@NotNull Project project) {
    StatusBar statusBar = WindowManager.getInstance().getStatusBar(project);
    final FileEditor fileEditor = StatusBarUtil.getCurrentFileEditor(project, statusBar);
    VirtualFile result = null;
    if (fileEditor != null) {
        if (fileEditor instanceof TextEditor) {
            Document document = ((TextEditor) fileEditor).getEditor().getDocument();
            result = FileDocumentManager.getInstance().getFile(document);
        } else if (fileEditor instanceof ImageFileEditor) {
            result = ((ImageFileEditor) fileEditor).getImageEditor().getFile();
        }
    }
    if (result == null) {
        final FileEditorManager manager = FileEditorManager.getInstance(project);
        if (manager != null) {
            Editor editor = manager.getSelectedTextEditor();
            if (editor != null) {
                result = FileDocumentManager.getInstance().getFile(editor.getDocument());
            }
        }
    }
    return result;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ImageFileEditor(org.intellij.images.editor.ImageFileEditor) FileEditorManager(com.intellij.openapi.fileEditor.FileEditorManager) ImageFileEditor(org.intellij.images.editor.ImageFileEditor) FileEditor(com.intellij.openapi.fileEditor.FileEditor) TextEditor(com.intellij.openapi.fileEditor.TextEditor) Document(com.intellij.openapi.editor.Document) TextEditor(com.intellij.openapi.fileEditor.TextEditor) ImageFileEditor(org.intellij.images.editor.ImageFileEditor) FileEditor(com.intellij.openapi.fileEditor.FileEditor) Editor(com.intellij.openapi.editor.Editor) StatusBar(com.intellij.openapi.wm.StatusBar) CalledInAwt(org.jetbrains.annotations.CalledInAwt) Nullable(org.jetbrains.annotations.Nullable)

Example 35 with TextEditor

use of com.intellij.openapi.fileEditor.TextEditor in project android by JetBrains.

the class AndroidCodeStyleNotificationProvider method createNotificationPanel.

@Nullable
@Override
public MyPanel createNotificationPanel(@NotNull VirtualFile file, @NotNull FileEditor fileEditor) {
    if (file.getFileType() != XmlFileType.INSTANCE || !(fileEditor instanceof TextEditor)) {
        return null;
    }
    final Module module = ModuleUtilCore.findModuleForFile(file, myProject);
    if (module == null) {
        return null;
    }
    final AndroidFacet facet = AndroidFacet.getInstance(module);
    if (facet == null) {
        return null;
    }
    final VirtualFile parent = file.getParent();
    final VirtualFile resDir = parent != null ? parent.getParent() : null;
    if (resDir == null || !facet.getLocalResourceManager().isResourceDir(resDir)) {
        return null;
    }
    final CodeStyleSettings settings = CodeStyleSettingsManager.getSettings(myProject);
    final AndroidXmlCodeStyleSettings androidSettings = AndroidXmlCodeStyleSettings.getInstance(settings);
    if (androidSettings.USE_CUSTOM_SETTINGS) {
        return null;
    }
    if (NotificationsConfigurationImpl.getSettings(ANDROID_XML_CODE_STYLE_NOTIFICATION_GROUP).getDisplayType() == NotificationDisplayType.NONE) {
        return null;
    }
    NotificationsConfiguration.getNotificationsConfiguration().register(ANDROID_XML_CODE_STYLE_NOTIFICATION_GROUP, NotificationDisplayType.BALLOON, false);
    return new MyPanel();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) CodeStyleSettings(com.intellij.psi.codeStyle.CodeStyleSettings) TextEditor(com.intellij.openapi.fileEditor.TextEditor) Module(com.intellij.openapi.module.Module) AndroidFacet(org.jetbrains.android.facet.AndroidFacet) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

TextEditor (com.intellij.openapi.fileEditor.TextEditor)81 FileEditor (com.intellij.openapi.fileEditor.FileEditor)57 Editor (com.intellij.openapi.editor.Editor)32 VirtualFile (com.intellij.openapi.vfs.VirtualFile)28 Project (com.intellij.openapi.project.Project)21 Document (com.intellij.openapi.editor.Document)14 FileEditorManager (com.intellij.openapi.fileEditor.FileEditorManager)13 Nullable (org.jetbrains.annotations.Nullable)13 PsiFile (com.intellij.psi.PsiFile)11 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)6 NotNull (org.jetbrains.annotations.NotNull)6 Disposable (com.intellij.openapi.Disposable)3 EditorEx (com.intellij.openapi.editor.ex.EditorEx)3 EditorNotificationPanel (com.intellij.ui.EditorNotificationPanel)3 LightweightHint (com.intellij.ui.LightweightHint)3 NonNls (org.jetbrains.annotations.NonNls)3 HighlightingPass (com.intellij.codeHighlighting.HighlightingPass)2 TextEditorHighlightingPass (com.intellij.codeHighlighting.TextEditorHighlightingPass)2 TemplateBuilder (com.intellij.codeInsight.template.TemplateBuilder)2 UndoManager (com.intellij.openapi.command.undo.UndoManager)2