Search in sources :

Example 6 with EditorWindow

use of com.intellij.openapi.fileEditor.impl.EditorWindow in project ideavim by JetBrains.

the class FileGroup method closeFile.

/**
   * Close the current editor
   *
   * @param context The data context
   */
public void closeFile(@NotNull Editor editor, @NotNull DataContext context) {
    final Project project = PlatformDataKeys.PROJECT.getData(context);
    if (project != null) {
        final FileEditorManagerEx fileEditorManager = FileEditorManagerEx.getInstanceEx(project);
        final EditorWindow window = fileEditorManager.getCurrentWindow();
        final EditorTabbedContainer tabbedPane = window.getTabbedPane();
        if (tabbedPane != null) {
            if (tabbedPane.getTabCount() > 1) {
                final int index = tabbedPane.getSelectedIndex();
                tabbedPane.removeTabAt(index, index + 1);
            } else {
                tabbedPane.close();
            }
        } else {
            VirtualFile virtualFile = EditorData.getVirtualFile(editor);
            if (virtualFile != null) {
                fileEditorManager.closeFile(virtualFile);
            }
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) EditorTabbedContainer(com.intellij.openapi.fileEditor.impl.EditorTabbedContainer) FileEditorManagerEx(com.intellij.openapi.fileEditor.ex.FileEditorManagerEx) EditorWindow(com.intellij.openapi.fileEditor.impl.EditorWindow)

Example 7 with EditorWindow

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

the class SplitAction method actionPerformed.

public void actionPerformed(final AnActionEvent event) {
    final Project project = event.getData(CommonDataKeys.PROJECT);
    final FileEditorManagerEx fileEditorManager = FileEditorManagerEx.getInstanceEx(project);
    final EditorWindow window = event.getData(EditorWindow.DATA_KEY);
    final VirtualFile file = event.getData(CommonDataKeys.VIRTUAL_FILE);
    fileEditorManager.createSplitter(myOrientation, window);
    if (myCloseSource && window != null && file != null) {
        window.closeFile(file, false, false);
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) FileEditorManagerEx(com.intellij.openapi.fileEditor.ex.FileEditorManagerEx) EditorWindow(com.intellij.openapi.fileEditor.impl.EditorWindow)

Example 8 with EditorWindow

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

the class TabNavigationActionBase method update.

public void update(AnActionEvent event) {
    Presentation presentation = event.getPresentation();
    DataContext dataContext = event.getDataContext();
    Project project = CommonDataKeys.PROJECT.getData(dataContext);
    presentation.setEnabled(false);
    if (project == null || project.isDisposed()) {
        return;
    }
    final ToolWindowManager windowManager = ToolWindowManager.getInstance(project);
    if (windowManager.isEditorComponentActive()) {
        final FileEditorManagerEx editorManager = FileEditorManagerEx.getInstanceEx(project);
        EditorWindow currentWindow = EditorWindow.DATA_KEY.getData(dataContext);
        if (currentWindow == null) {
            editorManager.getCurrentWindow();
        }
        if (currentWindow != null) {
            final VirtualFile[] files = currentWindow.getFiles();
            presentation.setEnabled(files.length > 1);
        }
        return;
    }
    ContentManager contentManager = PlatformDataKeys.NONEMPTY_CONTENT_MANAGER.getData(dataContext);
    presentation.setEnabled(contentManager != null && contentManager.getContentCount() > 1 && contentManager.isSingleSelection());
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) ToolWindowManager(com.intellij.openapi.wm.ToolWindowManager) ContentManager(com.intellij.ui.content.ContentManager) FileEditorManagerEx(com.intellij.openapi.fileEditor.ex.FileEditorManagerEx) EditorWindow(com.intellij.openapi.fileEditor.impl.EditorWindow)

Example 9 with EditorWindow

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

the class TabNavigationActionBase method doNavigate.

private void doNavigate(DataContext dataContext, Project project) {
    final FileEditorManagerEx editorManager = FileEditorManagerEx.getInstanceEx(project);
    EditorWindow currentWindow = EditorWindow.DATA_KEY.getData(dataContext);
    if (currentWindow == null) {
        currentWindow = editorManager.getCurrentWindow();
    }
    VirtualFile selectedFile = currentWindow.getSelectedFile();
    if (selectedFile == null) {
        selectedFile = CommonDataKeys.VIRTUAL_FILE.getData(dataContext);
    }
    final VirtualFile[] files = currentWindow.getFiles();
    int index = ArrayUtil.find(files, selectedFile);
    LOG.assertTrue(index != -1);
    editorManager.openFile(files[(index + files.length + myDir) % files.length], true);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FileEditorManagerEx(com.intellij.openapi.fileEditor.ex.FileEditorManagerEx) EditorWindow(com.intellij.openapi.fileEditor.impl.EditorWindow)

Example 10 with EditorWindow

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

the class CloseAllEditorsAction method actionPerformed.

public void actionPerformed(final AnActionEvent e) {
    final Project project = e.getData(CommonDataKeys.PROJECT);
    CommandProcessor commandProcessor = CommandProcessor.getInstance();
    commandProcessor.executeCommand(project, () -> {
        final EditorWindow window = e.getData(EditorWindow.DATA_KEY);
        if (window != null) {
            final VirtualFile[] files = window.getFiles();
            for (final VirtualFile file : files) {
                window.closeFile(file);
            }
            return;
        }
        FileEditorManagerEx fileEditorManager = FileEditorManagerEx.getInstanceEx(project);
        VirtualFile selectedFile = fileEditorManager.getSelectedFiles()[0];
        VirtualFile[] openFiles = fileEditorManager.getSiblings(selectedFile);
        for (final VirtualFile openFile : openFiles) {
            fileEditorManager.closeFile(openFile);
        }
    }, IdeBundle.message("command.close.all.editors"), null);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) CommandProcessor(com.intellij.openapi.command.CommandProcessor) FileEditorManagerEx(com.intellij.openapi.fileEditor.ex.FileEditorManagerEx) EditorWindow(com.intellij.openapi.fileEditor.impl.EditorWindow)

Aggregations

EditorWindow (com.intellij.openapi.fileEditor.impl.EditorWindow)33 FileEditorManagerEx (com.intellij.openapi.fileEditor.ex.FileEditorManagerEx)22 Project (com.intellij.openapi.project.Project)16 VirtualFile (com.intellij.openapi.vfs.VirtualFile)14 EditorWithProviderComposite (com.intellij.openapi.fileEditor.impl.EditorWithProviderComposite)5 FileEditor (com.intellij.openapi.fileEditor.FileEditor)3 EditorComposite (com.intellij.openapi.fileEditor.impl.EditorComposite)3 Pair (com.intellij.openapi.util.Pair)3 CommandProcessor (com.intellij.openapi.command.CommandProcessor)2 Document (com.intellij.openapi.editor.Document)2 FileColorManager (com.intellij.ui.FileColorManager)2 NotNull (org.jetbrains.annotations.NotNull)2 Nullable (org.jetbrains.annotations.Nullable)2 HprofEditor (com.android.tools.idea.editors.hprof.HprofEditor)1 Presentation (com.intellij.openapi.actionSystem.Presentation)1 EditorEx (com.intellij.openapi.editor.ex.EditorEx)1 OpenFileDescriptor (com.intellij.openapi.fileEditor.OpenFileDescriptor)1 TextEditor (com.intellij.openapi.fileEditor.TextEditor)1 EditorTabbedContainer (com.intellij.openapi.fileEditor.impl.EditorTabbedContainer)1 EditorsSplitters (com.intellij.openapi.fileEditor.impl.EditorsSplitters)1