diff --git a/src/vs/platform/editor/common/editor.ts b/src/vs/platform/editor/common/editor.ts index 0a816d707a1f16f8d151127f1550282a71829f2d..44665b5be8e0bc9c2e9aeac90939db7716098330 100644 --- a/src/vs/platform/editor/common/editor.ts +++ b/src/vs/platform/editor/common/editor.ts @@ -22,17 +22,6 @@ export interface IEditorService { openEditor(input: IResourceInput, sideBySide?: boolean): TPromise; } -export interface IEditorInputWithOptions { - editor: IEditorInput; - options?: IEditorOptions; -} - -export function isEditorInputWithOptions(obj: any): obj is IEditorInputWithOptions { - const editorInputWithOptions = obj as IEditorInputWithOptions; - - return !!editorInputWithOptions && !!editorInputWithOptions.editor; -} - export interface IEditorModel { onDispose: Event; diff --git a/src/vs/workbench/browser/parts/editor/editorPart.ts b/src/vs/workbench/browser/parts/editor/editorPart.ts index a4e1960b54f9afd41947ef1ec1c8a951a063e894..a0d660d8d8803af12ff7d24544d872149addb994 100644 --- a/src/vs/workbench/browser/parts/editor/editorPart.ts +++ b/src/vs/workbench/browser/parts/editor/editorPart.ts @@ -947,11 +947,11 @@ export class EditorPart extends Part implements IEditorPart, IEditorGroupService } // Editor opening event (can be prevented and overridden) - const event = new EditorOpeningEvent(input, options, position); + const event = new EditorOpeningEvent(null, input, options); this._onEditorOpening.fire(event); const prevented = event.isPrevented(); if (prevented) { - return prevented(); + return prevented() as any; } // Open through UI diff --git a/src/vs/workbench/browser/parts/editor2/nextEditorGroupView.ts b/src/vs/workbench/browser/parts/editor2/nextEditorGroupView.ts index 2d3de84e55e33ade0b9812c2ddd33f53fdff49ce..2b35f90bfeca197f9f7c6bfc48156376aa2f3072 100644 --- a/src/vs/workbench/browser/parts/editor2/nextEditorGroupView.ts +++ b/src/vs/workbench/browser/parts/editor2/nextEditorGroupView.ts @@ -582,11 +582,11 @@ export class NextEditorGroupView extends Themable implements INextEditorGroupVie openEditor(editor: EditorInput, options?: EditorOptions): Thenable { // Editor opening event allows for prevention - const event = new EditorOpeningEvent(editor, options, this._group.id); // TODO@grid position => group ID + const event = new EditorOpeningEvent(this, editor, options); this._onWillOpenEditor.fire(event); const prevented = event.isPrevented(); if (prevented) { - return prevented().then(() => void 0); // TODO@grid do we need the BaseEditor return type still in the event? + return prevented(); } // Proceed with opening diff --git a/src/vs/workbench/common/editor.ts b/src/vs/workbench/common/editor.ts index 898b126568487052f98d590d7ba1d9d8f7fbf750..e0acbb17cfae4f0d091034e0133c3a82f518e321 100644 --- a/src/vs/workbench/common/editor.ts +++ b/src/vs/workbench/common/editor.ts @@ -11,7 +11,7 @@ import * as types from 'vs/base/common/types'; import URI from 'vs/base/common/uri'; import { IDisposable, dispose, Disposable } from 'vs/base/common/lifecycle'; import { IEditor, IEditorViewState, ScrollType } from 'vs/editor/common/editorCommon'; -import { IEditorInput, IEditorModel, IEditorOptions, ITextEditorOptions, IBaseResourceInput, Position, Verbosity, IEditor as IBaseEditor, IRevertOptions } from 'vs/platform/editor/common/editor'; +import { IEditorInput, IEditorModel, IEditorOptions, ITextEditorOptions, IBaseResourceInput, Position, Verbosity, IRevertOptions } from 'vs/platform/editor/common/editor'; import { IInstantiationService, IConstructorSignature0 } from 'vs/platform/instantiation/common/instantiation'; import { RawContextKey, ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey'; import { Registry } from 'vs/platform/registry/common/platform'; @@ -274,9 +274,9 @@ export abstract class EditorInput implements IEditorInput { } export interface IEditorOpeningEvent { - input: IEditorInput; + editor: IEditorInput; options?: IEditorOptions; - position: Position; + group: INextEditorGroup; /** * Allows to prevent the opening of an editor by providing a callback @@ -285,32 +285,32 @@ export interface IEditorOpeningEvent { * to return a promise that resolves to NULL to prevent the opening * altogether. */ - prevent(callback: () => TPromise): void; + prevent(callback: () => Thenable): void; } export class EditorOpeningEvent implements IEditorOpeningEvent { - private override: () => TPromise; + private override: () => Thenable; - constructor(private _input: IEditorInput, private _options: IEditorOptions, private _position: Position) { + constructor(private _group: INextEditorGroup, private _editor: IEditorInput, private _options: IEditorOptions) { } - public get input(): IEditorInput { - return this._input; + public get group(): INextEditorGroup { + return this._group; } - public get options(): IEditorOptions { - return this._options; + public get editor(): IEditorInput { + return this._editor; } - public get position(): Position { - return this._position; + public get options(): IEditorOptions { + return this._options; } - public prevent(callback: () => TPromise): void { + public prevent(callback: () => Thenable): void { this.override = callback; } - public isPrevented(): () => TPromise { + public isPrevented(): () => Thenable { return this.override; } } @@ -519,6 +519,17 @@ export class EditorModel extends Disposable implements IEditorModel { } } +export interface IEditorInputWithOptions { + editor: IEditorInput; + options?: IEditorOptions; +} + +export function isEditorInputWithOptions(obj: any): obj is IEditorInputWithOptions { + const editorInputWithOptions = obj as IEditorInputWithOptions; + + return !!editorInputWithOptions && !!editorInputWithOptions.editor; +} + /** * The editor options is the base class of options that can be passed in when opening an editor. */ diff --git a/src/vs/workbench/parts/files/electron-browser/fileActions.ts b/src/vs/workbench/parts/files/electron-browser/fileActions.ts index 1195fcf4de41c9e8629cf7a76f6d88f5e9610645..98e5d87b45c4db5dc09cf5fe4075b660151a4713 100644 --- a/src/vs/workbench/parts/files/electron-browser/fileActions.ts +++ b/src/vs/workbench/parts/files/electron-browser/fileActions.ts @@ -1104,13 +1104,13 @@ export class GlobalCompareResourcesAction extends Action { // Compare with next editor that opens const unbind = once(this.editorGroupService.onEditorOpening)(e => { - const resource = e.input.getResource(); + const resource = e.editor.getResource(); if (resource) { e.prevent(() => { return this.editorService.openEditor({ leftResource: activeResource, rightResource: resource - }); + }).then(() => void 0); }); } }); diff --git a/src/vs/workbench/parts/preferences/common/preferencesContribution.ts b/src/vs/workbench/parts/preferences/common/preferencesContribution.ts index 09d6aa2c742d8005c100a9b27c3f6d4eb859f717..7c4b77c1039ed0015ca74be386b07125d6405700 100644 --- a/src/vs/workbench/parts/preferences/common/preferencesContribution.ts +++ b/src/vs/workbench/parts/preferences/common/preferencesContribution.ts @@ -60,7 +60,7 @@ export class PreferencesContribution implements IWorkbenchContribution { } private onEditorOpening(event: IEditorOpeningEvent): void { - const resource = event.input.getResource(); + const resource = event.editor.getResource(); if ( !resource || resource.scheme !== 'file' || // require a file path opening !endsWith(resource.fsPath, 'settings.json') || // file must end in settings.json @@ -72,15 +72,13 @@ export class PreferencesContribution implements IWorkbenchContribution { // If the file resource was already opened before in the group, do not prevent // the opening of that resource. Otherwise we would have the same settings // opened twice (https://github.com/Microsoft/vscode/issues/36447) - const stacks = this.editorGroupService.getStacksModel(); - const group = stacks.groupAt(event.position); - if (group && group.contains(event.input)) { + if (event.group.isOpened(event.editor)) { return; } // Global User Settings File if (resource.fsPath === this.environmentService.appSettingsPath) { - return event.prevent(() => this.preferencesService.openGlobalSettings(event.options, event.position)); + return event.prevent(() => this.preferencesService.openGlobalSettings(event.options, event.group)); } // Single Folder Workspace Settings File @@ -88,7 +86,7 @@ export class PreferencesContribution implements IWorkbenchContribution { if (state === WorkbenchState.FOLDER) { const folders = this.workspaceService.getWorkspace().folders; if (resource.fsPath === folders[0].toResource(FOLDER_SETTINGS_PATH).fsPath) { - return event.prevent(() => this.preferencesService.openWorkspaceSettings(event.options, event.position)); + return event.prevent(() => this.preferencesService.openWorkspaceSettings(event.options, event.group)); } } @@ -97,7 +95,7 @@ export class PreferencesContribution implements IWorkbenchContribution { const folders = this.workspaceService.getWorkspace().folders; for (let i = 0; i < folders.length; i++) { if (resource.fsPath === folders[i].toResource(FOLDER_SETTINGS_PATH).fsPath) { - return event.prevent(() => this.preferencesService.openFolderSettings(folders[i].uri, event.options, event.position)); + return event.prevent(() => this.preferencesService.openFolderSettings(folders[i].uri, event.options, event.group)); } } } diff --git a/src/vs/workbench/services/editor/browser/nextEditorService.ts b/src/vs/workbench/services/editor/browser/nextEditorService.ts index 9fe7b2592f2bfc3603e410d301bfd070d8117332..a82d7bba9eea89f3b12f44df79ed36259da897e7 100644 --- a/src/vs/workbench/services/editor/browser/nextEditorService.ts +++ b/src/vs/workbench/services/editor/browser/nextEditorService.ts @@ -6,8 +6,8 @@ 'use strict'; import { IInstantiationService, ServicesAccessor } from 'vs/platform/instantiation/common/instantiation'; -import { IEditorInput, IResourceInput, IUntitledResourceInput, IResourceDiffInput, IResourceSideBySideInput, IEditor, ITextEditorOptions, IEditorOptions, IEditorInputWithOptions, isEditorInputWithOptions } from 'vs/platform/editor/common/editor'; -import { GroupIdentifier, IFileEditorInput, IEditorInputFactoryRegistry, Extensions as EditorExtensions, IFileInputFactory, EditorInput, SideBySideEditorInput, EditorOptions, TextEditorOptions, IEditorOpeningEvent } from 'vs/workbench/common/editor'; +import { IEditorInput, IResourceInput, IUntitledResourceInput, IResourceDiffInput, IResourceSideBySideInput, IEditor, ITextEditorOptions, IEditorOptions } from 'vs/platform/editor/common/editor'; +import { GroupIdentifier, IFileEditorInput, IEditorInputFactoryRegistry, Extensions as EditorExtensions, IFileInputFactory, EditorInput, SideBySideEditorInput, IEditorInputWithOptions, isEditorInputWithOptions, EditorOptions, TextEditorOptions, IEditorOpeningEvent } from 'vs/workbench/common/editor'; import { ResourceEditorInput } from 'vs/workbench/common/editor/resourceEditorInput'; import { DataUriEditorInput } from 'vs/workbench/common/editor/dataUriEditorInput'; import { Registry } from 'vs/platform/registry/common/platform'; @@ -163,9 +163,9 @@ export class NextEditorService extends Disposable implements INextEditorService //#region openEditor() - openEditor(editor: IEditorInput, options?: IEditorOptions, group?: GroupIdentifier | SIDE_GROUP_TYPE | ACTIVE_GROUP_TYPE): Thenable; - openEditor(editor: IResourceEditor, group?: GroupIdentifier | SIDE_GROUP_TYPE | ACTIVE_GROUP_TYPE): Thenable; - openEditor(editor: IEditorInput | IResourceEditor, optionsOrGroup?: IEditorOptions | GroupIdentifier | SIDE_GROUP_TYPE | ACTIVE_GROUP_TYPE, group?: GroupIdentifier): Thenable { + openEditor(editor: IEditorInput, options?: IEditorOptions, group?: INextEditorGroup | GroupIdentifier | SIDE_GROUP_TYPE | ACTIVE_GROUP_TYPE): Thenable; + openEditor(editor: IResourceEditor, group?: INextEditorGroup | GroupIdentifier | SIDE_GROUP_TYPE | ACTIVE_GROUP_TYPE): Thenable; + openEditor(editor: IEditorInput | IResourceEditor, optionsOrGroup?: IEditorOptions | INextEditorGroup | GroupIdentifier | SIDE_GROUP_TYPE | ACTIVE_GROUP_TYPE, group?: GroupIdentifier): Thenable { // Typed Editor Support if (editor instanceof EditorInput) { @@ -189,7 +189,7 @@ export class NextEditorService extends Disposable implements INextEditorService const typedInput = this.createInput(textInput); if (typedInput) { const editorOptions = TextEditorOptions.from(textInput); - const targetGroup = this.findTargetGroup(typedInput, editorOptions, optionsOrGroup as GroupIdentifier); + const targetGroup = this.findTargetGroup(typedInput, editorOptions, optionsOrGroup as INextEditorGroup | GroupIdentifier); return targetGroup.openEditor(typedInput, editorOptions).then(() => targetGroup.activeControl); } @@ -197,9 +197,14 @@ export class NextEditorService extends Disposable implements INextEditorService return TPromise.wrap(null); } - private findTargetGroup(input: IEditorInput, options?: IEditorOptions, group?: GroupIdentifier | SIDE_GROUP_TYPE | ACTIVE_GROUP_TYPE): INextEditorGroup { + private findTargetGroup(input: IEditorInput, options?: IEditorOptions, group?: INextEditorGroup | GroupIdentifier | SIDE_GROUP_TYPE | ACTIVE_GROUP_TYPE): INextEditorGroup { let targetGroup: INextEditorGroup; + // Group: Instance of Group + if (group && typeof group !== 'number') { + return group; + } + // Group: Active Group if (group === ACTIVE_GROUP) { targetGroup = this.nextEditorGroupsService.activeGroup; @@ -271,9 +276,9 @@ export class NextEditorService extends Disposable implements INextEditorService //#region openEditors() - openEditors(editors: IEditorInputWithOptions[], group?: GroupIdentifier | SIDE_GROUP_TYPE | ACTIVE_GROUP_TYPE): Thenable; - openEditors(editors: IResourceEditor[], group?: GroupIdentifier | SIDE_GROUP_TYPE | ACTIVE_GROUP_TYPE): Thenable; - openEditors(editors: (IEditorInputWithOptions | IResourceEditor)[], group?: GroupIdentifier | SIDE_GROUP_TYPE | ACTIVE_GROUP_TYPE): Thenable { + openEditors(editors: IEditorInputWithOptions[], group?: INextEditorGroup | GroupIdentifier | SIDE_GROUP_TYPE | ACTIVE_GROUP_TYPE): Thenable; + openEditors(editors: IResourceEditor[], group?: INextEditorGroup | GroupIdentifier | SIDE_GROUP_TYPE | ACTIVE_GROUP_TYPE): Thenable; + openEditors(editors: (IEditorInputWithOptions | IResourceEditor)[], group?: INextEditorGroup | GroupIdentifier | SIDE_GROUP_TYPE | ACTIVE_GROUP_TYPE): Thenable { // Convert to typed editors and options const typedEditors: IEditorInputWithOptions[] = []; diff --git a/src/vs/workbench/services/editor/common/nextEditorService.ts b/src/vs/workbench/services/editor/common/nextEditorService.ts index 597d3683d40c96a04e386f101836d78c1fe7e3a3..9152c117de72f5e9b730f136ca18380aacd2a5c7 100644 --- a/src/vs/workbench/services/editor/common/nextEditorService.ts +++ b/src/vs/workbench/services/editor/common/nextEditorService.ts @@ -6,10 +6,11 @@ 'use strict'; import { createDecorator, ServiceIdentifier, ServicesAccessor } from 'vs/platform/instantiation/common/instantiation'; -import { IEditorInput, IResourceInput, IUntitledResourceInput, IResourceDiffInput, IResourceSideBySideInput, IEditor, IEditorOptions, IEditorInputWithOptions } from 'vs/platform/editor/common/editor'; -import { GroupIdentifier, IEditorOpeningEvent } from 'vs/workbench/common/editor'; +import { IEditorInput, IResourceInput, IUntitledResourceInput, IResourceDiffInput, IResourceSideBySideInput, IEditor, IEditorOptions } from 'vs/platform/editor/common/editor'; +import { GroupIdentifier, IEditorOpeningEvent, IEditorInputWithOptions } from 'vs/workbench/common/editor'; import { Event } from 'vs/base/common/event'; import { IEditor as ICodeEditor } from 'vs/editor/common/editorCommon'; +import { INextEditorGroup } from 'vs/workbench/services/group/common/nextEditorGroupsService'; export const INextEditorService = createDecorator('nextEditorService'); @@ -90,7 +91,7 @@ export interface INextEditorService { * active group. Use `SIDE_GROUP_TYPE` 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_GROUP_TYPE | ACTIVE_GROUP_TYPE): Thenable; + openEditor(editor: IEditorInput, options?: IEditorOptions, group?: INextEditorGroup | GroupIdentifier | SIDE_GROUP_TYPE | ACTIVE_GROUP_TYPE): Thenable; /** * Open an editor in an editor group. @@ -100,7 +101,7 @@ export interface INextEditorService { * active group. Use `SIDE_GROUP_TYPE` to open the editor in a new editor group to the side * of the currently active group. */ - openEditor(editor: IResourceEditor, group?: GroupIdentifier | SIDE_GROUP_TYPE | ACTIVE_GROUP_TYPE): Thenable; + openEditor(editor: IResourceEditor, group?: INextEditorGroup | GroupIdentifier | SIDE_GROUP_TYPE | ACTIVE_GROUP_TYPE): Thenable; /** * Open editors in an editor group. @@ -110,8 +111,8 @@ export interface INextEditorService { * active group. Use `SIDE_GROUP_TYPE` to open the editor in a new editor group to the side * of the currently active group. */ - openEditors(editors: IEditorInputWithOptions[], group?: GroupIdentifier | SIDE_GROUP_TYPE | ACTIVE_GROUP_TYPE): Thenable>; - openEditors(editors: IResourceEditor[], group?: GroupIdentifier | SIDE_GROUP_TYPE | ACTIVE_GROUP_TYPE): Thenable>; + openEditors(editors: IEditorInputWithOptions[], group?: INextEditorGroup | GroupIdentifier | SIDE_GROUP_TYPE | ACTIVE_GROUP_TYPE): Thenable>; + openEditors(editors: IResourceEditor[], group?: INextEditorGroup | GroupIdentifier | SIDE_GROUP_TYPE | ACTIVE_GROUP_TYPE): Thenable>; /** * Find out if the provided editor (or resource of an editor) is opened in any group. diff --git a/src/vs/workbench/services/group/common/nextEditorGroupsService.ts b/src/vs/workbench/services/group/common/nextEditorGroupsService.ts index 0eae320a4f7c8e96d4a51e0cc71925771487b81e..33f972a18d4ad7b1ac1154edc7296502906e70c9 100644 --- a/src/vs/workbench/services/group/common/nextEditorGroupsService.ts +++ b/src/vs/workbench/services/group/common/nextEditorGroupsService.ts @@ -7,8 +7,8 @@ import { Event } from 'vs/base/common/event'; import { createDecorator, ServiceIdentifier, ServicesAccessor } from 'vs/platform/instantiation/common/instantiation'; -import { GroupIdentifier, IEditorOpeningEvent } from 'vs/workbench/common/editor'; -import { IEditorInput, IEditor, IEditorOptions, IEditorInputWithOptions, Direction } from 'vs/platform/editor/common/editor'; +import { GroupIdentifier, IEditorOpeningEvent, IEditorInputWithOptions } from 'vs/workbench/common/editor'; +import { IEditorInput, IEditor, IEditorOptions, Direction } from 'vs/platform/editor/common/editor'; export const INextEditorGroupsService = createDecorator('nextEditorGroupsService'); diff --git a/src/vs/workbench/services/preferences/browser/preferencesService.ts b/src/vs/workbench/services/preferences/browser/preferencesService.ts index 43fb3e3974d537756c16eef4d2777420df85e7b8..7e40af00ca2d8332b5a96d1a793e8ab917b6074f 100644 --- a/src/vs/workbench/services/preferences/browser/preferencesService.ts +++ b/src/vs/workbench/services/preferences/browser/preferencesService.ts @@ -39,6 +39,7 @@ import { ICodeEditor } from 'vs/editor/browser/editorBrowser'; import { INotificationService } from 'vs/platform/notification/common/notification'; import { assign } from 'vs/base/common/objects'; import { INextEditorService } from 'vs/workbench/services/editor/common/nextEditorService'; +import { INextEditorGroup, INextEditorGroupsService } from 'vs/workbench/services/group/common/nextEditorGroupsService'; const emptyEditableSettingsContent = '{\n}'; @@ -61,6 +62,7 @@ export class PreferencesService extends Disposable implements IPreferencesServic @IWorkbenchEditorService private editorService: IWorkbenchEditorService, @INextEditorService private nextEditorService: INextEditorService, @IEditorGroupService private editorGroupService: IEditorGroupService, + @INextEditorGroupsService private nextEditorGroupService: INextEditorGroupsService, @IFileService private fileService: IFileService, @IWorkspaceConfigurationService private configurationService: IWorkspaceConfigurationService, @INotificationService private notificationService: INotificationService, @@ -181,30 +183,30 @@ export class PreferencesService extends Disposable implements IPreferencesServic return this.openOrSwitchSettings(target, resource); } - openGlobalSettings(options?: IEditorOptions, position?: EditorPosition): TPromise { - return this.openOrSwitchSettings(ConfigurationTarget.USER, this.userSettingsResource, options, position); + openGlobalSettings(options?: IEditorOptions, group?: INextEditorGroup): TPromise { + return this.openOrSwitchSettings(ConfigurationTarget.USER, this.userSettingsResource, options, group); } openSettings2(): TPromise { return this.editorService.openEditor(this.instantiationService.createInstance(SettingsEditor2Input), { pinned: true }).then(() => null); } - openWorkspaceSettings(options?: IEditorOptions, position?: EditorPosition): TPromise { + openWorkspaceSettings(options?: IEditorOptions, group?: INextEditorGroup): TPromise { if (this.contextService.getWorkbenchState() === WorkbenchState.EMPTY) { this.notificationService.info(nls.localize('openFolderFirst', "Open a folder first to create workspace settings")); return TPromise.as(null); } - return this.openOrSwitchSettings(ConfigurationTarget.WORKSPACE, this.workspaceSettingsResource, options, position); + return this.openOrSwitchSettings(ConfigurationTarget.WORKSPACE, this.workspaceSettingsResource, options, group); } - openFolderSettings(folder: URI, options?: IEditorOptions, position?: EditorPosition): TPromise { - return this.openOrSwitchSettings(ConfigurationTarget.WORKSPACE_FOLDER, this.getEditableSettingsURI(ConfigurationTarget.WORKSPACE_FOLDER, folder), options, position); + openFolderSettings(folder: URI, options?: IEditorOptions, group?: INextEditorGroup): TPromise { + return this.openOrSwitchSettings(ConfigurationTarget.WORKSPACE_FOLDER, this.getEditableSettingsURI(ConfigurationTarget.WORKSPACE_FOLDER, folder), options, group); } switchSettings(target: ConfigurationTarget, resource: URI): TPromise { const activeEditor = this.editorService.getActiveEditor(); if (activeEditor && activeEditor.input instanceof PreferencesEditorInput) { - return this.doSwitchSettings(target, resource, activeEditor.input, activeEditor.position).then(() => null); + return this.doSwitchSettings(target, resource, activeEditor.input, null).then(() => null); } else { return this.doOpenSettings(target, resource).then(() => null); } @@ -247,17 +249,15 @@ export class PreferencesService extends Disposable implements IPreferencesServic }); } - private openOrSwitchSettings(configurationTarget: ConfigurationTarget, resource: URI, options?: IEditorOptions, position?: EditorPosition): TPromise { - const activeGroup = this.editorGroupService.getStacksModel().activeGroup; - const positionToReplace = position !== void 0 ? position : activeGroup ? this.editorGroupService.getStacksModel().positionOfGroup(activeGroup) : EditorPosition.ONE; - const editorInput = this.getActiveSettingsEditorInput(positionToReplace); + private openOrSwitchSettings(configurationTarget: ConfigurationTarget, resource: URI, options?: IEditorOptions, group: INextEditorGroup = this.nextEditorGroupService.activeGroup): TPromise { + const editorInput = this.getActiveSettingsEditorInput(group); if (editorInput && editorInput.master.getResource().fsPath !== resource.fsPath) { - return this.doSwitchSettings(configurationTarget, resource, editorInput, positionToReplace); + return this.doSwitchSettings(configurationTarget, resource, editorInput, group); } - return this.doOpenSettings(configurationTarget, resource, options, position); + return this.doOpenSettings(configurationTarget, resource, options, group); } - private doOpenSettings(configurationTarget: ConfigurationTarget, resource: URI, options?: IEditorOptions, position?: EditorPosition): TPromise { + private doOpenSettings(configurationTarget: ConfigurationTarget, resource: URI, options?: IEditorOptions, group?: INextEditorGroup): TPromise { const openDefaultSettings = !!this.configurationService.getValue(DEFAULT_SETTINGS_EDITOR_SETTING); return this.getOrCreateEditableSettingsEditorInput(configurationTarget, resource) .then(editableSettingsEditorInput => { @@ -271,30 +271,29 @@ export class PreferencesService extends Disposable implements IPreferencesServic const defaultPreferencesEditorInput = this.instantiationService.createInstance(DefaultPreferencesEditorInput, this.getDefaultSettingsResource(configurationTarget)); const preferencesEditorInput = new PreferencesEditorInput(this.getPreferencesEditorInputName(configurationTarget, resource), editableSettingsEditorInput.getDescription(), defaultPreferencesEditorInput, editableSettingsEditorInput); this.lastOpenedSettingsInput = preferencesEditorInput; - return this.nextEditorService.openEditor(preferencesEditorInput, options /*, TODO@grid position */); + return this.nextEditorService.openEditor(preferencesEditorInput, options, group); } - return this.nextEditorService.openEditor(editableSettingsEditorInput, options /*, TODO@grid position */); + return this.nextEditorService.openEditor(editableSettingsEditorInput, options, group); }); } - private doSwitchSettings(target: ConfigurationTarget, resource: URI, input: PreferencesEditorInput, position?: EditorPosition): TPromise { + private doSwitchSettings(target: ConfigurationTarget, resource: URI, input: PreferencesEditorInput, group: INextEditorGroup): TPromise { return this.getOrCreateEditableSettingsEditorInput(target, this.getEditableSettingsURI(target, resource)) .then(toInput => { const replaceWith = new PreferencesEditorInput(this.getPreferencesEditorInputName(target, resource), toInput.getDescription(), this.instantiationService.createInstance(DefaultPreferencesEditorInput, this.getDefaultSettingsResource(target)), toInput); - return this.editorService.replaceEditors([{ - toReplace: input, - replaceWith - }], position).then(editors => { + + return group.replaceEditors([{ + editor: input, + replacement: replaceWith + }]).then(() => { this.lastOpenedSettingsInput = replaceWith; - return editors[0]; + return group.activeControl; }); }); } - private getActiveSettingsEditorInput(position?: EditorPosition): PreferencesEditorInput { - const stacksModel = this.editorGroupService.getStacksModel(); - const group = position !== void 0 ? stacksModel.groupAt(position) : stacksModel.activeGroup; - return group && group.getEditors().filter(e => e instanceof PreferencesEditorInput)[0]; + private getActiveSettingsEditorInput(group: INextEditorGroup = this.nextEditorGroupService.activeGroup): PreferencesEditorInput { + return group.editors.filter(e => e instanceof PreferencesEditorInput)[0]; } private getConfigurationTargetFromSettingsResource(resource: URI): ConfigurationTarget { diff --git a/src/vs/workbench/services/preferences/common/preferences.ts b/src/vs/workbench/services/preferences/common/preferences.ts index ccc4547988e6926be87e9879935b8575d1240427..1d831c08642e7ed47567b74fd6b75bbcdf53a19d 100644 --- a/src/vs/workbench/services/preferences/common/preferences.ts +++ b/src/vs/workbench/services/preferences/common/preferences.ts @@ -6,7 +6,7 @@ import URI from 'vs/base/common/uri'; import { TPromise } from 'vs/base/common/winjs.base'; import { createDecorator } from 'vs/platform/instantiation/common/instantiation'; -import { IEditor, Position, IEditorOptions } from 'vs/platform/editor/common/editor'; +import { IEditor, IEditorOptions } from 'vs/platform/editor/common/editor'; import { ITextModel } from 'vs/editor/common/model'; import { IRange } from 'vs/editor/common/core/range'; import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace'; @@ -16,6 +16,7 @@ import { Event } from 'vs/base/common/event'; import { IStringDictionary } from 'vs/base/common/collections'; import { ILocalExtension } from 'vs/platform/extensionManagement/common/extensionManagement'; import { localize } from 'vs/nls'; +import { INextEditorGroup } from 'vs/workbench/services/group/common/nextEditorGroupsService'; export interface ISettingsGroup { id: string; @@ -143,9 +144,9 @@ export interface IPreferencesService { openRawDefaultSettings(): TPromise; openSettings(): TPromise; openSettings2(): TPromise; - openGlobalSettings(options?: IEditorOptions, position?: Position): TPromise; - openWorkspaceSettings(options?: IEditorOptions, position?: Position): TPromise; - openFolderSettings(folder: URI, options?: IEditorOptions, position?: Position): TPromise; + openGlobalSettings(options?: IEditorOptions, group?: INextEditorGroup): TPromise; + openWorkspaceSettings(options?: IEditorOptions, group?: INextEditorGroup): TPromise; + openFolderSettings(folder: URI, options?: IEditorOptions, group?: INextEditorGroup): TPromise; switchSettings(target: ConfigurationTarget, resource: URI): TPromise; openGlobalKeybindingSettings(textual: boolean): TPromise;