diff --git a/src/vs/workbench/common/editor/resourceEditorInput.ts b/src/vs/workbench/common/editor/resourceEditorInput.ts index df60cae876eeec779c9a8be04441f40b401769d8..6ed97ae5dbd55ac28a4c0c1fa285d9e80dfc0c78 100644 --- a/src/vs/workbench/common/editor/resourceEditorInput.ts +++ b/src/vs/workbench/common/editor/resourceEditorInput.ts @@ -28,9 +28,9 @@ export class ResourceEditorInput extends AbstractTextResourceEditorInput impleme private modelReference: Promise> | 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, diff --git a/src/vs/workbench/contrib/customEditor/browser/customEditors.ts b/src/vs/workbench/contrib/customEditor/browser/customEditors.ts index 31cbccf8047f14de211b8c9664faf77f36d21027..bc56f8621376421e343e64a9359d0678f69ad7f4 100644 --- a/src/vs/workbench/contrib/customEditor/browser/customEditors.ts +++ b/src/vs/workbench/contrib/customEditor/browser/customEditors.ts @@ -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(); onDidChangeViewTypes: Event = this._onDidChangeViewTypes.event; + private readonly _fileEditorInputFactory = Registry.as(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(); 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(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) diff --git a/src/vs/workbench/contrib/files/common/editors/fileEditorInput.ts b/src/vs/workbench/contrib/files/common/editors/fileEditorInput.ts index d06919c88804ae53f28dabf6cefe752d4f7e3deb..7fdf2900791e73e69775fb87bd6cc39b41dc0e05 100644 --- a/src/vs/workbench/contrib/files/common/editors/fileEditorInput.ts +++ b/src/vs/workbench/contrib/files/common/editors/fileEditorInput.ts @@ -41,7 +41,7 @@ export class FileEditorInput extends AbstractTextResourceEditorInput implements private model: ITextFileEditorModel | undefined = undefined; private cachedTextFileModelReference: IReference | 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()); } diff --git a/src/vs/workbench/contrib/output/browser/logViewer.ts b/src/vs/workbench/contrib/output/browser/logViewer.ts index 560b003c2d2b875502f3582146cdef49f96661ab..a8fb736ea74f3ff692017f3ea3c15a66ecf9fd6f 100644 --- a/src/vs/workbench/contrib/output/browser/logViewer.ts +++ b/src/vs/workbench/contrib/output/browser/logViewer.ts @@ -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, diff --git a/src/vs/workbench/contrib/output/browser/outputView.ts b/src/vs/workbench/contrib/output/browser/outputView.ts index a3ba66658089264ec5d971e7e408e23149ba97cc..7eabcf2130ad288a1f7408a1024602aa3e2bb37e 100644 --- a/src/vs/workbench/contrib/output/browser/outputView.ts +++ b/src/vs/workbench/contrib/output/browser/outputView.ts @@ -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); } } diff --git a/src/vs/workbench/contrib/performance/electron-browser/perfviewEditor.ts b/src/vs/workbench/contrib/performance/electron-browser/perfviewEditor.ts index 7ba2316467205a01b16a0582152eb349fe92c4fb..27c66862d156825a029247c2b793eb5d509563ac 100644 --- a/src/vs/workbench/contrib/performance/electron-browser/perfviewEditor.ts +++ b/src/vs/workbench/contrib/performance/electron-browser/perfviewEditor.ts @@ -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, diff --git a/src/vs/workbench/contrib/searchEditor/browser/searchEditorInput.ts b/src/vs/workbench/contrib/searchEditor/browser/searchEditorInput.ts index 9a49d08059724912933f913c4bc2f51b34358f58..5178fcbba70999dcc0a53eb0415a0f6f02f30123 100644 --- a/src/vs/workbench/contrib/searchEditor/browser/searchEditorInput.ts +++ b/src/vs/workbench/contrib/searchEditor/browser/searchEditorInput.ts @@ -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(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; diff --git a/src/vs/workbench/services/editor/browser/editorService.ts b/src/vs/workbench/services/editor/browser/editorService.ts index a68c65756b89cef152870e0096b39c8c1acefb5e..b67f8de154f71d236d928982fc38a523327aaf42 100644 --- a/src/vs/workbench/services/editor/browser/editorService.ts +++ b/src/vs/workbench/services/editor/browser/editorService.ts @@ -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 diff --git a/src/vs/workbench/services/editor/test/browser/editorService.test.ts b/src/vs/workbench/services/editor/test/browser/editorService.test.ts index 31bbd1ebcc434aad399b64a8b7db700af26fc099..009cab9fd5ad7c3643f3eb95280d1ec5f7118ff1 100644 --- a/src/vs/workbench/services/editor/test/browser/editorService.test.ts +++ b/src/vs/workbench/services/editor/test/browser/editorService.test.ts @@ -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); diff --git a/src/vs/workbench/services/preferences/common/preferencesEditorInput.ts b/src/vs/workbench/services/preferences/common/preferencesEditorInput.ts index 6432e6993f57471a383cc202e5ffe89d23623ff5..b15108b73857a3b8926f2992271e0b9336144ff1 100644 --- a/src/vs/workbench/services/preferences/common/preferencesEditorInput.ts +++ b/src/vs/workbench/services/preferences/common/preferencesEditorInput.ts @@ -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 { diff --git a/src/vs/workbench/services/textmodelResolver/test/browser/textModelResolverService.test.ts b/src/vs/workbench/services/textmodelResolver/test/browser/textModelResolverService.test.ts index ed6e8dbf4f11bfac4ebd5b015d51ae3eb98bda2c..f8b2464c808b8b342e8493278fdc177c9b9580c7 100644 --- a/src/vs/workbench/services/textmodelResolver/test/browser/textModelResolverService.test.ts +++ b/src/vs/workbench/services/textmodelResolver/test/browser/textModelResolverService.test.ts @@ -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); diff --git a/src/vs/workbench/services/untitled/common/untitledTextEditorInput.ts b/src/vs/workbench/services/untitled/common/untitledTextEditorInput.ts index cfa7db772d20323d1ed095f6f82a34707dbf711d..c18ac77f5ed8831da138500d8f94d4aad27a66a9 100644 --- a/src/vs/workbench/services/untitled/common/untitledTextEditorInput.ts +++ b/src/vs/workbench/services/untitled/common/untitledTextEditorInput.ts @@ -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; } diff --git a/src/vs/workbench/test/browser/parts/editor/baseEditor.test.ts b/src/vs/workbench/test/browser/parts/editor/baseEditor.test.ts index b8a62fd8127eaacb74735d871fc5a3b6bd83c324..500950bf706143993010dc6ceed8935a2fbb5ba4 100644 --- a/src/vs/workbench/test/browser/parts/editor/baseEditor.test.ts +++ b/src/vs/workbench/test/browser/parts/editor/baseEditor.test.ts @@ -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()); }); diff --git a/src/vs/workbench/test/browser/parts/editor/editorDiffModel.test.ts b/src/vs/workbench/test/browser/parts/editor/editorDiffModel.test.ts index 37bfc6dc478e36be3742d303c330c5ad600121e7..6333219069c2b2806e2a988ff47add1d5768068b 100644 --- a/src/vs/workbench/test/browser/parts/editor/editorDiffModel.test.ts +++ b/src/vs/workbench/test/browser/parts/editor/editorDiffModel.test.ts @@ -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; diff --git a/src/vs/workbench/test/browser/parts/editor/resourceEditorInput.test.ts b/src/vs/workbench/test/browser/parts/editor/resourceEditorInput.test.ts index 7634e777a079c3c2ee3b539785925b14d6bc2476..a0fa7d56f5d6984d53404f26d4b64d723c915d0a 100644 --- a/src/vs/workbench/test/browser/parts/editor/resourceEditorInput.test.ts +++ b/src/vs/workbench/test/browser/parts/editor/resourceEditorInput.test.ts @@ -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);