Search in sources :

Example 31 with FileEditorManager

use of com.intellij.openapi.fileEditor.FileEditorManager in project intellij-plugins by JetBrains.

the class BaseEditorAction method update.

public void update(AnActionEvent e) {
    FileEditorManager editorManager = FileEditorManager.getInstance(getProject(e));
    Editor editor = editorManager.getSelectedTextEditor();
    T command = getCommand(e);
    MutablePicoContainer container = getContainer(e);
    if (command != null && editor != null && container != null) {
        VirtualFile file = FileDocumentManager.getInstance().getFile(editor.getDocument());
        if (file != null) {
            VFile vFile = VFSUtil.createFileFrom(file, editor.getProject());
            if (vFile == null) {
                return;
            }
            command.setVFile(vFile);
            setUser(container, command);
            prepareCommand(command, editor, container);
        }
    }
    super.update(e);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FileEditorManager(com.intellij.openapi.fileEditor.FileEditorManager) MutablePicoContainer(org.picocontainer.MutablePicoContainer) Editor(com.intellij.openapi.editor.Editor) VFile(jetbrains.communicator.core.vfs.VFile)

Example 32 with FileEditorManager

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

the class EditorFixture method selectEditorTab.

/**
   * Selects the given tab in the current editor. Used to switch between
   * design mode and editor mode for example.
   *
   * @param tab the tab to switch to
   */
public EditorFixture selectEditorTab(@NotNull final Tab tab) {
    String tabName = tab.myTabName;
    execute(new GuiTask() {

        @Override
        protected void executeInEDT() throws Throwable {
            VirtualFile currentFile = getCurrentFile();
            assertNotNull("Can't switch to tab " + tabName + " when no file is open in the editor", currentFile);
            FileEditorManager manager = FileEditorManager.getInstance(myFrame.getProject());
            FileEditor[] editors = manager.getAllEditors(currentFile);
            FileEditor target = null;
            for (FileEditor editor : editors) {
                if (tabName == null || tabName.equals(editor.getName())) {
                    target = editor;
                    break;
                }
            }
            if (target != null) {
                // Have to use reflection
                //FileEditorManagerImpl#setSelectedEditor(final FileEditor editor)
                method("setSelectedEditor").withParameterTypes(FileEditor.class).in(manager).invoke(target);
                return;
            }
            List<String> tabNames = Lists.newArrayList();
            for (FileEditor editor : editors) {
                tabNames.add(editor.getName());
            }
            fail("Could not find editor tab \"" + (tabName != null ? tabName : "<default>") + "\": Available tabs = " + tabNames);
        }
    });
    return this;
}
Also used : GuiTask(org.fest.swing.edt.GuiTask) VirtualFile(com.intellij.openapi.vfs.VirtualFile) FileEditorManager(com.intellij.openapi.fileEditor.FileEditorManager) FileEditor(com.intellij.openapi.fileEditor.FileEditor) List(java.util.List) JBList(com.intellij.ui.components.JBList)

Example 33 with FileEditorManager

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

the class EditorFixture method open.

/**
   * Opens up a different file. This will run through the "Open File..." dialog to
   * find and select the given file.
   *
   * @param file the file to open
   * @param tab which tab to open initially, if there are multiple editors
   */
public EditorFixture open(@NotNull final VirtualFile file, @NotNull final Tab tab) {
    execute(new GuiTask() {

        @Override
        protected void executeInEDT() throws Throwable {
            // TODO: Use UI to navigate to the file instead
            Project project = myFrame.getProject();
            FileEditorManager manager = FileEditorManager.getInstance(project);
            if (tab == Tab.EDITOR) {
                manager.openTextEditor(new OpenFileDescriptor(project, file), true);
            } else {
                manager.openFile(file, true);
            }
        }
    });
    selectEditorTab(tab);
    Wait.seconds(5).expecting("file " + quote(file.getPath()) + " to be opened and loaded").until(() -> {
        if (!file.equals(getCurrentFile())) {
            return false;
        }
        FileEditor fileEditor = FileEditorManager.getInstance(myFrame.getProject()).getSelectedEditor(file);
        JComponent editorComponent = fileEditor.getComponent();
        if (editorComponent instanceof JBLoadingPanel) {
            return !((JBLoadingPanel) editorComponent).isLoading();
        }
        return true;
    });
    myFrame.requestFocusIfLost();
    robot.waitForIdle();
    return this;
}
Also used : GuiTask(org.fest.swing.edt.GuiTask) Project(com.intellij.openapi.project.Project) FileEditorManager(com.intellij.openapi.fileEditor.FileEditorManager) FileEditor(com.intellij.openapi.fileEditor.FileEditor) OpenFileDescriptor(com.intellij.openapi.fileEditor.OpenFileDescriptor) JBLoadingPanel(com.intellij.ui.components.JBLoadingPanel)

Example 34 with FileEditorManager

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

the class HtmlLinkManager method openEditor.

private static boolean openEditor(@NotNull Project project, @NotNull VirtualFile file, int line, int column) {
    OpenFileDescriptor descriptor = new OpenFileDescriptor(project, file, line, column);
    FileEditorManager manager = FileEditorManager.getInstance(project);
    // Attempt to prefer text editor if it's available for this file
    if (manager.openTextEditor(descriptor, true) != null) {
        return true;
    }
    return !manager.openEditor(descriptor, true).isEmpty();
}
Also used : FileEditorManager(com.intellij.openapi.fileEditor.FileEditorManager) OpenFileDescriptor(com.intellij.openapi.fileEditor.OpenFileDescriptor)

Example 35 with FileEditorManager

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

the class ImageEditorImpl method propertyChanged.

void propertyChanged(@NotNull VirtualFilePropertyEvent event) {
    if (file.equals(event.getFile())) {
        // Change document
        file.refresh(true, false, () -> {
            if (ImageFileTypeManager.getInstance().isImage(file)) {
                setValue(file);
            } else {
                setValue(null);
                // Close editor
                FileEditorManager editorManager = FileEditorManager.getInstance(project);
                editorManager.closeFile(file);
            }
        });
    }
}
Also used : FileEditorManager(com.intellij.openapi.fileEditor.FileEditorManager)

Aggregations

FileEditorManager (com.intellij.openapi.fileEditor.FileEditorManager)67 VirtualFile (com.intellij.openapi.vfs.VirtualFile)36 FileEditor (com.intellij.openapi.fileEditor.FileEditor)29 Editor (com.intellij.openapi.editor.Editor)22 Project (com.intellij.openapi.project.Project)22 TextEditor (com.intellij.openapi.fileEditor.TextEditor)12 Document (com.intellij.openapi.editor.Document)10 PsiFile (com.intellij.psi.PsiFile)10 OpenFileDescriptor (com.intellij.openapi.fileEditor.OpenFileDescriptor)9 Nullable (org.jetbrains.annotations.Nullable)8 TextRange (com.intellij.openapi.util.TextRange)6 NotNull (org.jetbrains.annotations.NotNull)6 FileEditorManagerListener (com.intellij.openapi.fileEditor.FileEditorManagerListener)5 PsiElement (com.intellij.psi.PsiElement)5 StructureViewComponent (com.intellij.ide.structureView.newStructureView.StructureViewComponent)4 EditorColorsScheme (com.intellij.openapi.editor.colors.EditorColorsScheme)4 GuiTask (org.fest.swing.edt.GuiTask)4 HighlightManager (com.intellij.codeInsight.highlighting.HighlightManager)3 ResourceBundleAsVirtualFile (com.intellij.lang.properties.editor.ResourceBundleAsVirtualFile)3 PsiClass (com.intellij.psi.PsiClass)3