未验证 提交 2340d870 编写于 作者: B Benjamin Pasero 提交者: GitHub

debt - remove data uri inputs (#85203)

上级 a825aaaa
......@@ -6,7 +6,6 @@
import * as DOM from 'vs/base/browser/dom';
import { DomScrollableElement } from 'vs/base/browser/ui/scrollbar/scrollableElement';
import { Disposable, DisposableStore, IDisposable } from 'vs/base/common/lifecycle';
import { Schemas } from 'vs/base/common/network';
import { URI } from 'vs/base/common/uri';
import 'vs/css!./media/resourceviewer';
import * as nls from 'vs/nls';
......@@ -132,13 +131,11 @@ class FileSeemsBinaryFileView {
label.textContent = nls.localize('nativeBinaryError', "The file is not displayed in the editor because it is either binary or uses an unsupported text encoding.");
container.appendChild(label);
if (descriptor.resource.scheme !== Schemas.data) {
const link = DOM.append(label, DOM.$('a.embedded-link'));
link.setAttribute('role', 'button');
link.textContent = nls.localize('openAsText', "Do you want to open it anyway?");
const link = DOM.append(label, DOM.$('a.embedded-link'));
link.setAttribute('role', 'button');
link.textContent = nls.localize('openAsText', "Do you want to open it anyway?");
disposables.add(DOM.addDisposableListener(link, DOM.EventType.CLICK, () => delegate.openInternalClb(descriptor.resource)));
}
disposables.add(DOM.addDisposableListener(link, DOM.EventType.CLICK, () => delegate.openInternalClb(descriptor.resource)));
scrollbar.scanDomNode();
......
......@@ -6,8 +6,6 @@
import { EditorModel } from 'vs/workbench/common/editor';
import { URI } from 'vs/base/common/uri';
import { IFileService } from 'vs/platform/files/common/files';
import { Schemas } from 'vs/base/common/network';
import { DataUri } from 'vs/base/common/resources';
import { MIME_BINARY } from 'vs/base/common/mime';
/**
......@@ -28,18 +26,6 @@ export class BinaryEditorModel extends EditorModel {
this.resource = resource;
this.name = name;
this.mime = MIME_BINARY;
if (resource.scheme === Schemas.data) {
const metadata = DataUri.parseMetaData(resource);
if (metadata.has(DataUri.META_DATA_SIZE)) {
this.size = Number(metadata.get(DataUri.META_DATA_SIZE));
}
const metadataMime = metadata.get(DataUri.META_DATA_MIME);
if (metadataMime) {
this.mime = metadataMime;
}
}
}
/**
......
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { EditorInput } from 'vs/workbench/common/editor';
import { URI } from 'vs/base/common/uri';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { BinaryEditorModel } from 'vs/workbench/common/editor/binaryEditorModel';
import { DataUri, basename } from 'vs/base/common/resources';
/**
* An editor input to present data URIs in a binary editor. Data URIs have the form of:
* data:[mime type];[meta data <key=value>;...];base64,[base64 encoded value]
*/
export class DataUriEditorInput extends EditorInput {
static readonly ID: string = 'workbench.editors.dataUriEditorInput';
private readonly name: string;
private readonly description: string | undefined;
constructor(
name: string | undefined,
description: string | undefined,
private readonly resource: URI,
@IInstantiationService private readonly instantiationService: IInstantiationService
) {
super();
if (!name || !description) {
const metadata = DataUri.parseMetaData(this.resource);
if (!name) {
name = metadata.get(DataUri.META_DATA_LABEL) || basename(resource);
}
if (!description) {
description = metadata.get(DataUri.META_DATA_DESCRIPTION);
}
}
this.name = name;
this.description = description;
}
getResource(): URI {
return this.resource;
}
getTypeId(): string {
return DataUriEditorInput.ID;
}
getName(): string {
return this.name;
}
getDescription(): string | undefined {
return this.description;
}
resolve(): Promise<BinaryEditorModel> {
return this.instantiationService.createInstance(BinaryEditorModel, this.resource, this.getName()).load();
}
matches(otherInput: unknown): boolean {
if (super.matches(otherInput) === true) {
return true;
}
// Compare by resource
if (otherInput instanceof DataUriEditorInput) {
return otherInput.resource.toString() === this.resource.toString();
}
return false;
}
}
......@@ -27,7 +27,6 @@ import { KeyMod, KeyCode } from 'vs/base/common/keyCodes';
import * as platform from 'vs/base/common/platform';
import { ExplorerViewlet, ExplorerViewletViewsContribution } from 'vs/workbench/contrib/files/browser/explorerViewlet';
import { IEditorRegistry, EditorDescriptor, Extensions as EditorExtensions } from 'vs/workbench/browser/editor';
import { DataUriEditorInput } from 'vs/workbench/common/editor/dataUriEditorInput';
import { LifecyclePhase } from 'vs/platform/lifecycle/common/lifecycle';
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
import { IEditorGroupsService } from 'vs/workbench/services/editor/common/editorGroupsService';
......@@ -107,8 +106,7 @@ Registry.as<IEditorRegistry>(EditorExtensions.Editors).registerEditor(
nls.localize('binaryFileEditor', "Binary File Editor")
),
[
new SyncDescriptor<EditorInput>(FileEditorInput),
new SyncDescriptor<EditorInput>(DataUriEditorInput)
new SyncDescriptor<EditorInput>(FileEditorInput)
]
);
......
......@@ -7,7 +7,6 @@ import { IInstantiationService, ServicesAccessor } from 'vs/platform/instantiati
import { IResourceInput, ITextEditorOptions, IEditorOptions, EditorActivation } from 'vs/platform/editor/common/editor';
import { IEditorInput, IEditor, GroupIdentifier, IFileEditorInput, IUntitledTextResourceInput, IResourceDiffInput, IResourceSideBySideInput, IEditorInputFactoryRegistry, Extensions as EditorExtensions, IFileInputFactory, EditorInput, SideBySideEditorInput, IEditorInputWithOptions, isEditorInputWithOptions, EditorOptions, TextEditorOptions, IEditorIdentifier, IEditorCloseEvent, ITextEditor, ITextDiffEditor, ITextSideBySideEditor, toResource, SideBySideEditor, IRevertOptions } from 'vs/workbench/common/editor';
import { ResourceEditorInput } from 'vs/workbench/common/editor/resourceEditorInput';
import { DataUriEditorInput } from 'vs/workbench/common/editor/dataUriEditorInput';
import { Registry } from 'vs/platform/registry/common/platform';
import { ResourceMap } from 'vs/base/common/map';
import { IUntitledTextEditorService } from 'vs/workbench/services/untitled/common/untitledTextEditorService';
......@@ -29,7 +28,7 @@ import { ILabelService } from 'vs/platform/label/common/label';
import { registerSingleton } from 'vs/platform/instantiation/common/extensions';
import { withNullAsUndefined } from 'vs/base/common/types';
type CachedEditorInput = ResourceEditorInput | IFileEditorInput | DataUriEditorInput;
type CachedEditorInput = ResourceEditorInput | IFileEditorInput;
type OpenInEditorGroup = IEditorGroup | GroupIdentifier | SIDE_GROUP_TYPE | ACTIVE_GROUP_TYPE;
export class EditorService extends Disposable implements EditorServiceImpl {
......@@ -584,8 +583,8 @@ export class EditorService extends Disposable implements EditorServiceImpl {
const resourceInput = input as IResourceInput;
if (resourceInput.resource instanceof URI) {
let label = resourceInput.label;
if (!label && resourceInput.resource.scheme !== Schemas.data) {
label = basename(resourceInput.resource); // derive the label from the path (but not for data URIs)
if (!label) {
label = basename(resourceInput.resource); // derive the label from the path
}
return this.createOrGet(resourceInput.resource, this.instantiationService, label, resourceInput.description, resourceInput.encoding, resourceInput.mode, resourceInput.forceFile) as EditorInput;
......@@ -609,7 +608,7 @@ export class EditorService extends Disposable implements EditorServiceImpl {
if (mode) {
input.setPreferredMode(mode);
}
} else if (!(input instanceof DataUriEditorInput)) {
} else {
if (encoding) {
input.setPreferredEncoding(encoding);
}
......@@ -628,11 +627,6 @@ export class EditorService extends Disposable implements EditorServiceImpl {
input = this.fileInputFactory.createFileInput(resource, encoding, mode, instantiationService);
}
// Data URI
else if (resource.scheme === Schemas.data) {
input = instantiationService.createInstance(DataUriEditorInput, label || basename(resource), description, resource);
}
// Resource
else {
input = instantiationService.createInstance(ResourceEditorInput, label, description, resource, mode);
......
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as assert from 'assert';
import { URI } from 'vs/base/common/uri';
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
import { workbenchInstantiationService } from 'vs/workbench/test/workbenchTestServices';
import { DataUriEditorInput } from 'vs/workbench/common/editor/dataUriEditorInput';
import { BinaryEditorModel } from 'vs/workbench/common/editor/binaryEditorModel';
suite('DataUriEditorInput', () => {
let instantiationService: IInstantiationService;
setup(() => {
instantiationService = workbenchInstantiationService();
});
test('simple', () => {
const resource = URI.parse('data:image/png;label:SomeLabel;description:SomeDescription;size:1024;base64,77+9UE5');
const input: DataUriEditorInput = instantiationService.createInstance(DataUriEditorInput, undefined, undefined, resource);
assert.equal(input.getName(), 'SomeLabel');
assert.equal(input.getDescription(), 'SomeDescription');
return input.resolve().then((model: BinaryEditorModel) => {
assert.ok(model);
assert.equal(model.getSize(), 1024);
assert.equal(model.getMime(), 'image/png');
});
});
});
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册