Search in sources :

Example 1 with EditorTabbedContainer

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

the class MotionGroup method switchEditorTab.

/**
   * If 'absolute' is true, then set tab index to 'value', otherwise add 'value' to tab index with wraparound.
   */
private void switchEditorTab(@Nullable EditorWindow editorWindow, int value, boolean absolute) {
    if (editorWindow != null) {
        final EditorTabbedContainer tabbedPane = editorWindow.getTabbedPane();
        if (tabbedPane != null) {
            if (absolute) {
                tabbedPane.setSelectedIndex(value);
            } else {
                int tabIndex = (value + tabbedPane.getSelectedIndex()) % tabbedPane.getTabCount();
                tabbedPane.setSelectedIndex(tabIndex < 0 ? tabIndex + tabbedPane.getTabCount() : tabIndex);
            }
        }
    }
}
Also used : EditorTabbedContainer(com.intellij.openapi.fileEditor.impl.EditorTabbedContainer)

Example 2 with EditorTabbedContainer

use of com.intellij.openapi.fileEditor.impl.EditorTabbedContainer 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)

Aggregations

EditorTabbedContainer (com.intellij.openapi.fileEditor.impl.EditorTabbedContainer)2 FileEditorManagerEx (com.intellij.openapi.fileEditor.ex.FileEditorManagerEx)1 EditorWindow (com.intellij.openapi.fileEditor.impl.EditorWindow)1 Project (com.intellij.openapi.project.Project)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1