提交 6d8cbf85 编写于 作者: B Benjamin Pasero

fixes #8826

上级 1d080314
......@@ -194,8 +194,16 @@ export enum Verbosity {
export interface IEditorInput extends IDisposable {
/**
* Triggered when this input is disposed.
*/
onDispose: Event<void>;
/**
* Returns the associated resource of this input.
*/
getResource(): URI;
/**
* Returns the display name of this input.
*/
......
......@@ -14,7 +14,7 @@ import types = require('vs/base/common/types');
import errors = require('vs/base/common/errors');
import DOM = require('vs/base/browser/dom');
import { CodeEditor } from 'vs/editor/browser/codeEditor';
import { EditorInput, EditorOptions, toResource } from 'vs/workbench/common/editor';
import { EditorInput, EditorOptions } from 'vs/workbench/common/editor';
import { BaseEditor } from 'vs/workbench/browser/parts/editor/baseEditor';
import { IEditorViewState, IEditor, isCommonCodeEditor, isCommonDiffEditor } from 'vs/editor/common/editorCommon';
import { Position } from 'vs/platform/editor/common/editor';
......@@ -318,7 +318,7 @@ export abstract class BaseTextEditor extends BaseEditor {
}
if (this.input) {
return toResource(this.input);
return this.input.getResource();
}
return null;
......
......@@ -31,7 +31,7 @@ import { IResourceInput, IEditorInput } from 'vs/platform/editor/common/editor';
import { IModeService } from 'vs/editor/common/services/modeService';
import { getIconClasses } from 'vs/workbench/browser/labels';
import { IModelService } from 'vs/editor/common/services/modelService';
import { EditorInput, toResource, IWorkbenchEditorConfiguration } from 'vs/workbench/common/editor';
import { EditorInput, IWorkbenchEditorConfiguration } from 'vs/workbench/common/editor';
import { Component } from 'vs/workbench/common/component';
import Event, { Emitter } from 'vs/base/common/event';
import { IPartService } from 'vs/workbench/services/part/common/partService';
......@@ -1332,7 +1332,7 @@ export class EditorHistoryEntry extends EditorQuickOpenEntry {
}
function resourceForEditorHistory(input: EditorInput, fileService: IFileService): URI {
const resource = toResource(input);
const resource = input ? input.getResource() : void 0;
// For the editor history we only prefer resources that are either untitled or
// can be handled by the file service which indicates they are editable resources.
......
......@@ -124,6 +124,13 @@ export abstract class EditorInput implements IEditorInput {
return this._onDispose.event;
}
/**
* Returns the associated resource of this input if any.
*/
public getResource(): URI {
return null;
}
/**
* Returns the name of this input that can be shown to the user. Examples include showing the name of the input
* above the editor area when the input is shown.
......@@ -285,11 +292,6 @@ export interface IEncodingSupport {
*/
export interface IFileEditorInput extends IEditorInput, IEncodingSupport {
/**
* Gets the absolute file resource URI this input is about.
*/
getResource(): URI;
/**
* Sets the preferred encodingt to use for this input.
*/
......@@ -829,7 +831,7 @@ export function toResource(editor: IEditorInput, options?: IResourceOptions): UR
editor = editor.master;
}
const resource = doGetEditorResource(editor);
const resource = editor.getResource();
if (!options || !options.filter) {
return resource; // return early if no filter is specified
}
......@@ -859,18 +861,6 @@ export function toResource(editor: IEditorInput, options?: IResourceOptions): UR
return null;
}
// TODO@Ben every editor should have an associated resource
function doGetEditorResource(editor: IEditorInput): URI {
if (editor instanceof EditorInput && typeof (<any>editor).getResource === 'function') {
const candidate = (<any>editor).getResource();
if (candidate instanceof URI) {
return candidate;
}
}
return null;
}
class EditorInputFactoryRegistry implements IEditorInputFactoryRegistry {
private instantiationService: IInstantiationService;
private fileInputFactory: IFileInputFactory;
......
......@@ -1215,7 +1215,7 @@ export class EditorStacksModel implements IEditorStacksModel {
// Close the editor when it is no longer open in any group including diff editors
editorsToClose.forEach(editorToClose => {
const resource = toResource(editorToClose); // prefer resource to not close right-hand side editors of a diff editor
const resource = editorToClose ? editorToClose.getResource() : void 0; // prefer resource to not close right-hand side editors of a diff editor
if (!this.isOpen(resource || editorToClose)) {
editorToClose.close();
}
......
......@@ -8,7 +8,6 @@ import URI from 'vs/base/common/uri';
import Event, { Emitter } from 'vs/base/common/event';
import * as editorCommon from 'vs/editor/common/editorCommon';
import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService';
import { toResource } from 'vs/workbench/common/editor';
import { IRange } from 'vs/editor/common/core/range';
import { CursorChangeReason, ICursorPositionChangedEvent } from 'vs/editor/common/controller/cursorEvents';
import { ModelDecorationOptions } from 'vs/editor/common/model/textModelWithDecorations';
......@@ -55,7 +54,8 @@ export class RangeHighlightDecorations implements IDisposable {
}
private getEditor(resourceRange: IRangeHighlightDecoration): editorCommon.ICommonCodeEditor {
const resource = toResource(this.editorService.getActiveEditorInput());
const activeInput = this.editorService.getActiveEditorInput();
const resource = activeInput && activeInput.getResource();
if (resource) {
if (resource.toString() === resourceRange.resource.toString()) {
return <editorCommon.ICommonCodeEditor>this.editorService.getActiveEditor().getControl();
......
......@@ -1177,7 +1177,8 @@ export class GlobalCompareResourcesAction extends Action {
}
public run(): TPromise<any> {
const activeResource = toResource(this.editorService.getActiveEditorInput());
const activeInput = this.editorService.getActiveEditorInput();
const activeResource = activeInput ? activeInput.getResource() : void 0;
if (activeResource) {
// Keep as resource to compare
......@@ -1195,7 +1196,7 @@ export class GlobalCompareResourcesAction extends Action {
let description: string;
if (input instanceof EditorInput) {
resource = toResource(input);
resource = input.getResource();
} else {
resource = (input as IResourceInput).resource;
}
......
......@@ -240,8 +240,8 @@ export class FileEditorTracker implements IWorkbenchContribution {
for (let i = 0; i < editors.length; i++) {
const editor = editors[i];
if (editor && editor.position === stacks.positionOfGroup(group)) {
const editorResource = toResource(editor.input);
if (editor && editor.input && editor.position === stacks.positionOfGroup(group)) {
const editorResource = editor.input.getResource();
if (editorResource && resource.toString() === editorResource.toString()) {
const control = editor.getControl();
if (isCommonCodeEditor(control)) {
......
......@@ -16,7 +16,6 @@ import { IActionItem } from 'vs/base/browser/ui/actionbar/actionbar';
import { IMarkerService } from 'vs/platform/markers/common/markers';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { IEditorGroupService } from 'vs/workbench/services/group/common/groupService';
import { toResource } from 'vs/workbench/common/editor';
import { Panel } from 'vs/workbench/browser/panel';
import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService';
import Constants from 'vs/workbench/parts/markers/common/constants';
......@@ -285,7 +284,8 @@ export class MarkersPanel extends Panel {
}
private onEditorsChanged(): void {
this.currentActiveResource = toResource(this.editorService.getActiveEditorInput());
const activeInput = this.editorService.getActiveEditorInput();
this.currentActiveResource = activeInput ? activeInput.getResource() : void 0;
this.autoReveal();
}
......
......@@ -12,7 +12,7 @@ import { Dimension, Builder } from 'vs/base/browser/builder';
import { ArrayNavigator, INavigator } from 'vs/base/common/iterator';
import { Disposable, IDisposable, dispose } from 'vs/base/common/lifecycle';
import { KeyMod, KeyCode } from 'vs/base/common/keyCodes';
import { toResource, SideBySideEditorInput, EditorOptions, EditorInput } from 'vs/workbench/common/editor';
import { SideBySideEditorInput, EditorOptions, EditorInput } from 'vs/workbench/common/editor';
import { BaseEditor } from 'vs/workbench/browser/parts/editor/baseEditor';
import { ResourceEditorModel } from 'vs/workbench/common/editor/resourceEditorModel';
import { IEditorControl, Position, Verbosity } from 'vs/platform/editor/common/editor';
......@@ -226,7 +226,7 @@ export class PreferencesEditor extends BaseEditor {
}
private updateInput(oldInput: PreferencesEditorInput, newInput: PreferencesEditorInput, options?: EditorOptions): TPromise<void> {
const resource = toResource(newInput.master);
const resource = newInput.master.getResource();
this.settingsTargetsWidget.updateTargets(this.getSettingsConfigurationTargetUri(resource), this.getSettingsConfigurationTarget(resource));
return this.sideBySidePreferencesWidget.setInput(<DefaultPreferencesEditorInput>newInput.details, <EditorInput>newInput.master, options).then(({ defaultPreferencesRenderer, editablePreferencesRenderer }) => {
......@@ -267,7 +267,7 @@ export class PreferencesEditor extends BaseEditor {
private onWorkspaceFoldersChanged(): void {
if (this.input) {
const settingsResource = toResource((<PreferencesEditorInput>this.input).master);
const settingsResource = (<PreferencesEditorInput>this.input).master.getResource();
const targetResource = this.getSettingsConfigurationTargetUri(settingsResource);
if (!targetResource) {
this.switchSettings(this.preferencesService.userSettingsResource);
......@@ -277,7 +277,7 @@ export class PreferencesEditor extends BaseEditor {
private onWorkbenchStateChanged(): void {
if (this.input) {
const editableSettingsResource = toResource((<PreferencesEditorInput>this.input).master);
const editableSettingsResource = (<PreferencesEditorInput>this.input).master.getResource();
const newConfigurationTarget = this.getSettingsConfigurationTarget(editableSettingsResource);
if (newConfigurationTarget) {
if (newConfigurationTarget !== this.settingsTargetsWidget.configurationTarget) {
......@@ -528,7 +528,7 @@ class SideBySidePreferencesWidget extends Widget {
public setInput(defaultPreferencesEditorInput: DefaultPreferencesEditorInput, editablePreferencesEditorInput: EditorInput, options?: EditorOptions): TPromise<{ defaultPreferencesRenderer: IPreferencesRenderer<ISetting>, editablePreferencesRenderer: IPreferencesRenderer<ISetting> }> {
this.getOrCreateEditablePreferencesEditor(editablePreferencesEditorInput);
this.dolayout(this.sash.getVerticalSashLeft());
return TPromise.join([this.updateInput(this.defaultPreferencesEditor, defaultPreferencesEditorInput, DefaultSettingsEditorContribution.ID, toResource(editablePreferencesEditorInput), options),
return TPromise.join([this.updateInput(this.defaultPreferencesEditor, defaultPreferencesEditorInput, DefaultSettingsEditorContribution.ID, editablePreferencesEditorInput.getResource(), options),
this.updateInput(this.editablePreferencesEditor, editablePreferencesEditorInput, SettingsEditorContribution.ID, defaultPreferencesEditorInput.getResource(), options)])
.then(([defaultPreferencesRenderer, editablePreferencesRenderer]) => ({ defaultPreferencesRenderer, editablePreferencesRenderer }));
}
......
......@@ -23,7 +23,6 @@ import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/edi
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { ResolvedKeybinding, createKeybinding } from 'vs/base/common/keyCodes';
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
import { toResource } from 'vs/workbench/common/editor';
import { ServicesAccessor, IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { IListService } from 'vs/platform/list/browser/listService';
import { explorerItemToFileResource } from 'vs/workbench/parts/files/common/files';
......@@ -639,7 +638,8 @@ export class ReplaceAction extends AbstractSearchAndReplaceAction {
}
private hasToOpenFile(): boolean {
const file = toResource(this.editorService.getActiveEditorInput());
const activeInput = this.editorService.getActiveEditorInput();
const file = activeInput ? activeInput.getResource() : void 0;
if (file) {
return file.toString() === this.element.parent().resource().toString();
}
......
......@@ -10,7 +10,7 @@ import errors = require('vs/base/common/errors');
import URI from 'vs/base/common/uri';
import { IEditor } from 'vs/editor/common/editorCommon';
import { IEditor as IBaseEditor, IEditorInput, ITextEditorOptions, IResourceInput, ITextEditorSelection, Position as GroupPosition } from 'vs/platform/editor/common/editor';
import { Extensions as EditorExtensions, EditorInput, IEditorCloseEvent, toResource, IEditorGroup, IEditorInputFactoryRegistry } from 'vs/workbench/common/editor';
import { Extensions as EditorExtensions, EditorInput, IEditorCloseEvent, IEditorGroup, IEditorInputFactoryRegistry } from 'vs/workbench/common/editor';
import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService';
import { IHistoryService } from 'vs/workbench/services/history/common/history';
import { FileChangesEvent, IFileService, FileChangeType } from 'vs/platform/files/common/files';
......@@ -245,7 +245,7 @@ export class HistoryService extends BaseHistoryService implements IHistoryServic
// Track closing of pinned editor to support to reopen closed editors
if (event.pinned) {
const resource = toResource(event.editor);
const resource = event.editor ? event.editor.getResource() : void 0;
const supportsReopen = resource && this.fileService.canHandleResource(resource); // we only support file'ish things to reopen
if (supportsReopen) {
......@@ -592,7 +592,7 @@ export class HistoryService extends BaseHistoryService implements IHistoryServic
}
private preferResourceInput(input: IEditorInput): IEditorInput | IResourceInput {
const resource = toResource(input);
const resource = input ? input.getResource() : void 0;
const preferResourceInput = resource && this.fileService.canHandleResource(resource); // file'ish things prefer resources
if (preferResourceInput) {
return { resource };
......@@ -680,7 +680,7 @@ export class HistoryService extends BaseHistoryService implements IHistoryServic
}
if (arg2 instanceof EditorInput) {
const inputResource = toResource(arg2);
const inputResource = arg2.getResource();
return inputResource && this.fileService.canHandleResource(inputResource) && inputResource.toString() === resource.toString();
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册