Search in sources :

Example 56 with FileEditor

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

the class CopyHandler method updateSelectionInActiveProjectView.

static void updateSelectionInActiveProjectView(PsiElement newElement, Project project, boolean selectInActivePanel) {
    String id = ToolWindowManager.getInstance(project).getActiveToolWindowId();
    if (id != null) {
        ToolWindow window = ToolWindowManager.getInstance(project).getToolWindow(id);
        Content selectedContent = window.getContentManager().getSelectedContent();
        if (selectedContent != null) {
            JComponent component = selectedContent.getComponent();
            if (component instanceof TwoPaneIdeView) {
                ((TwoPaneIdeView) component).selectElement(newElement, selectInActivePanel);
                return;
            }
        }
    }
    if (ToolWindowId.PROJECT_VIEW.equals(id)) {
        ProjectView.getInstance(project).selectPsiElement(newElement, true);
    } else if (ToolWindowId.STRUCTURE_VIEW.equals(id)) {
        VirtualFile virtualFile = newElement.getContainingFile().getVirtualFile();
        FileEditor editor = FileEditorManager.getInstance(newElement.getProject()).getSelectedEditor(virtualFile);
        StructureViewFactoryEx.getInstanceEx(project).getStructureViewWrapper().selectCurrentElement(editor, virtualFile, true);
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ToolWindow(com.intellij.openapi.wm.ToolWindow) FileEditor(com.intellij.openapi.fileEditor.FileEditor) Content(com.intellij.ui.content.Content) TwoPaneIdeView(com.intellij.ide.TwoPaneIdeView)

Example 57 with FileEditor

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

the class IntentionWrapper method applyFix.

@Override
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
    VirtualFile virtualFile = myFile.getVirtualFile();
    if (virtualFile != null) {
        FileEditor editor = FileEditorManager.getInstance(project).getSelectedEditor(virtualFile);
        myAction.invoke(project, editor instanceof TextEditor ? ((TextEditor) editor).getEditor() : null, myFile);
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FileEditor(com.intellij.openapi.fileEditor.FileEditor) TextEditor(com.intellij.openapi.fileEditor.TextEditor)

Example 58 with FileEditor

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

the class EditorOptionsPanel method clearAllIdentifierHighlighters.

private static void clearAllIdentifierHighlighters() {
    for (Project project : ProjectManager.getInstance().getOpenProjects()) {
        for (FileEditor fileEditor : FileEditorManager.getInstance(project).getAllEditors()) {
            if (fileEditor instanceof TextEditor) {
                Document document = ((TextEditor) fileEditor).getEditor().getDocument();
                IdentifierHighlighterPass.clearMyHighlights(document, project);
            }
        }
    }
}
Also used : Project(com.intellij.openapi.project.Project) FileEditor(com.intellij.openapi.fileEditor.FileEditor) TextEditor(com.intellij.openapi.fileEditor.TextEditor) Document(com.intellij.openapi.editor.Document)

Example 59 with FileEditor

use of com.intellij.openapi.fileEditor.FileEditor 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 60 with FileEditor

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

the class SdkSetupNotificationTestBase method configureBySdkAndText.

protected EditorNotificationPanel configureBySdkAndText(@Nullable Sdk sdk, boolean moduleSdk, @NotNull String name, @NotNull String text) {
    final PsiFile psiFile = myFixture.configureByText(name, text);
    final FileEditor[] editors = FileEditorManagerEx.getInstanceEx(getProject()).openFile(psiFile.getVirtualFile(), true);
    assertSize(1, editors);
    if (moduleSdk) {
        ModuleRootModificationUtil.setModuleSdk(myModule, sdk);
    } else {
        setProjectSdk(sdk);
        ModuleRootModificationUtil.setSdkInherited(myModule);
    }
    return editors[0].getUserData(SdkSetupNotificationProvider.KEY);
}
Also used : FileEditor(com.intellij.openapi.fileEditor.FileEditor) PsiFile(com.intellij.psi.PsiFile)

Aggregations

FileEditor (com.intellij.openapi.fileEditor.FileEditor)140 TextEditor (com.intellij.openapi.fileEditor.TextEditor)54 VirtualFile (com.intellij.openapi.vfs.VirtualFile)53 Editor (com.intellij.openapi.editor.Editor)41 Project (com.intellij.openapi.project.Project)34 FileEditorManager (com.intellij.openapi.fileEditor.FileEditorManager)27 DataContext (com.intellij.openapi.actionSystem.DataContext)20 Nullable (org.jetbrains.annotations.Nullable)19 PsiFile (com.intellij.psi.PsiFile)16 Document (com.intellij.openapi.editor.Document)14 IpnbFileEditor (org.jetbrains.plugins.ipnb.editor.IpnbFileEditor)14 NotNull (org.jetbrains.annotations.NotNull)13 OpenFileDescriptor (com.intellij.openapi.fileEditor.OpenFileDescriptor)9 IpnbFilePanel (org.jetbrains.plugins.ipnb.editor.panels.IpnbFilePanel)8 StructureViewBuilder (com.intellij.ide.structureView.StructureViewBuilder)6 StructureViewComponent (com.intellij.ide.structureView.newStructureView.StructureViewComponent)6 StructureViewComposite (com.intellij.ide.structureView.impl.StructureViewComposite)5 FileEditorManagerEx (com.intellij.openapi.fileEditor.ex.FileEditorManagerEx)5 PsiElement (com.intellij.psi.PsiElement)5 List (java.util.List)5