提交 57f3b4e8 编写于 作者: B Benjamin Pasero

debt - introduce IResourceDiffInput (for #17063)

上级 b09b9a3a
...@@ -55,6 +55,34 @@ export interface IResourceInput { ...@@ -55,6 +55,34 @@ export interface IResourceInput {
options?: ITextEditorOptions; 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 { export interface IEditorControl {
} }
......
...@@ -11,7 +11,7 @@ import types = require('vs/base/common/types'); ...@@ -11,7 +11,7 @@ import types = require('vs/base/common/types');
import URI from 'vs/base/common/uri'; import URI from 'vs/base/common/uri';
import { IDisposable, dispose } from 'vs/base/common/lifecycle'; import { IDisposable, dispose } from 'vs/base/common/lifecycle';
import { IEditor, ICommonCodeEditor, IEditorViewState, IEditorOptions as ICodeEditorOptions, IModel } from 'vs/editor/common/editorCommon'; 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 { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';
import { IEditorGroupService } from 'vs/workbench/services/group/common/groupService'; import { IEditorGroupService } from 'vs/workbench/services/group/common/groupService';
import { SyncDescriptor, AsyncDescriptor } from 'vs/platform/instantiation/common/descriptors'; import { SyncDescriptor, AsyncDescriptor } from 'vs/platform/instantiation/common/descriptors';
...@@ -577,7 +577,7 @@ export class TextEditorOptions extends EditorOptions { ...@@ -577,7 +577,7 @@ export class TextEditorOptions extends EditorOptions {
private editorViewState: IEditorViewState; private editorViewState: IEditorViewState;
private editorOptions: ICodeEditorOptions; private editorOptions: ICodeEditorOptions;
public static from(input: IResourceInput): TextEditorOptions { public static from(input: IResourceInput | IResourceDiffInput): TextEditorOptions {
let options: TextEditorOptions = null; let options: TextEditorOptions = null;
if (input && input.options) { 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') { if (input.options.selection || input.options.forceOpen || input.options.revealIfVisible || input.options.preserveFocus || input.options.pinned || input.options.inactive || typeof input.options.index === 'number') {
......
...@@ -11,8 +11,6 @@ import { Action } from 'vs/base/common/actions'; ...@@ -11,8 +11,6 @@ import { Action } from 'vs/base/common/actions';
import { IWindowIPCService } from 'vs/workbench/services/window/electron-browser/windowService'; import { IWindowIPCService } from 'vs/workbench/services/window/electron-browser/windowService';
import { IWindowService, IWindowsService } from 'vs/platform/windows/common/windows'; import { IWindowService, IWindowsService } from 'vs/platform/windows/common/windows';
import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService'; 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 nls = require('vs/nls');
import product from 'vs/platform/node/product'; import product from 'vs/platform/node/product';
import pkg from 'vs/platform/node/package'; import pkg from 'vs/platform/node/package';
...@@ -608,18 +606,13 @@ export class KeybindingsReferenceAction extends Action { ...@@ -608,18 +606,13 @@ export class KeybindingsReferenceAction extends Action {
CommandsRegistry.registerCommand('_workbench.diff', function (accessor: ServicesAccessor, args: [URI, URI, string, string]) { CommandsRegistry.registerCommand('_workbench.diff', function (accessor: ServicesAccessor, args: [URI, URI, string, string]) {
const editorService = accessor.get(IWorkbenchEditorService); const editorService = accessor.get(IWorkbenchEditorService);
let [left, right, label, description] = args; let [leftResource, rightResource, label, description] = args;
if (!label) { 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 => { return editorService.openEditor({ leftResource, rightResource, label, description }).then(() => {
const [left, right] = inputs;
const diff = new DiffEditorInput(label, description, <EditorInput>left, <EditorInput>right);
return editorService.openEditor(diff);
}).then(() => {
return void 0; return void 0;
}); });
}); });
......
...@@ -47,7 +47,6 @@ import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace ...@@ -47,7 +47,6 @@ import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace
import { Keybinding, KeyMod, KeyCode } from 'vs/base/common/keyCodes'; import { Keybinding, KeyMod, KeyCode } from 'vs/base/common/keyCodes';
import { Selection } from 'vs/editor/common/core/selection'; import { Selection } from 'vs/editor/common/core/selection';
import { getCodeEditor } from 'vs/editor/common/services/codeEditorService'; import { getCodeEditor } from 'vs/editor/common/services/codeEditorService';
import { ICommandService } from 'vs/platform/commands/common/commands';
export interface IEditableData { export interface IEditableData {
action: IAction; action: IAction;
...@@ -1216,7 +1215,6 @@ export class CompareResourcesAction extends Action { ...@@ -1216,7 +1215,6 @@ export class CompareResourcesAction extends Action {
tree: ITree, tree: ITree,
@IWorkspaceContextService private contextService: IWorkspaceContextService, @IWorkspaceContextService private contextService: IWorkspaceContextService,
@IInstantiationService private instantiationService: IInstantiationService, @IInstantiationService private instantiationService: IInstantiationService,
@ICommandService private commandService: ICommandService,
@IWorkbenchEditorService private editorService: IWorkbenchEditorService @IWorkbenchEditorService private editorService: IWorkbenchEditorService
) { ) {
super('workbench.files.action.compareFiles', CompareResourcesAction.computeLabel()); super('workbench.files.action.compareFiles', CompareResourcesAction.computeLabel());
...@@ -1271,7 +1269,11 @@ export class CompareResourcesAction extends Action { ...@@ -1271,7 +1269,11 @@ export class CompareResourcesAction extends Action {
this.tree.clearHighlight(); 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)
});
} }
} }
......
...@@ -15,9 +15,11 @@ import { ResourceEditorInput } from 'vs/workbench/common/editor/resourceEditorIn ...@@ -15,9 +15,11 @@ import { ResourceEditorInput } from 'vs/workbench/common/editor/resourceEditorIn
import { UntitledEditorInput } from 'vs/workbench/common/editor/untitledEditorInput'; import { UntitledEditorInput } from 'vs/workbench/common/editor/untitledEditorInput';
import { IUntitledEditorService } from 'vs/workbench/services/untitled/common/untitledEditorService'; import { IUntitledEditorService } from 'vs/workbench/services/untitled/common/untitledEditorService';
import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService'; 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 { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { AsyncDescriptor0 } from 'vs/platform/instantiation/common/descriptors'; 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 { export interface IEditorPart {
openEditor(input?: IEditorInput, options?: IEditorOptions | ITextEditorOptions, sideBySide?: boolean): TPromise<BaseEditor>; openEditor(input?: IEditorInput, options?: IEditorOptions | ITextEditorOptions, sideBySide?: boolean): TPromise<BaseEditor>;
...@@ -42,10 +44,11 @@ export class WorkbenchEditorService implements IWorkbenchEditorService { ...@@ -42,10 +44,11 @@ export class WorkbenchEditorService implements IWorkbenchEditorService {
constructor( constructor(
editorPart: IEditorPart | IWorkbenchEditorService, editorPart: IEditorPart | IWorkbenchEditorService,
@IUntitledEditorService private untitledEditorService: IUntitledEditorService, @IUntitledEditorService private untitledEditorService: IUntitledEditorService,
@IWorkspaceContextService private workspaceContextService: IWorkspaceContextService,
@IInstantiationService private instantiationService?: IInstantiationService @IInstantiationService private instantiationService?: IInstantiationService
) { ) {
this.editorPart = editorPart; this.editorPart = editorPart;
this.fileInputDescriptor = (<IEditorRegistry>Registry.as(Extensions.Editors)).getDefaultFileInput(); this.fileInputDescriptor = Registry.as<IEditorRegistry>(Extensions.Editors).getDefaultFileInput();
} }
public getActiveEditor(): IEditor { public getActiveEditor(): IEditor {
...@@ -85,8 +88,8 @@ export class WorkbenchEditorService implements IWorkbenchEditorService { ...@@ -85,8 +88,8 @@ export class WorkbenchEditorService implements IWorkbenchEditorService {
public openEditor(input: IEditorInput, options?: IEditorOptions, sideBySide?: boolean): TPromise<IEditor>; public openEditor(input: IEditorInput, options?: IEditorOptions, sideBySide?: boolean): TPromise<IEditor>;
public openEditor(input: IEditorInput, options?: IEditorOptions, position?: Position): TPromise<IEditor>; public openEditor(input: IEditorInput, options?: IEditorOptions, position?: Position): TPromise<IEditor>;
public openEditor(input: IResourceInput, position?: Position): TPromise<IEditor>; public openEditor(input: IResourceInput | IResourceDiffInput, position?: Position): TPromise<IEditor>;
public openEditor(input: IResourceInput, sideBySide?: boolean): TPromise<IEditor>; public openEditor(input: IResourceInput | IResourceDiffInput, sideBySide?: boolean): TPromise<IEditor>;
public openEditor(input: any, arg2?: any, arg3?: any): TPromise<IEditor> { public openEditor(input: any, arg2?: any, arg3?: any): TPromise<IEditor> {
if (!input) { if (!input) {
return TPromise.as<IEditor>(null); return TPromise.as<IEditor>(null);
...@@ -109,7 +112,7 @@ export class WorkbenchEditorService implements IWorkbenchEditorService { ...@@ -109,7 +112,7 @@ export class WorkbenchEditorService implements IWorkbenchEditorService {
} }
// Untyped Text Editor Support (required for code that uses this service below workbench level) // Untyped Text Editor Support (required for code that uses this service below workbench level)
const textInput = <IResourceInput>input; const textInput = <IResourceInput | IResourceDiffInput>input;
return this.createInput(textInput).then(typedInput => { return this.createInput(textInput).then(typedInput => {
if (typedInput) { if (typedInput) {
return this.doOpenEditor(typedInput, TextEditorOptions.from(textInput), arg2); return this.doOpenEditor(typedInput, TextEditorOptions.from(textInput), arg2);
...@@ -141,7 +144,7 @@ export class WorkbenchEditorService implements IWorkbenchEditorService { ...@@ -141,7 +144,7 @@ export class WorkbenchEditorService implements IWorkbenchEditorService {
return this.editorPart.openEditor(input, options, arg3); return this.editorPart.openEditor(input, options, arg3);
} }
public openEditors(editors: { input: IResourceInput, position: Position }[]): TPromise<IEditor[]>; public openEditors(editors: { input: IResourceInput | IResourceDiffInput, position: Position }[]): TPromise<IEditor[]>;
public openEditors(editors: { input: IEditorInput, position: Position, options?: IEditorOptions }[]): TPromise<IEditor[]>; public openEditors(editors: { input: IEditorInput, position: Position, options?: IEditorOptions }[]): TPromise<IEditor[]>;
public openEditors(editors: any[]): TPromise<IEditor[]> { public openEditors(editors: any[]): TPromise<IEditor[]> {
return TPromise.join(editors.map(editor => this.createInput(editor.input))).then(inputs => { return TPromise.join(editors.map(editor => this.createInput(editor.input))).then(inputs => {
...@@ -159,7 +162,7 @@ export class WorkbenchEditorService implements IWorkbenchEditorService { ...@@ -159,7 +162,7 @@ export class WorkbenchEditorService implements IWorkbenchEditorService {
}); });
} }
public replaceEditors(editors: { toReplace: IResourceInput, replaceWith: IResourceInput }[]): TPromise<BaseEditor[]>; public replaceEditors(editors: { toReplace: IResourceInput | IResourceDiffInput, replaceWith: IResourceInput | IResourceDiffInput }[]): TPromise<BaseEditor[]>;
public replaceEditors(editors: { toReplace: EditorInput, replaceWith: EditorInput, options?: IEditorOptions }[]): TPromise<BaseEditor[]>; public replaceEditors(editors: { toReplace: EditorInput, replaceWith: EditorInput, options?: IEditorOptions }[]): TPromise<BaseEditor[]>;
public replaceEditors(editors: any[]): TPromise<BaseEditor[]> { public replaceEditors(editors: any[]): TPromise<BaseEditor[]> {
return TPromise.join(editors.map(editor => this.createInput(editor.toReplace))).then(toReplaceInputs => { return TPromise.join(editors.map(editor => this.createInput(editor.toReplace))).then(toReplaceInputs => {
...@@ -192,7 +195,7 @@ export class WorkbenchEditorService implements IWorkbenchEditorService { ...@@ -192,7 +195,7 @@ export class WorkbenchEditorService implements IWorkbenchEditorService {
} }
public createInput(input: EditorInput): TPromise<EditorInput>; public createInput(input: EditorInput): TPromise<EditorInput>;
public createInput(input: IResourceInput): TPromise<EditorInput>; public createInput(input: IResourceInput | IResourceDiffInput): TPromise<EditorInput>;
public createInput(input: any): TPromise<IEditorInput> { public createInput(input: any): TPromise<IEditorInput> {
// Workbench Input Support // Workbench Input Support
...@@ -200,6 +203,18 @@ export class WorkbenchEditorService implements IWorkbenchEditorService { ...@@ -200,6 +203,18 @@ export class WorkbenchEditorService implements IWorkbenchEditorService {
return TPromise.as<EditorInput>(input); return TPromise.as<EditorInput>(input);
} }
// Diff Editor Support
const resourceDiffInput = <IResourceDiffInput>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 // Base Text Editor Support for inmemory resources
const resourceInput = <IResourceInput>input; const resourceInput = <IResourceInput>input;
...@@ -253,11 +268,13 @@ export class DelegatingWorkbenchEditorService extends WorkbenchEditorService { ...@@ -253,11 +268,13 @@ export class DelegatingWorkbenchEditorService extends WorkbenchEditorService {
handler: IDelegatingWorkbenchEditorServiceHandler, handler: IDelegatingWorkbenchEditorServiceHandler,
@IUntitledEditorService untitledEditorService: IUntitledEditorService, @IUntitledEditorService untitledEditorService: IUntitledEditorService,
@IInstantiationService instantiationService: IInstantiationService, @IInstantiationService instantiationService: IInstantiationService,
@IWorkspaceContextService workspaceContextService: IWorkspaceContextService,
@IWorkbenchEditorService editorService: IWorkbenchEditorService @IWorkbenchEditorService editorService: IWorkbenchEditorService
) { ) {
super( super(
editorService, editorService,
untitledEditorService, untitledEditorService,
workspaceContextService,
instantiationService instantiationService
); );
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
import { TPromise } from 'vs/base/common/winjs.base'; import { TPromise } from 'vs/base/common/winjs.base';
import { createDecorator, ServiceIdentifier } from 'vs/platform/instantiation/common/instantiation'; 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<IWorkbenchEditorService>('editorService'); export const IWorkbenchEditorService = createDecorator<IWorkbenchEditorService>('editorService');
...@@ -49,23 +49,23 @@ export interface IWorkbenchEditorService extends IEditorService { ...@@ -49,23 +49,23 @@ export interface IWorkbenchEditorService extends IEditorService {
openEditor(input: IEditorInput, options?: IEditorOptions | ITextEditorOptions, sideBySide?: boolean): TPromise<IEditor>; openEditor(input: IEditorInput, options?: IEditorOptions | ITextEditorOptions, sideBySide?: boolean): TPromise<IEditor>;
/** /**
* Specific overload to open an instance of IResourceInput. * Specific overload to open an instance of IResourceInput and IResourceDiffInput.
*/ */
openEditor(input: IResourceInput, position?: Position): TPromise<IEditor>; openEditor(input: IResourceInput | IResourceDiffInput, position?: Position): TPromise<IEditor>;
openEditor(input: IResourceInput, sideBySide?: boolean): TPromise<IEditor>; openEditor(input: IResourceInput | IResourceDiffInput, sideBySide?: boolean): TPromise<IEditor>;
/** /**
* Similar to #openEditor() but allows to open multiple editors for different positions at the same time. If there are * 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. * 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<IEditor[]>; openEditors(editors: { input: IResourceInput | IResourceDiffInput, position: Position }[]): TPromise<IEditor[]>;
openEditors(editors: { input: IEditorInput, position: Position, options?: IEditorOptions | ITextEditorOptions }[]): TPromise<IEditor[]>; openEditors(editors: { input: IEditorInput, position: Position, options?: IEditorOptions | ITextEditorOptions }[]): TPromise<IEditor[]>;
/** /**
* Given a list of editors to replace, will look across all groups where this editor is open (active or hidden) * 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. * and replace it with the new editor and the provied options.
*/ */
replaceEditors(editors: { toReplace: IResourceInput, replaceWith: IResourceInput }[]): TPromise<IEditor[]>; replaceEditors(editors: { toReplace: IResourceInput | IResourceDiffInput, replaceWith: IResourceInput | IResourceDiffInput }[]): TPromise<IEditor[]>;
replaceEditors(editors: { toReplace: IEditorInput, replaceWith: IEditorInput, options?: IEditorOptions | ITextEditorOptions }[]): TPromise<IEditor[]>; replaceEditors(editors: { toReplace: IEditorInput, replaceWith: IEditorInput, options?: IEditorOptions | ITextEditorOptions }[]): TPromise<IEditor[]>;
/** /**
...@@ -88,5 +88,5 @@ export interface IWorkbenchEditorService extends IEditorService { ...@@ -88,5 +88,5 @@ export interface IWorkbenchEditorService extends IEditorService {
/** /**
* Allows to resolve an untyped input to a workbench typed instanceof editor input * Allows to resolve an untyped input to a workbench typed instanceof editor input
*/ */
createInput(input: IResourceInput): TPromise<IEditorInput>; createInput(input: IResourceInput | IResourceDiffInput): TPromise<IEditorInput>;
} }
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册