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

debt - introduce IResourceDiffInput (for #17063)

上级 b09b9a3a
......@@ -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 {
}
......
......@@ -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') {
......
......@@ -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, <EditorInput>left, <EditorInput>right);
return editorService.openEditor(diff);
}).then(() => {
return editorService.openEditor({ leftResource, rightResource, label, description }).then(() => {
return void 0;
});
});
......
......@@ -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)
});
}
}
......
......@@ -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<BaseEditor>;
......@@ -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 = (<IEditorRegistry>Registry.as(Extensions.Editors)).getDefaultFileInput();
this.fileInputDescriptor = Registry.as<IEditorRegistry>(Extensions.Editors).getDefaultFileInput();
}
public getActiveEditor(): IEditor {
......@@ -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, position?: Position): TPromise<IEditor>;
public openEditor(input: IResourceInput, position?: Position): TPromise<IEditor>;
public openEditor(input: IResourceInput, sideBySide?: boolean): TPromise<IEditor>;
public openEditor(input: IResourceInput | IResourceDiffInput, position?: Position): TPromise<IEditor>;
public openEditor(input: IResourceInput | IResourceDiffInput, sideBySide?: boolean): TPromise<IEditor>;
public openEditor(input: any, arg2?: any, arg3?: any): TPromise<IEditor> {
if (!input) {
return TPromise.as<IEditor>(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 = <IResourceInput>input;
const textInput = <IResourceInput | IResourceDiffInput>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<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: any[]): TPromise<IEditor[]> {
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<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: any[]): TPromise<BaseEditor[]> {
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<EditorInput>;
public createInput(input: IResourceInput): TPromise<EditorInput>;
public createInput(input: IResourceInput | IResourceDiffInput): TPromise<EditorInput>;
public createInput(input: any): TPromise<IEditorInput> {
// Workbench Input Support
......@@ -200,6 +203,18 @@ export class WorkbenchEditorService implements IWorkbenchEditorService {
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
const resourceInput = <IResourceInput>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
);
......
......@@ -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<IWorkbenchEditorService>('editorService');
......@@ -49,23 +49,23 @@ export interface IWorkbenchEditorService extends IEditorService {
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, sideBySide?: boolean): TPromise<IEditor>;
openEditor(input: IResourceInput | IResourceDiffInput, position?: Position): 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
* 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[]>;
/**
* 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<IEditor[]>;
replaceEditors(editors: { toReplace: IResourceInput | IResourceDiffInput, replaceWith: IResourceInput | IResourceDiffInput }[]): TPromise<IEditor[]>;
replaceEditors(editors: { toReplace: IEditorInput, replaceWith: IEditorInput, options?: IEditorOptions | ITextEditorOptions }[]): TPromise<IEditor[]>;
/**
......@@ -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<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.
先完成此消息的编辑!
想要评论请 注册