diff --git a/src/vs/platform/editor/common/editor.ts b/src/vs/platform/editor/common/editor.ts index ec9dccfbf424f240722ba09e67a99e66df2ee4f3..d35396a181a4738169841d6a4db650cde4436f3a 100644 --- a/src/vs/platform/editor/common/editor.ts +++ b/src/vs/platform/editor/common/editor.ts @@ -128,22 +128,3 @@ export interface ITextEditorOptions extends IEditorOptions { */ revealInCenterIfOutsideViewport?: boolean; } - -//#region TODO@grid obsolete - -/** - * Possible locations for opening an editor. - */ -export enum Position { - - /** Opens the editor in the first position replacing the input currently showing */ - ONE = 0, - - /** Opens the editor in the second position replacing the input currently showing */ - TWO = 1, - - /** Opens the editor in the third most position replacing the input currently showing */ - THREE = 2 -} - -//#endregion \ No newline at end of file diff --git a/src/vs/workbench/api/electron-browser/mainThreadDocumentsAndEditors.ts b/src/vs/workbench/api/electron-browser/mainThreadDocumentsAndEditors.ts index 3e3ae1a1f3e4ba87edc764bf4706b381f60bbd4f..1fa22534e8215ce7bc4e3939a098e556a272d701 100644 --- a/src/vs/workbench/api/electron-browser/mainThreadDocumentsAndEditors.ts +++ b/src/vs/workbench/api/electron-browser/mainThreadDocumentsAndEditors.ts @@ -13,7 +13,7 @@ import { ExtHostContext, ExtHostDocumentsAndEditorsShape, IModelAddedData, IText import { MainThreadTextEditor } from './mainThreadEditor'; import { ITextFileService } from 'vs/workbench/services/textfile/common/textfiles'; import { IEditorGroupsService } from 'vs/workbench/services/group/common/editorGroupsService'; -import { Position as EditorPosition } from 'vs/platform/editor/common/editor'; +import { EditorPosition } from 'vs/workbench/api/shared/editor'; import { IEditor } from 'vs/workbench/common/editor'; import { extHostCustomer } from 'vs/workbench/api/electron-browser/extHostCustomers'; import { MainThreadDocuments } from 'vs/workbench/api/electron-browser/mainThreadDocuments'; diff --git a/src/vs/workbench/api/electron-browser/mainThreadEditors.ts b/src/vs/workbench/api/electron-browser/mainThreadEditors.ts index 0fe76183315f05e0baf1c48e5b72af0c2c65bef7..e234debabec9e7614fcec22ca2f7763e42f0b9cc 100644 --- a/src/vs/workbench/api/electron-browser/mainThreadEditors.ts +++ b/src/vs/workbench/api/electron-browser/mainThreadEditors.ts @@ -4,6 +4,9 @@ *--------------------------------------------------------------------------------------------*/ 'use strict'; +import { ServicesAccessor } from 'vs/platform/instantiation/common/instantiation'; +import { IEditorOptions, ITextEditorOptions } from 'vs/platform/editor/common/editor'; +import { localize } from 'vs/nls'; import { disposed } from 'vs/base/common/errors'; import { IDisposable, dispose } from 'vs/base/common/lifecycle'; import { equals as objectEquals } from 'vs/base/common/objects'; @@ -15,7 +18,8 @@ import { IRange } from 'vs/editor/common/core/range'; import { ISelection } from 'vs/editor/common/core/selection'; import { IDecorationOptions, IDecorationRenderOptions, ILineChange } from 'vs/editor/common/editorCommon'; import { ISingleEditOperation } from 'vs/editor/common/model'; -import { ITextEditorOptions, Position as EditorPosition } from 'vs/platform/editor/common/editor'; +import { EditorPosition } from 'vs/workbench/api/shared/editor'; +import { CommandsRegistry } from 'vs/platform/commands/common/commands'; import { IApplyEditsOptions, ITextEditorConfigurationUpdate, IUndoStopOptions, TextEditorRevealType, WorkspaceEditDto, reviveWorkspaceEditDto } from 'vs/workbench/api/node/extHost.protocol'; import { IEditorService, SIDE_GROUP, ACTIVE_GROUP } from 'vs/workbench/services/editor/common/editorService'; import { IEditorGroupsService } from 'vs/workbench/services/group/common/editorGroupsService'; @@ -127,7 +131,7 @@ export class MainThreadTextEditors implements MainThreadTextEditorsShape { }); } - $tryShowEditor(id: string, position: EditorPosition): TPromise { + $tryShowEditor(id: string, position?: EditorPosition): TPromise { let mainThreadEditor = this._documentsAndEditors.getEditor(id); if (mainThreadEditor) { let model = mainThreadEditor.getModel(); @@ -241,6 +245,36 @@ export class MainThreadTextEditors implements MainThreadTextEditorsShape { } } +// --- commands + +CommandsRegistry.registerCommand('_workbench.open', function (accessor: ServicesAccessor, args: [URI, IEditorOptions, EditorPosition]) { + const editorService = accessor.get(IEditorService); + const editorGroupService = accessor.get(IEditorGroupsService); + + const [resource, options, position] = args; + + return editorService.openEditor({ resource, options }, findEditorGroup(editorGroupService, position)).then(() => void 0); +}); + +CommandsRegistry.registerCommand('_workbench.diff', function (accessor: ServicesAccessor, args: [URI, URI, string, string, IEditorOptions, EditorPosition]) { + const editorService = accessor.get(IEditorService); + const editorGroupService = accessor.get(IEditorGroupsService); + + let [leftResource, rightResource, label, description, options, position] = args; + + if (!options || typeof options !== 'object') { + options = { + preserveFocus: false + }; + } + + if (!label) { + label = localize('diffLeftRightLabel', "{0} ⟷ {1}", leftResource.toString(true), rightResource.toString(true)); + } + + return editorService.openEditor({ leftResource, rightResource, label, description, options }, findEditorGroup(editorGroupService, position)).then(() => void 0); +}); + export function findEditorGroup(editorGroupService: IEditorGroupsService, position?: EditorPosition): GroupIdentifier { if (typeof position !== 'number') { return ACTIVE_GROUP; // prefer active group when position is undefined diff --git a/src/vs/workbench/api/electron-browser/mainThreadWebview.ts b/src/vs/workbench/api/electron-browser/mainThreadWebview.ts index c6ad2693207b4b5a09c68920b5a6674ed8eda768..9f558d8974b8b6c457b9c3db5ec09dcdcf9bed3f 100644 --- a/src/vs/workbench/api/electron-browser/mainThreadWebview.ts +++ b/src/vs/workbench/api/electron-browser/mainThreadWebview.ts @@ -8,7 +8,7 @@ import URI, { UriComponents } from 'vs/base/common/uri'; import { TPromise } from 'vs/base/common/winjs.base'; import { localize } from 'vs/nls'; import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey'; -import { Position } from 'vs/platform/editor/common/editor'; +import { EditorPosition } from 'vs/workbench/api/shared/editor'; import { ILifecycleService } from 'vs/platform/lifecycle/common/lifecycle'; import { IOpenerService } from 'vs/platform/opener/common/opener'; import { ExtHostContext, ExtHostWebviewsShape, IExtHostContext, MainContext, MainThreadWebviewsShape, WebviewPanelHandle } from 'vs/workbench/api/node/extHost.protocol'; @@ -69,7 +69,7 @@ export class MainThreadWebviews implements MainThreadWebviewsShape, WebviewReviv handle: WebviewPanelHandle, viewType: string, title: string, - showOptions: { viewColumn: Position, preserveFocus: boolean }, + showOptions: { viewColumn: EditorPosition | null, preserveFocus: boolean }, options: WebviewInputOptions, extensionLocation: UriComponents ): void { @@ -104,7 +104,7 @@ export class MainThreadWebviews implements MainThreadWebviewsShape, WebviewReviv webview.html = value; } - $reveal(handle: WebviewPanelHandle, viewColumn: Position | null, preserveFocus: boolean): void { + $reveal(handle: WebviewPanelHandle, viewColumn: EditorPosition | null, preserveFocus: boolean): void { const webview = this.getWebview(handle); if (webview.isDisposed()) { return; diff --git a/src/vs/workbench/api/node/apiCommands.ts b/src/vs/workbench/api/node/apiCommands.ts index 98c37e9ed2ee8a21b64ddc4b47c7172019b0ef6f..14c061349dd013b2317869b8a3ea7830663ca53b 100644 --- a/src/vs/workbench/api/node/apiCommands.ts +++ b/src/vs/workbench/api/node/apiCommands.ts @@ -8,7 +8,8 @@ import URI from 'vs/base/common/uri'; import * as vscode from 'vscode'; import * as typeConverters from 'vs/workbench/api/node/extHostTypeConverters'; import { CommandsRegistry, ICommandService, ICommandHandler } from 'vs/platform/commands/common/commands'; -import { Position as EditorPosition, ITextEditorOptions } from 'vs/platform/editor/common/editor'; +import { ITextEditorOptions } from 'vs/platform/editor/common/editor'; +import { EditorPosition } from 'vs/workbench/api/shared/editor'; // ----------------------------------------------------------------- // The following commands are registered on both sides separately. @@ -70,21 +71,21 @@ export class OpenAPICommand { public static ID = 'vscode.open'; public static execute(executor: ICommandsExecutor, resource: URI, columnOrOptions?: vscode.ViewColumn | vscode.TextDocumentShowOptions): Thenable { let options: ITextEditorOptions; - let column: EditorPosition; + let position: EditorPosition; if (columnOrOptions) { if (typeof columnOrOptions === 'number') { - column = typeConverters.ViewColumn.from(columnOrOptions); + position = typeConverters.ViewColumn.from(columnOrOptions); } else { options = typeConverters.TextEditorOptions.from(columnOrOptions); - column = typeConverters.ViewColumn.from(columnOrOptions.viewColumn); + position = typeConverters.ViewColumn.from(columnOrOptions.viewColumn); } } return executor.executeCommand('_workbench.open', [ resource, options, - column + position ]); } } diff --git a/src/vs/workbench/api/node/extHost.protocol.ts b/src/vs/workbench/api/node/extHost.protocol.ts index 760596d1d992a86d08d85f083adda9f3c98b4ab1..03c1ea29e7fc75efaeb51cdf902b14763bb58b15 100644 --- a/src/vs/workbench/api/node/extHost.protocol.ts +++ b/src/vs/workbench/api/node/extHost.protocol.ts @@ -13,7 +13,7 @@ import Severity from 'vs/base/common/severity'; import { TPromise } from 'vs/base/common/winjs.base'; import { IMarkerData } from 'vs/platform/markers/common/markers'; -import { Position as EditorPosition } from 'vs/platform/editor/common/editor'; +import { EditorPosition } from 'vs/workbench/api/shared/editor'; import { IExtensionDescription } from 'vs/workbench/services/extensions/common/extensions'; import { StatusbarAlignment as MainThreadStatusBarAlignment } from 'vs/platform/statusbar/common/statusbar'; import { ITelemetryInfo } from 'vs/platform/telemetry/common/telemetry'; diff --git a/src/vs/workbench/api/node/extHostTextEditors.ts b/src/vs/workbench/api/node/extHostTextEditors.ts index 7339cf6408185583cfefe6b52ce5bfe0b5ea9286..b117852e86e7d12d3c6387341a2ad2a4f722e3d6 100644 --- a/src/vs/workbench/api/node/extHostTextEditors.ts +++ b/src/vs/workbench/api/node/extHostTextEditors.ts @@ -11,7 +11,7 @@ import { TextEditorSelectionChangeKind } from './extHostTypes'; import * as TypeConverters from './extHostTypeConverters'; import { TextEditorDecorationType, ExtHostTextEditor } from './extHostTextEditor'; import { ExtHostDocumentsAndEditors } from './extHostDocumentsAndEditors'; -import { Position as EditorPosition } from 'vs/platform/editor/common/editor'; +import { EditorPosition } from 'vs/workbench/api/shared/editor'; import { MainContext, MainThreadTextEditorsShape, ExtHostEditorsShape, ITextDocumentShowOptions, ITextEditorPositionData, IMainContext, WorkspaceEditDto, IEditorPropertiesChangeData } from './extHost.protocol'; import * as vscode from 'vscode'; @@ -73,7 +73,7 @@ export class ExtHostEditors implements ExtHostEditorsShape { }; } else { options = { - position: EditorPosition.ONE, + position: 0 as EditorPosition, preserveFocus: false }; } diff --git a/src/vs/workbench/api/node/extHostTypeConverters.ts b/src/vs/workbench/api/node/extHostTypeConverters.ts index e0183392127126aade5839fbf902877f9d51add4..43cd0b87c997f42dc4232f71dcf54b3c7e418dd3 100644 --- a/src/vs/workbench/api/node/extHostTypeConverters.ts +++ b/src/vs/workbench/api/node/extHostTypeConverters.ts @@ -6,7 +6,8 @@ import * as modes from 'vs/editor/common/modes'; import * as types from './extHostTypes'; -import { Position as EditorPosition, ITextEditorOptions } from 'vs/platform/editor/common/editor'; +import { ITextEditorOptions } from 'vs/platform/editor/common/editor'; +import { EditorPosition } from 'vs/workbench/api/shared/editor'; import { IDecorationOptions } from 'vs/editor/common/editorCommon'; import { EndOfLineSequence } from 'vs/editor/common/model'; import * as vscode from 'vscode'; @@ -157,13 +158,13 @@ export namespace DiagnosticSeverity { export namespace ViewColumn { export function from(column?: vscode.ViewColumn): EditorPosition { - let editorColumn = EditorPosition.ONE; + let editorColumn = 0; if (typeof column !== 'number') { // stick with ONE } else if (column === types.ViewColumn.Two) { - editorColumn = EditorPosition.TWO; + editorColumn = 1; } else if (column === types.ViewColumn.Three) { - editorColumn = EditorPosition.THREE; + editorColumn = 2; } else if (column === types.ViewColumn.Active) { editorColumn = undefined; } @@ -174,11 +175,11 @@ export namespace ViewColumn { if (typeof position !== 'number') { return undefined; } - if (position === EditorPosition.ONE) { + if (position === 0) { return types.ViewColumn.One; - } else if (position === EditorPosition.TWO) { + } else if (position === 1) { return types.ViewColumn.Two; - } else if (position === EditorPosition.THREE) { + } else if (position === 2) { return types.ViewColumn.Three; } return undefined; diff --git a/src/vs/workbench/api/node/extHostWebview.ts b/src/vs/workbench/api/node/extHostWebview.ts index a122fbca89f93e2c769ce50b01ec158f25976059..3af0dfb1add7c35c759650a68313a986e3a5b263 100644 --- a/src/vs/workbench/api/node/extHostWebview.ts +++ b/src/vs/workbench/api/node/extHostWebview.ts @@ -7,7 +7,7 @@ import { MainContext, MainThreadWebviewsShape, IMainContext, ExtHostWebviewsShap import * as vscode from 'vscode'; import { Event, Emitter } from 'vs/base/common/event'; import * as typeConverters from 'vs/workbench/api/node/extHostTypeConverters'; -import { Position } from 'vs/platform/editor/common/editor'; +import { EditorPosition } from 'vs/workbench/api/shared/editor'; import { TPromise } from 'vs/base/common/winjs.base'; import { Disposable } from './extHostTypes'; import URI from 'vs/base/common/uri'; @@ -248,7 +248,7 @@ export class ExtHostWebviews implements ExtHostWebviewsShape { } } - $onDidChangeWebviewPanelViewState(handle: WebviewPanelHandle, visible: boolean, position: Position): void { + $onDidChangeWebviewPanelViewState(handle: WebviewPanelHandle, visible: boolean, position: EditorPosition): void { const panel = this.getWebviewPanel(handle); if (panel) { const viewColumn = typeConverters.ViewColumn.to(position); @@ -274,7 +274,7 @@ export class ExtHostWebviews implements ExtHostWebviewsShape { viewType: string, title: string, state: any, - position: Position, + position: EditorPosition, options: vscode.WebviewOptions & vscode.WebviewPanelOptions ): Thenable { const serializer = this._serializers.get(viewType); diff --git a/src/vs/workbench/api/shared/editor.ts b/src/vs/workbench/api/shared/editor.ts new file mode 100644 index 0000000000000000000000000000000000000000..77fa626555c942eb2398ec83fd5ffef46e7b9b65 --- /dev/null +++ b/src/vs/workbench/api/shared/editor.ts @@ -0,0 +1,11 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +'use strict'; + +// TODO@api this was previously a hardcoded list of editor positions (ONE, TWO, THREE) +// that with the introduction of grid editor feature is now unbounded. This should be +// revisited when the grid functionality is exposed to extensions +export type EditorPosition = number; \ No newline at end of file diff --git a/src/vs/workbench/electron-browser/commands.ts b/src/vs/workbench/electron-browser/commands.ts index 859842b2cb4a96bade3fdcbac7987b1881eb24aa..ecb6e315f434aa1a6799b3014787cd102785b7a6 100644 --- a/src/vs/workbench/electron-browser/commands.ts +++ b/src/vs/workbench/electron-browser/commands.ts @@ -5,7 +5,6 @@ 'use strict'; -import * as nls from 'vs/nls'; import { KeyMod, KeyChord, KeyCode } from 'vs/base/common/keyCodes'; import { ServicesAccessor } from 'vs/platform/instantiation/common/instantiation'; import { KeybindingsRegistry } from 'vs/platform/keybinding/common/keybindingsRegistry'; @@ -14,9 +13,6 @@ import { IWindowsService, IWindowService } from 'vs/platform/windows/common/wind import { List } from 'vs/base/browser/ui/list/listWidget'; import * as errors from 'vs/base/common/errors'; import { CommandsRegistry } from 'vs/platform/commands/common/commands'; -import { IEditorService } from 'vs/workbench/services/editor/common/editorService'; -import URI from 'vs/base/common/uri'; -import { IEditorOptions, Position as EditorPosition } from 'vs/platform/editor/common/editor'; import { WorkbenchListFocusContextKey, IListService, WorkbenchListSupportsMultiSelectContextKey, ListWidget } from 'vs/platform/list/browser/listService'; import { PagedList } from 'vs/base/browser/ui/list/listPaging'; import { range } from 'vs/base/common/arrays'; @@ -535,30 +531,6 @@ export function registerCommands(): void { win: { primary: void 0 } }); - CommandsRegistry.registerCommand('_workbench.diff', function (accessor: ServicesAccessor, args: [URI, URI, string, string, IEditorOptions, EditorPosition]) { - const editorService = accessor.get(IEditorService); - let [leftResource, rightResource, label, description, options, position] = args; - - if (!options || typeof options !== 'object') { - options = { - preserveFocus: false - }; - } - - if (!label) { - label = nls.localize('diffLeftRightLabel', "{0} ⟷ {1}", leftResource.toString(true), rightResource.toString(true)); - } - - return editorService.openEditor({ leftResource, rightResource, label, description, options }, position).then(() => void 0); - }); - - CommandsRegistry.registerCommand('_workbench.open', function (accessor: ServicesAccessor, args: [URI, IEditorOptions, EditorPosition]) { - const editorService = accessor.get(IEditorService); - const [resource, options, column] = args; - - return editorService.openEditor({ resource, options }, column).then(() => void 0); - }); - CommandsRegistry.registerCommand('_workbench.removeFromRecentlyOpened', function (accessor: ServicesAccessor, path: string) { const windowsService = accessor.get(IWindowsService); diff --git a/src/vs/workbench/parts/backup/common/backupRestorer.ts b/src/vs/workbench/parts/backup/common/backupRestorer.ts index e9630f6804ca2071f55e8cdb9a2e101438dccdd7..c9fba97e14bed475d418ad017cfc0beb212c3397 100644 --- a/src/vs/workbench/parts/backup/common/backupRestorer.ts +++ b/src/vs/workbench/parts/backup/common/backupRestorer.ts @@ -47,7 +47,7 @@ export class BackupRestorer implements IWorkbenchContribution { // Find all files and untitled with backups return this.backupFileService.getWorkspaceFileBackups().then(backups => { - // Resolve backups that are opened in stacks model + // Resolve backups that are opened return this.doResolveOpenedBackups(backups).then(unresolved => { // Some failed to restore or were not opened at all so we open and resolve them manually diff --git a/src/vs/workbench/parts/html/electron-browser/html.contribution.ts b/src/vs/workbench/parts/html/electron-browser/html.contribution.ts index 9e8be4f6c22e3803d2a698fbda0fb7f6321967c2..77cbe9bebc52a3aebfc909de3cdb932a1fafcdc9 100644 --- a/src/vs/workbench/parts/html/electron-browser/html.contribution.ts +++ b/src/vs/workbench/parts/html/electron-browser/html.contribution.ts @@ -9,7 +9,7 @@ import { localize } from 'vs/nls'; import { CommandsRegistry } from 'vs/platform/commands/common/commands'; import { IInstantiationService, ServicesAccessor } from 'vs/platform/instantiation/common/instantiation'; import { IEditorService } from 'vs/workbench/services/editor/common/editorService'; -import { Position as EditorPosition } from 'vs/platform/editor/common/editor'; +import { EditorPosition } from 'vs/workbench/api/shared/editor'; import { HtmlInput, HtmlInputOptions } from '../common/htmlInput'; import { HtmlPreviewPart } from './htmlPreviewPart'; import { Registry } from 'vs/platform/registry/common/platform'; diff --git a/src/vs/workbench/parts/webview/electron-browser/webviewEditorService.ts b/src/vs/workbench/parts/webview/electron-browser/webviewEditorService.ts index e690fb8f04818bb9e4282a0e61903d0059d71210..37c28b1951e463cb951dc15ff97d96c5edc06569 100644 --- a/src/vs/workbench/parts/webview/electron-browser/webviewEditorService.ts +++ b/src/vs/workbench/parts/webview/electron-browser/webviewEditorService.ts @@ -6,7 +6,6 @@ import { IDisposable, toDisposable } from 'vs/base/common/lifecycle'; import URI from 'vs/base/common/uri'; import { TPromise } from 'vs/base/common/winjs.base'; -import { Position } from 'vs/platform/editor/common/editor'; import { IInstantiationService, createDecorator } from 'vs/platform/instantiation/common/instantiation'; import { IEditorService, ACTIVE_GROUP_TYPE, SIDE_GROUP_TYPE } from 'vs/workbench/services/editor/common/editorService'; import { IEditorGroupsService, IEditorGroup } from 'vs/workbench/services/group/common/editorGroupsService'; @@ -69,7 +68,6 @@ export interface WebviewReviver { export interface WebviewEvents { onMessage?(message: any): void; - onDidChangePosition?(newPosition: Position): void; onDispose?(): void; onDidClickLink?(link: URI, options: vscode.WebviewOptions): void; } diff --git a/src/vs/workbench/test/electron-browser/api/extHostWebview.test.ts b/src/vs/workbench/test/electron-browser/api/extHostWebview.test.ts index fba6786ff1609b9035819565ae1dc7bb057e43a8..1981437727330d338a2530de11aadfcebcd01ff5 100644 --- a/src/vs/workbench/test/electron-browser/api/extHostWebview.test.ts +++ b/src/vs/workbench/test/electron-browser/api/extHostWebview.test.ts @@ -11,7 +11,7 @@ import { ExtHostWebviews } from 'vs/workbench/api/node/extHostWebview'; import { mock } from 'vs/workbench/test/electron-browser/api/mock'; import * as vscode from 'vscode'; import { SingleProxyRPCProtocol } from './testRPCProtocol'; -import { Position as EditorPosition } from 'vs/platform/editor/common/editor'; +import { EditorPosition } from 'vs/workbench/api/shared/editor'; suite('ExtHostWebview', function () { @@ -34,7 +34,7 @@ suite('ExtHostWebview', function () { const serializerARegistration = extHostWebviews.registerWebviewPanelSerializer(viewType, serializerA); - await extHostWebviews.$deserializeWebviewPanel('x', viewType, 'title', {}, EditorPosition.ONE, {}); + await extHostWebviews.$deserializeWebviewPanel('x', viewType, 'title', {}, 0 as EditorPosition, {}); assert.strictEqual(lastInvokedDeserializer, serializerA); assert.throws( @@ -45,7 +45,7 @@ suite('ExtHostWebview', function () { extHostWebviews.registerWebviewPanelSerializer(viewType, serializerB); - await extHostWebviews.$deserializeWebviewPanel('x', viewType, 'title', {}, EditorPosition.ONE, {}); + await extHostWebviews.$deserializeWebviewPanel('x', viewType, 'title', {}, 0 as EditorPosition, {}); assert.strictEqual(lastInvokedDeserializer, serializerB); }); });