提交 7685c6ed 编写于 作者: B Benjamin Pasero

editors - some code cleanup

上级 5f0b0b9c
......@@ -28,9 +28,9 @@ export class ResourceEditorInput extends AbstractTextResourceEditorInput impleme
private modelReference: Promise<IReference<ITextEditorModel>> | undefined = undefined;
constructor(
resource: URI,
private name: string | undefined,
private description: string | undefined,
resource: URI,
private preferredMode: string | undefined,
@ITextModelService private readonly textModelResolverService: ITextModelService,
@ITextFileService textFileService: ITextFileService,
......
......@@ -3,6 +3,7 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { Registry } from 'vs/platform/registry/common/platform';
import { coalesce, distinct } from 'vs/base/common/arrays';
import { Emitter, Event } from 'vs/base/common/event';
import { Lazy } from 'vs/base/common/lazy';
......@@ -21,11 +22,10 @@ import { IStorageService } from 'vs/platform/storage/common/storage';
import * as colorRegistry from 'vs/platform/theme/common/colorRegistry';
import { registerThemingParticipant } from 'vs/platform/theme/common/themeService';
import { IWorkbenchContribution } from 'vs/workbench/common/contributions';
import { EditorInput, EditorOptions, GroupIdentifier, IEditorInput, IEditorPane } from 'vs/workbench/common/editor';
import { EditorInput, EditorOptions, GroupIdentifier, IEditorInput, IEditorPane, IEditorInputFactoryRegistry, Extensions as EditorInputExtensions } from 'vs/workbench/common/editor';
import { DiffEditorInput } from 'vs/workbench/common/editor/diffEditorInput';
import { CONTEXT_CUSTOM_EDITORS, CONTEXT_FOCUSED_CUSTOM_EDITOR_IS_EDITABLE, CustomEditorCapabilities, CustomEditorInfo, CustomEditorInfoCollection, CustomEditorPriority, ICustomEditorService } from 'vs/workbench/contrib/customEditor/common/customEditor';
import { CustomEditorModelManager } from 'vs/workbench/contrib/customEditor/common/customEditorModelManager';
import { FileEditorInput } from 'vs/workbench/contrib/files/common/editors/fileEditorInput';
import { defaultEditorOverrideEntry } from 'vs/workbench/contrib/files/common/openWith';
import { IWebviewService, webviewHasOwnEditFunctionsContext } from 'vs/workbench/contrib/webview/browser/webview';
import { CustomEditorAssociation, CustomEditorsAssociations, customEditorsAssociationsSettingId } from 'vs/workbench/services/editor/common/editorAssociationsSetting';
......@@ -48,6 +48,8 @@ export class CustomEditorService extends Disposable implements ICustomEditorServ
private readonly _onDidChangeViewTypes = new Emitter<void>();
onDidChangeViewTypes: Event<void> = this._onDidChangeViewTypes.event;
private readonly _fileEditorInputFactory = Registry.as<IEditorInputFactoryRegistry>(EditorInputExtensions.EditorInputFactories).getFileEditorInputFactory();
constructor(
@IContextKeyService contextKeyService: IContextKeyService,
@IFileService fileService: IFileService,
......@@ -322,7 +324,7 @@ export class CustomEditorService extends Disposable implements ICustomEditorServ
const editorsToReplace = new Map<GroupIdentifier, IEditorInput[]>();
for (const group of this.editorGroupService.groups) {
for (const editor of group.editors) {
if (editor instanceof FileEditorInput
if (this._fileEditorInputFactory.isFileEditorInput(editor)
&& !(editor instanceof CustomEditorInput)
&& isEqual(editor.resource, newResource)
) {
......@@ -420,6 +422,9 @@ export class CustomEditorService extends Disposable implements ICustomEditorServ
}
export class CustomEditorContribution extends Disposable implements IWorkbenchContribution {
private readonly _fileEditorInputFactory = Registry.as<IEditorInputFactoryRegistry>(EditorInputExtensions.EditorInputFactories).getFileEditorInputFactory();
constructor(
@IEditorService private readonly editorService: IEditorService,
@ICustomEditorService private readonly customEditorService: ICustomEditorService,
......@@ -441,7 +446,7 @@ export class CustomEditorContribution extends Disposable implements IWorkbenchCo
return [
{
...defaultEditorOverrideEntry,
active: currentEditor instanceof FileEditorInput,
active: this._fileEditorInputFactory.isFileEditorInput(currentEditor),
},
...customEditors.allEditors
.filter(entry => entry.id !== defaultCustomEditor.id)
......
......@@ -41,7 +41,7 @@ export class FileEditorInput extends AbstractTextResourceEditorInput implements
private model: ITextFileEditorModel | undefined = undefined;
private cachedTextFileModelReference: IReference<ITextFileEditorModel> | undefined = undefined;
private modelListeners: DisposableStore = this._register(new DisposableStore());
private readonly modelListeners: DisposableStore = this._register(new DisposableStore());
constructor(
resource: URI,
......@@ -119,6 +119,37 @@ export class FileEditorInput extends AbstractTextResourceEditorInput implements
}));
}
getTypeId(): string {
return FILE_EDITOR_INPUT_ID;
}
getName(): string {
return this.decorateLabel(super.getName());
}
getTitle(verbosity: Verbosity): string {
return this.decorateLabel(super.getTitle(verbosity));
}
private decorateLabel(label: string): string {
const orphaned = this.model?.hasState(TextFileEditorModelState.ORPHAN);
const readonly = this.isReadonly();
if (orphaned && readonly) {
return localize('orphanedReadonlyFile', "{0} (deleted, read-only)", label);
}
if (orphaned) {
return localize('orphanedFile', "{0} (deleted)", label);
}
if (readonly) {
return localize('readonlyFile', "{0} (read-only)", label);
}
return label;
}
getEncoding(): string | undefined {
if (this.model) {
return this.model.getEncoding();
......@@ -169,37 +200,6 @@ export class FileEditorInput extends AbstractTextResourceEditorInput implements
this.forceOpenAs = ForceOpenAs.Binary;
}
getTypeId(): string {
return FILE_EDITOR_INPUT_ID;
}
getName(): string {
return this.decorateLabel(super.getName());
}
getTitle(verbosity: Verbosity): string {
return this.decorateLabel(super.getTitle(verbosity));
}
private decorateLabel(label: string): string {
const orphaned = this.model?.hasState(TextFileEditorModelState.ORPHAN);
const readonly = this.isReadonly();
if (orphaned && readonly) {
return localize('orphanedReadonlyFile', "{0} (deleted, read-only)", label);
}
if (orphaned) {
return localize('orphanedFile', "{0} (deleted)", label);
}
if (readonly) {
return localize('readonlyFile', "{0} (read-only)", label);
}
return label;
}
isDirty(): boolean {
return !!(this.model?.isDirty());
}
......
......@@ -39,9 +39,9 @@ export class LogViewerInput extends ResourceEditorInput {
@IFilesConfigurationService filesConfigurationService: IFilesConfigurationService
) {
super(
URI.from({ scheme: LOG_SCHEME, path: outputChannelDescriptor.id }),
basename(outputChannelDescriptor.file.path),
dirname(outputChannelDescriptor.file.path),
URI.from({ scheme: LOG_SCHEME, path: outputChannelDescriptor.id }),
undefined,
textModelResolverService,
textFileService,
......
......@@ -157,7 +157,7 @@ export class OutputViewPane extends ViewPane {
}
private createInput(channel: IOutputChannel): ResourceEditorInput {
return this.instantiationService.createInstance(ResourceEditorInput, nls.localize('output model title', "{0} - Output", channel.label), nls.localize('channel', "Output channel for '{0}'", channel.label), channel.uri, undefined);
return this.instantiationService.createInstance(ResourceEditorInput, channel.uri, nls.localize('output model title', "{0} - Output", channel.label), nls.localize('channel', "Output channel for '{0}'", channel.label), undefined);
}
}
......
......@@ -58,9 +58,9 @@ export class PerfviewInput extends ResourceEditorInput {
@IFilesConfigurationService filesConfigurationService: IFilesConfigurationService
) {
super(
PerfviewInput.Uri,
localize('name', "Startup Performance"),
undefined,
PerfviewInput.Uri,
undefined,
textModelResolverService,
textFileService,
......
......@@ -3,6 +3,7 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { Registry } from 'vs/platform/registry/common/platform';
import { Emitter, Event } from 'vs/base/common/event';
import * as network from 'vs/base/common/network';
import { basename } from 'vs/base/common/path';
......@@ -18,9 +19,8 @@ import { IFileDialogService } from 'vs/platform/dialogs/common/dialogs';
import { IInstantiationService, ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
import { IStorageService, StorageScope } from 'vs/platform/storage/common/storage';
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
import { EditorInput, GroupIdentifier, IEditorInput, IMoveResult, IRevertOptions, ISaveOptions } from 'vs/workbench/common/editor';
import { EditorInput, GroupIdentifier, IEditorInput, IMoveResult, IRevertOptions, ISaveOptions, IEditorInputFactoryRegistry, Extensions as EditorInputExtensions } from 'vs/workbench/common/editor';
import { Memento } from 'vs/workbench/common/memento';
import { FileEditorInput } from 'vs/workbench/contrib/files/common/editors/fileEditorInput';
import { SearchEditorFindMatchClass, SearchEditorScheme } from 'vs/workbench/contrib/searchEditor/browser/constants';
import { SearchEditorModel } from 'vs/workbench/contrib/searchEditor/browser/searchEditorModel';
import { defaultSearchConfig, extractSearchQueryFromModel, parseSavedSearchEditor, serializeSearchConfiguration } from 'vs/workbench/contrib/searchEditor/browser/searchEditorSerialization';
......@@ -70,6 +70,8 @@ export class SearchEditorInput extends EditorInput {
this._onDidChangeLabel.fire();
}
private readonly fileEditorInputFactory = Registry.as<IEditorInputFactoryRegistry>(EditorInputExtensions.EditorInputFactories).getFileEditorInputFactory();
get resource() {
return this.backingUri || this.modelUri;
}
......@@ -235,7 +237,7 @@ export class SearchEditorInput extends EditorInput {
if (other instanceof SearchEditorInput) {
return !!(other.modelUri.fragment && other.modelUri.fragment === this.modelUri.fragment);
} else if (other instanceof FileEditorInput) {
} else if (this.fileEditorInputFactory.isFileEditorInput(other)) {
return other.resource?.toString() === this.backingUri?.toString();
}
return false;
......
......@@ -887,7 +887,7 @@ export class EditorService extends Disposable implements EditorServiceImpl {
}
// Resource
return this.instantiationService.createInstance(ResourceEditorInput, resourceEditorInput.label, resourceEditorInput.description, canonicalResource, resourceEditorInput.mode);
return this.instantiationService.createInstance(ResourceEditorInput, canonicalResource, resourceEditorInput.label, resourceEditorInput.description, resourceEditorInput.mode);
}, cachedInput => {
// Untitled
......
......@@ -403,7 +403,7 @@ suite('EditorService', () => {
const ed = instantiationService.createInstance(MyEditor, 'my.editor');
const inp = instantiationService.createInstance(ResourceEditorInput, 'name', 'description', URI.parse('my://resource-delegate'), undefined);
const inp = instantiationService.createInstance(ResourceEditorInput, URI.parse('my://resource-delegate'), 'name', 'description', undefined);
const delegate = instantiationService.createInstance(DelegatingEditorService, async (delegate, group, input) => {
assert.strictEqual(input, inp);
......
......@@ -45,7 +45,7 @@ export class DefaultPreferencesEditorInput extends ResourceEditorInput {
@ILabelService labelService: ILabelService,
@IFilesConfigurationService filesConfigurationService: IFilesConfigurationService
) {
super(nls.localize('settingsEditorName', "Default Settings"), '', defaultSettingsResource, undefined, textModelResolverService, textFileService, editorService, editorGroupService, fileService, labelService, filesConfigurationService);
super(defaultSettingsResource, nls.localize('settingsEditorName', "Default Settings"), '', undefined, textModelResolverService, textFileService, editorService, editorGroupService, fileService, labelService, filesConfigurationService);
}
getTypeId(): string {
......
......@@ -52,7 +52,7 @@ suite('Workbench - TextModelResolverService', () => {
});
let resource = URI.from({ scheme: 'test', authority: null!, path: 'thePath' });
let input: ResourceEditorInput = instantiationService.createInstance(ResourceEditorInput, 'The Name', 'The Description', resource, undefined);
let input: ResourceEditorInput = instantiationService.createInstance(ResourceEditorInput, resource, 'The Name', 'The Description', undefined);
const model = await input.resolve();
assert.ok(model);
......
......@@ -13,7 +13,6 @@ import { IEditorService } from 'vs/workbench/services/editor/common/editorServic
import { IEditorGroupsService } from 'vs/workbench/services/editor/common/editorGroupsService';
import { IFileService } from 'vs/platform/files/common/files';
import { IFilesConfigurationService } from 'vs/workbench/services/filesConfiguration/common/filesConfigurationService';
import { basenameOrAuthority } from 'vs/base/common/resources';
/**
* An editor input to be used for untitled text buffers.
......@@ -52,10 +51,6 @@ export class UntitledTextEditorInput extends AbstractTextResourceEditorInput imp
return UntitledTextEditorInput.ID;
}
get ariaLabel(): string {
return basenameOrAuthority(this.resource);
}
getName(): string {
return this.model.name;
}
......
......@@ -159,10 +159,10 @@ suite('Workbench base editor', () => {
let inst = workbenchInstantiationService();
const editor = EditorRegistry.getEditor(inst.createInstance(MyResourceEditorInput, 'fake', '', URI.file('/fake'), undefined))!.instantiate(inst);
const editor = EditorRegistry.getEditor(inst.createInstance(MyResourceEditorInput, URI.file('/fake'), 'fake', '', undefined))!.instantiate(inst);
assert.strictEqual(editor.getId(), 'myEditor');
const otherEditor = EditorRegistry.getEditor(inst.createInstance(ResourceEditorInput, 'fake', '', URI.file('/fake'), undefined))!.instantiate(inst);
const otherEditor = EditorRegistry.getEditor(inst.createInstance(ResourceEditorInput, URI.file('/fake'), 'fake', '', undefined))!.instantiate(inst);
assert.strictEqual(otherEditor.getId(), 'workbench.editors.textResourceEditor');
disposable.dispose();
......@@ -171,7 +171,7 @@ suite('Workbench base editor', () => {
test('Editor Lookup favors specific class over superclass (match on super class)', function () {
let inst = workbenchInstantiationService();
const editor = EditorRegistry.getEditor(inst.createInstance(MyResourceEditorInput, 'fake', '', URI.file('/fake'), undefined))!.instantiate(inst);
const editor = EditorRegistry.getEditor(inst.createInstance(MyResourceEditorInput, URI.file('/fake'), 'fake', '', undefined))!.instantiate(inst);
assert.strictEqual('workbench.editors.textResourceEditor', editor.getId());
});
......
......@@ -35,8 +35,8 @@ suite('Workbench editor model', () => {
}
});
let input = instantiationService.createInstance(ResourceEditorInput, 'name', 'description', URI.from({ scheme: 'test', authority: null!, path: 'thePath' }), undefined);
let otherInput = instantiationService.createInstance(ResourceEditorInput, 'name2', 'description', URI.from({ scheme: 'test', authority: null!, path: 'thePath' }), undefined);
let input = instantiationService.createInstance(ResourceEditorInput, URI.from({ scheme: 'test', authority: null!, path: 'thePath' }), 'name', 'description', undefined);
let otherInput = instantiationService.createInstance(ResourceEditorInput, URI.from({ scheme: 'test', authority: null!, path: 'thePath' }), 'name2', 'description', undefined);
let diffInput = new DiffEditorInput('name', 'description', input, otherInput);
let model = await diffInput.resolve() as TextDiffEditorModel;
......
......@@ -26,7 +26,7 @@ suite('Resource text editors', () => {
const resource = URI.from({ scheme: 'inmemory', authority: null!, path: 'thePath' });
accessor.modelService.createModel('function test() {}', accessor.modeService.create('text'), resource);
const input: ResourceEditorInput = instantiationService.createInstance(ResourceEditorInput, 'The Name', 'The Description', resource, undefined);
const input: ResourceEditorInput = instantiationService.createInstance(ResourceEditorInput, resource, 'The Name', 'The Description', undefined);
const model = await input.resolve();
......@@ -42,7 +42,7 @@ suite('Resource text editors', () => {
const resource = URI.from({ scheme: 'inmemory', authority: null!, path: 'thePath' });
accessor.modelService.createModel('function test() {}', accessor.modeService.create('text'), resource);
const input: ResourceEditorInput = instantiationService.createInstance(ResourceEditorInput, 'The Name', 'The Description', resource, 'resource-input-test');
const input: ResourceEditorInput = instantiationService.createInstance(ResourceEditorInput, resource, 'The Name', 'The Description', 'resource-input-test');
const model = await input.resolve();
assert.ok(model);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册