From 9390006a7ba543cff9f617a0e8eb4d59f57c96c8 Mon Sep 17 00:00:00 2001 From: Benjamin Pasero Date: Tue, 8 May 2018 17:01:09 +0200 Subject: [PATCH] grid - add action to open editor side by side --- .../parts/editor/editor.contribution.ts | 3 ++- .../parts/editor2/nextEditorActions.ts | 23 +++++++++++++++++++ .../editor/browser/nextEditorService.ts | 16 ++++++------- .../editor/common/nextEditorService.ts | 12 +++++----- 4 files changed, 39 insertions(+), 15 deletions(-) diff --git a/src/vs/workbench/browser/parts/editor/editor.contribution.ts b/src/vs/workbench/browser/parts/editor/editor.contribution.ts index a864965ae2e..d15f6880fdb 100644 --- a/src/vs/workbench/browser/parts/editor/editor.contribution.ts +++ b/src/vs/workbench/browser/parts/editor/editor.contribution.ts @@ -42,7 +42,7 @@ import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey'; import { isMacintosh } from 'vs/base/common/platform'; import { GroupOnePicker, GroupTwoPicker, GroupThreePicker, AllEditorsPicker } from 'vs/workbench/browser/parts/editor/editorPicker'; import { Schemas } from 'vs/base/common/network'; -import { GridOpenEditorsAction, GridCloseActiveEditorAction, GridRemoveActiveGroupAction, GridOpenOneEditorAction } from 'vs/workbench/browser/parts/editor2/nextEditorActions'; +import { GridOpenEditorsAction, GridCloseActiveEditorAction, GridRemoveActiveGroupAction, GridOpenOneEditorAction, GridOpenOneEditorSideBySideAction } from 'vs/workbench/browser/parts/editor2/nextEditorActions'; // Register String Editor Registry.as(EditorExtensions.Editors).registerEditor( @@ -443,5 +443,6 @@ registry.registerWorkbenchAction(new SyncActionDescriptor(GridOpenEditorsAction, registry.registerWorkbenchAction(new SyncActionDescriptor(GridCloseActiveEditorAction, GridCloseActiveEditorAction.ID, GridCloseActiveEditorAction.LABEL), 'Grid: Close Active Editor', gridCategory); registry.registerWorkbenchAction(new SyncActionDescriptor(GridRemoveActiveGroupAction, GridRemoveActiveGroupAction.ID, GridRemoveActiveGroupAction.LABEL), 'Grid: Remove Active Group', gridCategory); registry.registerWorkbenchAction(new SyncActionDescriptor(GridOpenOneEditorAction, GridOpenOneEditorAction.ID, GridOpenOneEditorAction.LABEL), 'Grid: Open One Editor', gridCategory); +registry.registerWorkbenchAction(new SyncActionDescriptor(GridOpenOneEditorSideBySideAction, GridOpenOneEditorSideBySideAction.ID, GridOpenOneEditorSideBySideAction.LABEL), 'Grid: Open One Editor Side by Side', gridCategory); registry.registerWorkbenchAction(new SyncActionDescriptor(SplitEditorGroupHorizontalAction, SplitEditorGroupHorizontalAction.ID, SplitEditorGroupHorizontalAction.LABEL), 'Grid: Split Horizontal', gridCategory); registry.registerWorkbenchAction(new SyncActionDescriptor(SplitEditorGroupVerticalAction, SplitEditorGroupVerticalAction.ID, SplitEditorGroupVerticalAction.LABEL), 'Grid: Split Vertical', gridCategory); \ No newline at end of file diff --git a/src/vs/workbench/browser/parts/editor2/nextEditorActions.ts b/src/vs/workbench/browser/parts/editor2/nextEditorActions.ts index 2c00868312d..6754fd9da49 100644 --- a/src/vs/workbench/browser/parts/editor2/nextEditorActions.ts +++ b/src/vs/workbench/browser/parts/editor2/nextEditorActions.ts @@ -14,6 +14,7 @@ import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/edi import { EditorInput } from 'vs/workbench/common/editor'; import { join, dirname } from 'vs/base/common/paths'; import { isWindows } from 'vs/base/common/platform'; +import { INextEditorService, SIDE_BY_SIDE } from 'vs/workbench/services/editor/common/nextEditorService'; function getVSCodeBaseFolder(): string { let workingDir = process.cwd(); @@ -93,6 +94,28 @@ export class GridOpenOneEditorAction extends Action { } } +export class GridOpenOneEditorSideBySideAction extends Action { + + static readonly ID = 'workbench.action.gridOpenOneEditorSideBySide'; + static readonly LABEL = localize('gridOpenOneEditorSideBySide', "Grid: Open One Editor Side by Side"); + + constructor( + id: string, + label: string, + @IWorkbenchEditorService private legacyEditorService: IWorkbenchEditorService, + @INextEditorService private editorService: INextEditorService + ) { + super(id, label); + } + + run(): TPromise { + const path = join(getVSCodeBaseFolder(), 'src/vs/workbench/browser/parts/editor/editor.contribution.ts'); + this.editorService.openEditor(this.legacyEditorService.createInput({ resource: URI.file(path) }) as EditorInput, null, SIDE_BY_SIDE); + + return TPromise.as(void 0); + } +} + export class GridCloseActiveEditorAction extends Action { static readonly ID = 'workbench.action.gridCloseActiveEditor'; diff --git a/src/vs/workbench/services/editor/browser/nextEditorService.ts b/src/vs/workbench/services/editor/browser/nextEditorService.ts index 422f4e48a86..9343e9106ac 100644 --- a/src/vs/workbench/services/editor/browser/nextEditorService.ts +++ b/src/vs/workbench/services/editor/browser/nextEditorService.ts @@ -25,7 +25,7 @@ import { DiffEditorInput } from 'vs/workbench/common/editor/diffEditorInput'; import { localize } from 'vs/nls'; import { TPromise } from 'vs/base/common/winjs.base'; import { INextEditorGroupsService, INextEditorGroup, GroupDirection } from 'vs/workbench/services/group/common/nextEditorGroupsService'; -import { INextEditorService, IResourceEditor, SIDE_BY_SIDE, SIDE_BY_SIDE_VALUE, IEditorInputWithOptions } from 'vs/workbench/services/editor/common/nextEditorService'; +import { INextEditorService, IResourceEditor, SIDE_BY_SIDE_TYPE, SIDE_BY_SIDE, IEditorInputWithOptions } from 'vs/workbench/services/editor/common/nextEditorService'; import { IConfigurationService } from 'vs/platform/configuration/common/configuration'; import { Disposable, IDisposable, dispose } from 'vs/base/common/lifecycle'; import { coalesce } from 'vs/base/common/arrays'; @@ -165,8 +165,8 @@ export class NextEditorService extends Disposable implements INextEditorService //#region openEditor() - openEditor(editor: IEditorInput, options?: IEditorOptions, group?: GroupIdentifier | SIDE_BY_SIDE): Thenable; - openEditor(editor: IResourceEditor, group?: GroupIdentifier | SIDE_BY_SIDE): Thenable; + openEditor(editor: IEditorInput, options?: IEditorOptions, group?: GroupIdentifier | SIDE_BY_SIDE_TYPE): Thenable; + openEditor(editor: IResourceEditor, group?: GroupIdentifier | SIDE_BY_SIDE_TYPE): Thenable; openEditor(editor: IEditorInput | IResourceEditor, optionsOrGroup?: IEditorOptions | GroupIdentifier, group?: GroupIdentifier): Thenable { // Typed Editor Support @@ -193,11 +193,11 @@ export class NextEditorService extends Disposable implements INextEditorService return TPromise.wrap(null); } - private doOpenEditor(input: IEditorInput, options?: EditorOptions, group?: GroupIdentifier | SIDE_BY_SIDE): Thenable { + private doOpenEditor(input: IEditorInput, options?: EditorOptions, group?: GroupIdentifier | SIDE_BY_SIDE_TYPE): Thenable { let targetGroup: INextEditorGroup; // Group: Side by Side - if (group === SIDE_BY_SIDE_VALUE) { + if (group === SIDE_BY_SIDE) { targetGroup = this.nextEditorGroupsService.addGroup(this.nextEditorGroupsService.activeGroup, GroupDirection.RIGHT); } @@ -259,9 +259,9 @@ export class NextEditorService extends Disposable implements INextEditorService //#region openEditors() // TODO@grid openEditors() - openEditors(editors: IEditorInputWithOptions[], group?: GroupIdentifier | SIDE_BY_SIDE): Thenable; - openEditors(editors: IResourceEditor[], group?: GroupIdentifier | SIDE_BY_SIDE): Thenable; - openEditors(editors: (IEditorInputWithOptions | IResourceEditor)[], group?: GroupIdentifier | SIDE_BY_SIDE): Thenable { + openEditors(editors: IEditorInputWithOptions[], group?: GroupIdentifier | SIDE_BY_SIDE_TYPE): Thenable; + openEditors(editors: IResourceEditor[], group?: GroupIdentifier | SIDE_BY_SIDE_TYPE): Thenable; + openEditors(editors: (IEditorInputWithOptions | IResourceEditor)[], group?: GroupIdentifier | SIDE_BY_SIDE_TYPE): Thenable { const inputs = editors.map(editor => this.createInput(editor)); return this.openEditor(inputs[0]); diff --git a/src/vs/workbench/services/editor/common/nextEditorService.ts b/src/vs/workbench/services/editor/common/nextEditorService.ts index cde00062680..5b77bc663cb 100644 --- a/src/vs/workbench/services/editor/common/nextEditorService.ts +++ b/src/vs/workbench/services/editor/common/nextEditorService.ts @@ -15,8 +15,8 @@ export const INextEditorService = createDecorator('nextEdito export type IResourceEditor = IResourceInput | IUntitledResourceInput | IResourceDiffInput | IResourceSideBySideInput; -export const SIDE_BY_SIDE_VALUE = -1; -export type SIDE_BY_SIDE = typeof SIDE_BY_SIDE_VALUE; +export const SIDE_BY_SIDE = -1; +export type SIDE_BY_SIDE_TYPE = typeof SIDE_BY_SIDE; export interface IEditorInputWithOptions { editor: IEditorInput; @@ -87,7 +87,7 @@ export interface INextEditorService { * active group. Use `SIDE_BY_SIDE` to open the editor in a new editor group to the side * of the currently active group. */ - openEditor(editor: IEditorInput, options?: IEditorOptions, group?: GroupIdentifier | SIDE_BY_SIDE): Thenable; + openEditor(editor: IEditorInput, options?: IEditorOptions, group?: GroupIdentifier | SIDE_BY_SIDE_TYPE): Thenable; /** * Open an editor in an editor group. @@ -97,7 +97,7 @@ export interface INextEditorService { * active group. Use `SIDE_BY_SIDE` to open the editor in a new editor group to the side * of the currently active group. */ - openEditor(editor: IResourceEditor, group?: GroupIdentifier | SIDE_BY_SIDE): Thenable; + openEditor(editor: IResourceEditor, group?: GroupIdentifier | SIDE_BY_SIDE_TYPE): Thenable; /** * Open editors in an editor group. @@ -107,8 +107,8 @@ export interface INextEditorService { * active group. Use `SIDE_BY_SIDE` to open the editor in a new editor group to the side * of the currently active group. */ - openEditors(editors: IEditorInputWithOptions[], group?: GroupIdentifier | SIDE_BY_SIDE): Thenable; - openEditors(editors: IResourceEditor[], group?: GroupIdentifier | SIDE_BY_SIDE): Thenable; + openEditors(editors: IEditorInputWithOptions[], group?: GroupIdentifier | SIDE_BY_SIDE_TYPE): Thenable; + openEditors(editors: IResourceEditor[], group?: GroupIdentifier | SIDE_BY_SIDE_TYPE): Thenable; /** * Find out if the provided editor (or resource of an editor) is opened in any group. -- GitLab