提交 932b40df 编写于 作者: B Benjamin Pasero

debt - adopt IResourceDiffInput (for #17063)

上级 df2faa21
......@@ -21,7 +21,7 @@ import { extractResources } from 'vs/base/browser/dnd';
import { Builder, $ } from 'vs/base/browser/builder';
import { IPartService } from 'vs/workbench/services/part/common/partService';
import { AutoSaveConfiguration } from 'vs/platform/files/common/files';
import { toResource, EditorInput } from 'vs/workbench/common/editor';
import { toResource } from 'vs/workbench/common/editor';
import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService';
import { IEditorGroupService } from 'vs/workbench/services/group/common/groupService';
import { IMessageService } from 'vs/platform/message/common/message';
......@@ -29,7 +29,6 @@ import { IWorkspaceConfigurationService } from 'vs/workbench/services/configurat
import { IWindowsService, IWindowService, IWindowSettings } from 'vs/platform/windows/common/windows';
import { IContextMenuService } from 'vs/platform/contextview/browser/contextView';
import { IWindowIPCService } from 'vs/workbench/services/window/electron-browser/windowService';
import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';
import { IUntitledEditorService } from 'vs/workbench/services/untitled/common/untitledEditorService';
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
......@@ -45,7 +44,6 @@ import { ReloadWindowAction, ToggleDevToolsAction, ShowStartupPerformance, OpenR
import { KeyMod, KeyCode } from 'vs/base/common/keyCodes';
import { ICommandService } from 'vs/platform/commands/common/commands';
import { IViewletService } from 'vs/workbench/services/viewlet/browser/viewlet';
import { DiffEditorInput, toDiffLabel } from 'vs/workbench/common/editor/diffEditorInput';
import { Position, IResourceInput } from 'vs/platform/editor/common/editor';
import { IExtensionService } from 'vs/platform/extensions/common/extensions';
......@@ -91,7 +89,6 @@ export class ElectronWindow {
@IContextMenuService private contextMenuService: IContextMenuService,
@IKeybindingService private keybindingService: IKeybindingService,
@IEnvironmentService private environmentService: IEnvironmentService,
@IWorkspaceContextService private contextService: IWorkspaceContextService,
@IUntitledEditorService private untitledEditorService: IUntitledEditorService,
) {
this.win = win;
......@@ -382,10 +379,8 @@ export class ElectronWindow {
return this.partService.joinCreation().then(() => {
// In diffMode we open 2 resources as diff
if (diffMode) {
return TPromise.join(resources.map(f => this.editorService.createInput(f))).then((inputs: EditorInput[]) => {
return this.editorService.openEditor(new DiffEditorInput(toDiffLabel(resources[0].resource, resources[1].resource, this.contextService), null, inputs[0], inputs[1]));
});
if (diffMode && resources.length === 2) {
return this.editorService.openEditor({ leftResource: resources[0].resource, rightResource: resources[1].resource });
}
// For one file, just put it into the current active editor
......
......@@ -38,7 +38,6 @@ import { WorkbenchLayout } from 'vs/workbench/browser/layout';
import { IActionBarRegistry, Extensions as ActionBarExtensions } from 'vs/workbench/browser/actionBarRegistry';
import { PanelRegistry, Extensions as PanelExtensions } from 'vs/workbench/browser/panel';
import { QuickOpenController } from 'vs/workbench/browser/parts/quickopen/quickOpenController';
import { DiffEditorInput, toDiffLabel } from 'vs/workbench/common/editor/diffEditorInput';
import { getServices } from 'vs/platform/instantiation/common/extensions';
import { IUntitledEditorService } from 'vs/workbench/services/untitled/common/untitledEditorService';
import { WorkbenchEditorService } from 'vs/workbench/services/editor/browser/editorService';
......@@ -360,10 +359,8 @@ export class Workbench implements IPartService {
const filesToDiff = wbopt.filesToDiff;
// Files to diff is exclusive
if (filesToDiff && filesToDiff.length) {
return TPromise.join<EditorInput>(filesToDiff.map(resourceInput => this.editorService.createInput(resourceInput))).then((inputsToDiff) => {
return [{ input: new DiffEditorInput(toDiffLabel(filesToDiff[0].resource, filesToDiff[1].resource, this.contextService), null, inputsToDiff[0], inputsToDiff[1]) }];
});
if (filesToDiff && filesToDiff.length === 2) {
return this.editorService.createInput({ leftResource: filesToDiff[0].resource, rightResource: filesToDiff[1].resource }).then(input => [{ input }]);
}
// Otherwise: Open/Create files
......
......@@ -26,7 +26,6 @@ import { VIEWLET_ID } from 'vs/workbench/parts/files/common/files';
import labels = require('vs/base/common/labels');
import { ITextFileService } from 'vs/workbench/services/textfile/common/textfiles';
import { IFileService, IFileStat } from 'vs/platform/files/common/files';
import { toDiffLabel } from 'vs/workbench/common/editor/diffEditorInput';
import { toResource, IEditorIdentifier, EditorInput } from 'vs/workbench/common/editor';
import { FileStat, NewStatPlaceholder } from 'vs/workbench/parts/files/common/explorerViewModel';
import { ExplorerView } from 'vs/workbench/parts/files/browser/views/explorerView';
......@@ -1213,7 +1212,6 @@ export class CompareResourcesAction extends Action {
constructor(
resource: URI,
tree: ITree,
@IWorkspaceContextService private contextService: IWorkspaceContextService,
@IInstantiationService private instantiationService: IInstantiationService,
@IWorkbenchEditorService private editorService: IWorkbenchEditorService
) {
......@@ -1271,8 +1269,7 @@ export class CompareResourcesAction extends Action {
return this.editorService.openEditor({
leftResource: globalResourceToCompare,
rightResource: this.resource,
label: toDiffLabel(globalResourceToCompare, this.resource, this.contextService)
rightResource: this.resource
});
}
}
......
......@@ -11,7 +11,6 @@ import { toErrorMessage } from 'vs/base/common/errorMessage';
import paths = require('vs/base/common/paths');
import { Action } from 'vs/base/common/actions';
import URI from 'vs/base/common/uri';
import { ICommandService } from 'vs/platform/commands/common/commands';
import { EditorInputAction } from 'vs/workbench/browser/parts/editor/baseEditor';
import { SaveFileAsAction, RevertFileAction, SaveFileAction } from 'vs/workbench/parts/files/browser/fileActions';
import { IFileOperationResult, FileOperationResult } from 'vs/platform/files/common/files';
......@@ -186,7 +185,6 @@ class ResolveSaveConflictMessage implements IMessageWithAction {
@IMessageService private messageService: IMessageService,
@IInstantiationService private instantiationService: IInstantiationService,
@IWorkbenchEditorService private editorService: IWorkbenchEditorService,
@ICommandService commandService: ICommandService,
@IEnvironmentService private environmentService: IEnvironmentService
) {
this.model = model;
......@@ -204,7 +202,7 @@ class ResolveSaveConflictMessage implements IMessageWithAction {
const name = paths.basename(resource.fsPath);
const editorLabel = nls.localize('saveConflictDiffLabel', "{0} (on disk) ↔ {1} (in {2}) - Resolve save conflict", name, name, this.environmentService.appNameLong);
return commandService.executeCommand('_workbench.diff', [URI.from({ scheme: CONFLICT_RESOLUTION_SCHEME, path: resource.fsPath }), resource, editorLabel]).then(() => {
return this.editorService.openEditor({ leftResource: URI.from({ scheme: CONFLICT_RESOLUTION_SCHEME, path: resource.fsPath }), rightResource: resource, label: editorLabel }).then(() => {
// We have to bring the model into conflict resolution mode to prevent subsequent save erros when the user makes edits
this.model.setConflictResolutionMode();
......
......@@ -10,7 +10,6 @@ import URI from 'vs/base/common/uri';
import * as network from 'vs/base/common/network';
import { Disposable } from 'vs/base/common/lifecycle';
import { IReplaceService } from 'vs/workbench/parts/search/common/replace';
import { EditorInput } from 'vs/workbench/common/editor';
import { IEditorService } from 'vs/platform/editor/common/editor';
import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService';
import { IModelService } from 'vs/editor/common/services/modelService';
......@@ -18,7 +17,6 @@ import { Match, FileMatch, FileMatchOrMatch, ISearchWorkbenchService } from 'vs/
import { BulkEdit, IResourceEdit, createBulkEdit } from 'vs/editor/common/services/bulkEdit';
import { IProgressRunner } from 'vs/platform/progress/common/progress';
import { IDiffEditor } from 'vs/editor/browser/editorBrowser';
import { DiffEditorInput } from 'vs/workbench/common/editor/diffEditorInput';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { ITextModelResolverService, ITextModelContentProvider } from 'vs/editor/common/services/resolverService';
import { IWorkbenchContribution } from 'vs/workbench/common/contributions';
......@@ -128,16 +126,23 @@ export class ReplaceService implements IReplaceService {
public openReplacePreview(element: FileMatchOrMatch, preserveFocus?: boolean, sideBySide?: boolean, pinned?: boolean): TPromise<any> {
this.telemetryService.publicLog('replace.open.previewEditor');
const fileMatch = element instanceof Match ? element.parent() : element;
return this.createInput(fileMatch).then((editorInput) => {
this.editorService.openEditor(editorInput, { preserveFocus, pinned, revealIfVisible: true })
.then(editor => {
this.updateReplacePreview(fileMatch).then(() => {
let editorControl = (<IDiffEditor>editor.getControl());
if (element instanceof Match) {
editorControl.revealLineInCenter(element.range().startLineNumber);
}
});
}, errors.onUnexpectedError);
return this.editorService.openEditor({
leftResource: fileMatch.resource(),
rightResource: this.getReplacePreviewUri(fileMatch),
label: nls.localize('fileReplaceChanges', "{0} ↔ {1} (Replace Preview)", fileMatch.name(), fileMatch.name()),
options: {
preserveFocus,
pinned,
revealIfVisible: true
}
}).then(editor => {
this.updateReplacePreview(fileMatch).then(() => {
let editorControl = (<IDiffEditor>editor.getControl());
if (element instanceof Match) {
editorControl.revealLineInCenter(element.range().startLineNumber);
}
});
}, errors.onUnexpectedError);
}
......@@ -168,13 +173,6 @@ export class ReplaceService implements IReplaceService {
return resourceEdit;
}
private createInput(fileMatch: FileMatch): TPromise<DiffEditorInput> {
return TPromise.join([this.editorService.createInput({ resource: fileMatch.resource() }), this.editorService.createInput({ resource: this.getReplacePreviewUri(fileMatch) })])
.then(([left, right]) => {
return new DiffEditorInput(nls.localize('fileReplaceChanges', "{0} ↔ {1} (Replace Preview)", fileMatch.name(), fileMatch.name()), '', <EditorInput>left, <EditorInput>right);
});
}
private getReplacePreviewUri(fileMatch: FileMatch): URI {
return fileMatch.resource().with({ scheme: network.Schemas.internal, fragment: 'preview' });
}
......
......@@ -138,9 +138,9 @@ export class WorkbenchEditorService implements IWorkbenchEditorService {
/**
* Allow subclasses to implement their own behavior for opening editor (see below).
*/
protected doOpenEditor(input: EditorInput, options?: EditorOptions, sideBySide?: boolean): TPromise<IEditor>;
protected doOpenEditor(input: EditorInput, options?: EditorOptions, position?: Position): TPromise<IEditor>;
protected doOpenEditor(input: EditorInput, options?: EditorOptions, arg3?: any): TPromise<IEditor> {
protected doOpenEditor(input: IEditorInput, options?: EditorOptions, sideBySide?: boolean): TPromise<IEditor>;
protected doOpenEditor(input: IEditorInput, options?: EditorOptions, position?: Position): TPromise<IEditor>;
protected doOpenEditor(input: IEditorInput, options?: EditorOptions, arg3?: any): TPromise<IEditor> {
return this.editorPart.openEditor(input, options, arg3);
}
......@@ -148,7 +148,7 @@ export class WorkbenchEditorService implements IWorkbenchEditorService {
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 => {
const typedInputs: { input: EditorInput, position: Position, options?: EditorOptions }[] = inputs.map((input, index) => {
const typedInputs: { input: IEditorInput, position: Position, options?: EditorOptions }[] = inputs.map((input, index) => {
const options = editors[index].input instanceof EditorInput ? this.toOptions(editors[index].options) : TextEditorOptions.from(editors[index].input);
return {
......@@ -163,11 +163,11 @@ export class WorkbenchEditorService implements IWorkbenchEditorService {
}
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: IEditorInput, replaceWith: IEditorInput, options?: IEditorOptions }[]): 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.replaceWith))).then(replaceWithInputs => {
const typedReplacements: { toReplace: EditorInput, replaceWith: EditorInput, options?: EditorOptions }[] = editors.map((editor, index) => {
const typedReplacements: { toReplace: IEditorInput, replaceWith: IEditorInput, options?: EditorOptions }[] = editors.map((editor, index) => {
const options = editor.toReplace instanceof EditorInput ? this.toOptions(editor.options) : TextEditorOptions.from(editor.replaceWith);
return {
......@@ -194,7 +194,7 @@ export class WorkbenchEditorService implements IWorkbenchEditorService {
return this.editorPart.closeAllEditors(except);
}
public createInput(input: EditorInput): TPromise<EditorInput>;
public createInput(input: IEditorInput): TPromise<EditorInput>;
public createInput(input: IResourceInput | IResourceDiffInput): TPromise<EditorInput>;
public createInput(input: any): TPromise<IEditorInput> {
......@@ -250,8 +250,8 @@ export class WorkbenchEditorService implements IWorkbenchEditorService {
}
export interface IDelegatingWorkbenchEditorServiceHandler {
(input: EditorInput, options?: EditorOptions, sideBySide?: boolean): TPromise<BaseEditor>;
(input: EditorInput, options?: EditorOptions, position?: Position): TPromise<BaseEditor>;
(input: IEditorInput, options?: EditorOptions, sideBySide?: boolean): TPromise<BaseEditor>;
(input: IEditorInput, options?: EditorOptions, position?: Position): TPromise<BaseEditor>;
}
/**
......@@ -281,9 +281,9 @@ export class DelegatingWorkbenchEditorService extends WorkbenchEditorService {
this.handler = handler;
}
protected doOpenEditor(input: EditorInput, options?: EditorOptions, sideBySide?: boolean): TPromise<IEditor>;
protected doOpenEditor(input: EditorInput, options?: EditorOptions, position?: Position): TPromise<IEditor>;
protected doOpenEditor(input: EditorInput, options?: EditorOptions, arg3?: any): TPromise<IEditor> {
protected doOpenEditor(input: IEditorInput, options?: EditorOptions, sideBySide?: boolean): TPromise<IEditor>;
protected doOpenEditor(input: IEditorInput, options?: EditorOptions, position?: Position): TPromise<IEditor>;
protected doOpenEditor(input: IEditorInput, options?: EditorOptions, arg3?: any): TPromise<IEditor> {
return this.handler(input, options, arg3).then(editor => {
if (editor) {
return TPromise.as<BaseEditor>(editor);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册