diff --git a/src/vs/platform/editor/common/editor.ts b/src/vs/platform/editor/common/editor.ts index bc66534184a..d789272604a 100644 --- a/src/vs/platform/editor/common/editor.ts +++ b/src/vs/platform/editor/common/editor.ts @@ -37,35 +37,12 @@ export interface IEditorModel { dispose(): void; } -export interface IResourceInput { - - /** - * The resource URL of the resource to open. - */ - resource: URI; - - /** - * The encoding of the text input if known. - */ - encoding?: string; +export interface IBaseResourceInput { /** * Optional options to use when opening the text input. */ options?: ITextEditorOptions; -} - -export interface IResourceDiffInput { - - /** - * The left hand side URI to open inside a diff editor. - */ - leftResource: URI; - - /** - * The right hand side URI to open inside a diff editor. - */ - rightResource: URI; /** * Label to show for the diff editor @@ -76,11 +53,45 @@ export interface IResourceDiffInput { * Description to show for the diff editor */ description?: string; +} + +export interface IResourceInput extends IBaseResourceInput { /** - * Optional options to use when opening the text diff input. + * The resource URL of the resource to open. */ - options?: ITextEditorOptions; + resource: URI; + + /** + * The encoding of the text input if known. + */ + encoding?: string; +} + +export interface IResourceDiffInput extends IBaseResourceInput { + + /** + * The left hand side URI to open inside a diff editor. + */ + leftResource: URI; + + /** + * The right hand side URI to open inside a diff editor. + */ + rightResource: URI; +} + +export interface IResourceSideBySideInput extends IBaseResourceInput { + + /** + * The right hand side URI to open inside a side by side editor. + */ + masterResource: URI; + + /** + * The left hand side URI to open inside a side by side editor. + */ + detailResource: URI; } export interface IEditorControl { diff --git a/src/vs/workbench/common/editor.ts b/src/vs/workbench/common/editor.ts index 421c27802ca..927e46b9ef1 100644 --- a/src/vs/workbench/common/editor.ts +++ b/src/vs/workbench/common/editor.ts @@ -11,7 +11,7 @@ import types = require('vs/base/common/types'); import URI from 'vs/base/common/uri'; import { IDisposable, dispose } from 'vs/base/common/lifecycle'; import { IEditor, ICommonCodeEditor, IEditorViewState, IEditorOptions as ICodeEditorOptions, IModel } from 'vs/editor/common/editorCommon'; -import { IEditorInput, IEditorModel, IEditorOptions, ITextEditorOptions, IResourceInput, IResourceDiffInput, Position } from 'vs/platform/editor/common/editor'; +import { IEditorInput, IEditorModel, IEditorOptions, ITextEditorOptions, IBaseResourceInput, Position } from 'vs/platform/editor/common/editor'; import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace'; import { IEditorGroupService } from 'vs/workbench/services/group/common/groupService'; import { SyncDescriptor, AsyncDescriptor } from 'vs/platform/instantiation/common/descriptors'; @@ -577,7 +577,7 @@ export class TextEditorOptions extends EditorOptions { private editorViewState: IEditorViewState; private editorOptions: ICodeEditorOptions; - public static from(input: IResourceInput | IResourceDiffInput): TextEditorOptions { + public static from(input: IBaseResourceInput): TextEditorOptions { let options: TextEditorOptions = null; if (input && input.options) { if (input.options.selection || input.options.forceOpen || input.options.revealIfVisible || input.options.preserveFocus || input.options.pinned || input.options.inactive || typeof input.options.index === 'number') { diff --git a/src/vs/workbench/services/editor/browser/editorService.ts b/src/vs/workbench/services/editor/browser/editorService.ts index 38f8898a3ee..ddffd5c9502 100644 --- a/src/vs/workbench/services/editor/browser/editorService.ts +++ b/src/vs/workbench/services/editor/browser/editorService.ts @@ -15,7 +15,7 @@ import { ResourceEditorInput } from 'vs/workbench/common/editor/resourceEditorIn import { UntitledEditorInput } from 'vs/workbench/common/editor/untitledEditorInput'; import { IUntitledEditorService } from 'vs/workbench/services/untitled/common/untitledEditorService'; import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService'; -import { IEditorInput, IEditorOptions, ITextEditorOptions, Position, Direction, IEditor, IResourceInput, IResourceDiffInput } from 'vs/platform/editor/common/editor'; +import { IEditorInput, IEditorOptions, ITextEditorOptions, Position, Direction, IEditor, IResourceInput, IResourceDiffInput, IResourceSideBySideInput } from 'vs/platform/editor/common/editor'; import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation'; import { AsyncDescriptor0 } from 'vs/platform/instantiation/common/descriptors'; import { DiffEditorInput, toDiffLabel } from 'vs/workbench/common/editor/diffEditorInput'; @@ -88,8 +88,8 @@ export class WorkbenchEditorService implements IWorkbenchEditorService { public openEditor(input: IEditorInput, options?: IEditorOptions, sideBySide?: boolean): TPromise; public openEditor(input: IEditorInput, options?: IEditorOptions, position?: Position): TPromise; - public openEditor(input: IResourceInput | IResourceDiffInput, position?: Position): TPromise; - public openEditor(input: IResourceInput | IResourceDiffInput, sideBySide?: boolean): TPromise; + public openEditor(input: IResourceInput | IResourceDiffInput | IResourceSideBySideInput, position?: Position): TPromise; + public openEditor(input: IResourceInput | IResourceDiffInput | IResourceSideBySideInput, sideBySide?: boolean): TPromise; public openEditor(input: any, arg2?: any, arg3?: any): TPromise { if (!input) { return TPromise.as(null); @@ -112,7 +112,7 @@ export class WorkbenchEditorService implements IWorkbenchEditorService { } // Untyped Text Editor Support (required for code that uses this service below workbench level) - const textInput = input; + const textInput = input; return this.createInput(textInput).then(typedInput => { if (typedInput) { return this.doOpenEditor(typedInput, TextEditorOptions.from(textInput), arg2); @@ -144,7 +144,7 @@ export class WorkbenchEditorService implements IWorkbenchEditorService { return this.editorPart.openEditor(input, options, arg3); } - public openEditors(editors: { input: IResourceInput | IResourceDiffInput, position: Position }[]): TPromise; + public openEditors(editors: { input: IResourceInput | IResourceDiffInput | IResourceSideBySideInput, position: Position }[]): TPromise; public openEditors(editors: { input: IEditorInput, position: Position, options?: IEditorOptions }[]): TPromise; public openEditors(editors: any[]): TPromise { return TPromise.join(editors.map(editor => this.createInput(editor.input))).then(inputs => { @@ -162,7 +162,7 @@ export class WorkbenchEditorService implements IWorkbenchEditorService { }); } - public replaceEditors(editors: { toReplace: IResourceInput | IResourceDiffInput, replaceWith: IResourceInput | IResourceDiffInput }[]): TPromise; + public replaceEditors(editors: { toReplace: IResourceInput | IResourceDiffInput | IResourceSideBySideInput, replaceWith: IResourceInput | IResourceDiffInput | IResourceSideBySideInput }[]): TPromise; public replaceEditors(editors: { toReplace: IEditorInput, replaceWith: IEditorInput, options?: IEditorOptions }[]): TPromise; public replaceEditors(editors: any[]): TPromise { return TPromise.join(editors.map(editor => this.createInput(editor.toReplace))).then(toReplaceInputs => { @@ -195,7 +195,7 @@ export class WorkbenchEditorService implements IWorkbenchEditorService { } public createInput(input: IEditorInput): TPromise; - public createInput(input: IResourceInput | IResourceDiffInput): TPromise; + public createInput(input: IResourceInput | IResourceDiffInput | IResourceSideBySideInput): TPromise; public createInput(input: any): TPromise { // Workbench Input Support @@ -203,6 +203,16 @@ export class WorkbenchEditorService implements IWorkbenchEditorService { return TPromise.as(input); } + // Side by Side Support + const resourceSideBySideInput = input; + if (resourceSideBySideInput.masterResource && resourceSideBySideInput.detailResource) { + return this.createInput({ resource: resourceSideBySideInput.masterResource }).then(masterInput => { + return this.createInput({ resource: resourceSideBySideInput.detailResource }).then(detailInput => { + return new SideBySideEditorInput(resourceSideBySideInput.label || masterInput.getName(), resourceSideBySideInput.description || masterInput.getDescription(), detailInput, masterInput); + }); + }); + } + // Diff Editor Support const resourceDiffInput = input; if (resourceDiffInput.leftResource && resourceDiffInput.rightResource) { diff --git a/src/vs/workbench/services/editor/common/editorService.ts b/src/vs/workbench/services/editor/common/editorService.ts index abd54ac7c83..3d22a66f41b 100644 --- a/src/vs/workbench/services/editor/common/editorService.ts +++ b/src/vs/workbench/services/editor/common/editorService.ts @@ -7,7 +7,7 @@ import { TPromise } from 'vs/base/common/winjs.base'; import { createDecorator, ServiceIdentifier } from 'vs/platform/instantiation/common/instantiation'; -import { IEditorService, IEditor, IEditorInput, IEditorOptions, ITextEditorOptions, Position, Direction, IResourceInput, IResourceDiffInput } from 'vs/platform/editor/common/editor'; +import { IEditorService, IEditor, IEditorInput, IEditorOptions, ITextEditorOptions, Position, Direction, IResourceInput, IResourceDiffInput, IResourceSideBySideInput } from 'vs/platform/editor/common/editor'; export const IWorkbenchEditorService = createDecorator('editorService'); @@ -49,23 +49,23 @@ export interface IWorkbenchEditorService extends IEditorService { openEditor(input: IEditorInput, options?: IEditorOptions | ITextEditorOptions, sideBySide?: boolean): TPromise; /** - * Specific overload to open an instance of IResourceInput and IResourceDiffInput. + * Specific overload to open an instance of IResourceInput, IResourceDiffInput or IResourceSideBySideInput. */ - openEditor(input: IResourceInput | IResourceDiffInput, position?: Position): TPromise; - openEditor(input: IResourceInput | IResourceDiffInput, sideBySide?: boolean): TPromise; + openEditor(input: IResourceInput | IResourceDiffInput | IResourceSideBySideInput, position?: Position): TPromise; + openEditor(input: IResourceInput | IResourceDiffInput | IResourceSideBySideInput, sideBySide?: boolean): TPromise; /** * Similar to #openEditor() but allows to open multiple editors for different positions at the same time. If there are * more than one editor per position, only the first one will be active and the others stacked behind inactive. */ - openEditors(editors: { input: IResourceInput | IResourceDiffInput, position: Position }[]): TPromise; + openEditors(editors: { input: IResourceInput | IResourceDiffInput | IResourceSideBySideInput, position: Position }[]): TPromise; openEditors(editors: { input: IEditorInput, position: Position, options?: IEditorOptions | ITextEditorOptions }[]): TPromise; /** * Given a list of editors to replace, will look across all groups where this editor is open (active or hidden) * and replace it with the new editor and the provied options. */ - replaceEditors(editors: { toReplace: IResourceInput | IResourceDiffInput, replaceWith: IResourceInput | IResourceDiffInput }[]): TPromise; + replaceEditors(editors: { toReplace: IResourceInput | IResourceDiffInput | IResourceSideBySideInput, replaceWith: IResourceInput | IResourceDiffInput | IResourceSideBySideInput }[]): TPromise; replaceEditors(editors: { toReplace: IEditorInput, replaceWith: IEditorInput, options?: IEditorOptions | ITextEditorOptions }[]): TPromise; /** @@ -88,5 +88,5 @@ export interface IWorkbenchEditorService extends IEditorService { /** * Allows to resolve an untyped input to a workbench typed instanceof editor input */ - createInput(input: IResourceInput | IResourceDiffInput): TPromise; + createInput(input: IResourceInput | IResourceDiffInput | IResourceSideBySideInput): TPromise; } \ No newline at end of file