diff --git a/src/vs/platform/editor/common/editor.ts b/src/vs/platform/editor/common/editor.ts index 05962f6e99d..bc66534184a 100644 --- a/src/vs/platform/editor/common/editor.ts +++ b/src/vs/platform/editor/common/editor.ts @@ -55,6 +55,34 @@ export interface IResourceInput { 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 + */ + label?: string; + + /** + * Description to show for the diff editor + */ + description?: string; + + /** + * Optional options to use when opening the text diff input. + */ + options?: ITextEditorOptions; +} + export interface IEditorControl { } diff --git a/src/vs/workbench/common/editor.ts b/src/vs/workbench/common/editor.ts index 91c1edc6a6d..421c27802ca 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, Position } from 'vs/platform/editor/common/editor'; +import { IEditorInput, IEditorModel, IEditorOptions, ITextEditorOptions, IResourceInput, IResourceDiffInput, 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): TextEditorOptions { + public static from(input: IResourceInput | IResourceDiffInput): 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/electron-browser/actions.ts b/src/vs/workbench/electron-browser/actions.ts index 469d4cc00ce..7784c60703d 100644 --- a/src/vs/workbench/electron-browser/actions.ts +++ b/src/vs/workbench/electron-browser/actions.ts @@ -11,8 +11,6 @@ import { Action } from 'vs/base/common/actions'; import { IWindowIPCService } from 'vs/workbench/services/window/electron-browser/windowService'; import { IWindowService, IWindowsService } from 'vs/platform/windows/common/windows'; import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService'; -import { EditorInput } from 'vs/workbench/common/editor'; -import { DiffEditorInput } from 'vs/workbench/common/editor/diffEditorInput'; import nls = require('vs/nls'); import product from 'vs/platform/node/product'; import pkg from 'vs/platform/node/package'; @@ -608,18 +606,13 @@ export class KeybindingsReferenceAction extends Action { CommandsRegistry.registerCommand('_workbench.diff', function (accessor: ServicesAccessor, args: [URI, URI, string, string]) { const editorService = accessor.get(IWorkbenchEditorService); - let [left, right, label, description] = args; + let [leftResource, rightResource, label, description] = args; if (!label) { - label = nls.localize('diffLeftRightLabel', "{0} ⟷ {1}", left.toString(true), right.toString(true)); + label = nls.localize('diffLeftRightLabel', "{0} ⟷ {1}", leftResource.toString(true), rightResource.toString(true)); } - return TPromise.join([editorService.createInput({ resource: left }), editorService.createInput({ resource: right })]).then(inputs => { - const [left, right] = inputs; - - const diff = new DiffEditorInput(label, description, left, right); - return editorService.openEditor(diff); - }).then(() => { + return editorService.openEditor({ leftResource, rightResource, label, description }).then(() => { return void 0; }); }); diff --git a/src/vs/workbench/parts/files/browser/fileActions.ts b/src/vs/workbench/parts/files/browser/fileActions.ts index cb0cd9b643c..ec27cdc274c 100644 --- a/src/vs/workbench/parts/files/browser/fileActions.ts +++ b/src/vs/workbench/parts/files/browser/fileActions.ts @@ -47,7 +47,6 @@ import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace import { Keybinding, KeyMod, KeyCode } from 'vs/base/common/keyCodes'; import { Selection } from 'vs/editor/common/core/selection'; import { getCodeEditor } from 'vs/editor/common/services/codeEditorService'; -import { ICommandService } from 'vs/platform/commands/common/commands'; export interface IEditableData { action: IAction; @@ -1216,7 +1215,6 @@ export class CompareResourcesAction extends Action { tree: ITree, @IWorkspaceContextService private contextService: IWorkspaceContextService, @IInstantiationService private instantiationService: IInstantiationService, - @ICommandService private commandService: ICommandService, @IWorkbenchEditorService private editorService: IWorkbenchEditorService ) { super('workbench.files.action.compareFiles', CompareResourcesAction.computeLabel()); @@ -1271,7 +1269,11 @@ export class CompareResourcesAction extends Action { this.tree.clearHighlight(); } - return this.commandService.executeCommand('_workbench.diff', [globalResourceToCompare, this.resource, toDiffLabel(globalResourceToCompare, this.resource, this.contextService)]); + return this.editorService.openEditor({ + leftResource: globalResourceToCompare, + rightResource: this.resource, + label: toDiffLabel(globalResourceToCompare, this.resource, this.contextService) + }); } } diff --git a/src/vs/workbench/services/editor/browser/editorService.ts b/src/vs/workbench/services/editor/browser/editorService.ts index b25aabc139c..7a9cf82c86e 100644 --- a/src/vs/workbench/services/editor/browser/editorService.ts +++ b/src/vs/workbench/services/editor/browser/editorService.ts @@ -15,9 +15,11 @@ 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 } from 'vs/platform/editor/common/editor'; +import { IEditorInput, IEditorOptions, ITextEditorOptions, Position, Direction, IEditor, IResourceInput, IResourceDiffInput } 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'; +import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace'; export interface IEditorPart { openEditor(input?: IEditorInput, options?: IEditorOptions | ITextEditorOptions, sideBySide?: boolean): TPromise; @@ -42,10 +44,11 @@ export class WorkbenchEditorService implements IWorkbenchEditorService { constructor( editorPart: IEditorPart | IWorkbenchEditorService, @IUntitledEditorService private untitledEditorService: IUntitledEditorService, + @IWorkspaceContextService private workspaceContextService: IWorkspaceContextService, @IInstantiationService private instantiationService?: IInstantiationService ) { this.editorPart = editorPart; - this.fileInputDescriptor = (Registry.as(Extensions.Editors)).getDefaultFileInput(); + this.fileInputDescriptor = Registry.as(Extensions.Editors).getDefaultFileInput(); } public getActiveEditor(): IEditor { @@ -85,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, position?: Position): TPromise; - public openEditor(input: IResourceInput, sideBySide?: boolean): TPromise; + public openEditor(input: IResourceInput | IResourceDiffInput, position?: Position): TPromise; + public openEditor(input: IResourceInput | IResourceDiffInput, sideBySide?: boolean): TPromise; public openEditor(input: any, arg2?: any, arg3?: any): TPromise { if (!input) { return TPromise.as(null); @@ -109,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); @@ -141,7 +144,7 @@ export class WorkbenchEditorService implements IWorkbenchEditorService { return this.editorPart.openEditor(input, options, arg3); } - public openEditors(editors: { input: IResourceInput, position: Position }[]): TPromise; + public openEditors(editors: { input: IResourceInput | IResourceDiffInput, 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 => { @@ -159,7 +162,7 @@ export class WorkbenchEditorService implements IWorkbenchEditorService { }); } - public replaceEditors(editors: { toReplace: IResourceInput, replaceWith: IResourceInput }[]): TPromise; + public replaceEditors(editors: { toReplace: IResourceInput | IResourceDiffInput, replaceWith: IResourceInput | IResourceDiffInput }[]): TPromise; public replaceEditors(editors: { toReplace: EditorInput, replaceWith: EditorInput, options?: IEditorOptions }[]): TPromise; public replaceEditors(editors: any[]): TPromise { return TPromise.join(editors.map(editor => this.createInput(editor.toReplace))).then(toReplaceInputs => { @@ -192,7 +195,7 @@ export class WorkbenchEditorService implements IWorkbenchEditorService { } public createInput(input: EditorInput): TPromise; - public createInput(input: IResourceInput): TPromise; + public createInput(input: IResourceInput | IResourceDiffInput): TPromise; public createInput(input: any): TPromise { // Workbench Input Support @@ -200,6 +203,18 @@ export class WorkbenchEditorService implements IWorkbenchEditorService { return TPromise.as(input); } + // Diff Editor Support + const resourceDiffInput = input; + if (resourceDiffInput.leftResource && resourceDiffInput.rightResource) { + return this.createInput({ resource: resourceDiffInput.leftResource }).then(leftInput => { + return this.createInput({ resource: resourceDiffInput.rightResource }).then(rightInput => { + const label = resourceDiffInput.label || toDiffLabel(resourceDiffInput.leftResource, resourceDiffInput.rightResource, this.workspaceContextService); + + return new DiffEditorInput(label, resourceDiffInput.description, leftInput, rightInput); + }); + }); + } + // Base Text Editor Support for inmemory resources const resourceInput = input; @@ -253,11 +268,13 @@ export class DelegatingWorkbenchEditorService extends WorkbenchEditorService { handler: IDelegatingWorkbenchEditorServiceHandler, @IUntitledEditorService untitledEditorService: IUntitledEditorService, @IInstantiationService instantiationService: IInstantiationService, + @IWorkspaceContextService workspaceContextService: IWorkspaceContextService, @IWorkbenchEditorService editorService: IWorkbenchEditorService ) { super( editorService, untitledEditorService, + workspaceContextService, instantiationService ); diff --git a/src/vs/workbench/services/editor/common/editorService.ts b/src/vs/workbench/services/editor/common/editorService.ts index 94e9e8bc3d5..abd54ac7c83 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 } from 'vs/platform/editor/common/editor'; +import { IEditorService, IEditor, IEditorInput, IEditorOptions, ITextEditorOptions, Position, Direction, IResourceInput, IResourceDiffInput } 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. + * Specific overload to open an instance of IResourceInput and IResourceDiffInput. */ - openEditor(input: IResourceInput, position?: Position): TPromise; - openEditor(input: IResourceInput, sideBySide?: boolean): TPromise; + openEditor(input: IResourceInput | IResourceDiffInput, position?: Position): TPromise; + openEditor(input: IResourceInput | IResourceDiffInput, 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, position: Position }[]): TPromise; + openEditors(editors: { input: IResourceInput | IResourceDiffInput, 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, replaceWith: IResourceInput }[]): TPromise; + replaceEditors(editors: { toReplace: IResourceInput | IResourceDiffInput, replaceWith: IResourceInput | IResourceDiffInput }[]): 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): TPromise; + createInput(input: IResourceInput | IResourceDiffInput): TPromise; } \ No newline at end of file