提交 4fe451d7 编写于 作者: J Johannes Rieken

move DataUri so that getIconClasses can be moved, #44860

上级 ade60477
......@@ -185,3 +185,38 @@ export function isMalformedFileUri(candidate: URI): URI | undefined {
}
return void 0;
}
/**
* Data URI related helpers.
*/
export namespace DataUri {
export const META_DATA_LABEL = 'label';
export const META_DATA_DESCRIPTION = 'description';
export const META_DATA_SIZE = 'size';
export const META_DATA_MIME = 'mime';
export function parseMetaData(dataUri: URI): Map<string, string> {
const metadata = new Map<string, string>();
// Given a URI of: data:image/png;size:2313;label:SomeLabel;description:SomeDescription;base64,77+9UE5...
// the metadata is: size:2313;label:SomeLabel;description:SomeDescription
const meta = dataUri.path.substring(dataUri.path.indexOf(';') + 1, dataUri.path.lastIndexOf(';'));
meta.split(';').forEach(property => {
const [key, value] = property.split(':');
if (key && value) {
metadata.set(key, value);
}
});
// Given a URI of: data:image/png;size:2313;label:SomeLabel;description:SomeDescription;base64,77+9UE5...
// the mime is: image/png
const mime = dataUri.path.substring(0, dataUri.path.indexOf(';'));
if (mime) {
metadata.set(META_DATA_MIME, mime);
}
return metadata;
}
}
......@@ -20,7 +20,6 @@ import { FileKind, FILES_ASSOCIATIONS_CONFIG } from 'vs/platform/files/common/fi
import { ITextModel } from 'vs/editor/common/model';
import { IThemeService } from 'vs/platform/theme/common/themeService';
import { Event, Emitter } from 'vs/base/common/event';
import { DataUri } from 'vs/workbench/common/resources';
import { ILabelService } from 'vs/platform/label/common/label';
export interface IResourceLabel {
......@@ -318,8 +317,8 @@ export function getIconClasses(modelService: IModelService, modeService: IModeSe
let name: string;
let path: string;
if (resource.scheme === Schemas.data) {
const metadata = DataUri.parseMetaData(resource);
name = metadata.get(DataUri.META_DATA_LABEL);
const metadata = resources.DataUri.parseMetaData(resource);
name = metadata.get(resources.DataUri.META_DATA_LABEL);
path = name;
} else {
name = cssEscape(resources.basenameOrAuthority(resource).toLowerCase());
......
......@@ -8,7 +8,7 @@ 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/workbench/common/resources';
import { DataUri } from 'vs/base/common/resources';
/**
* An editor model that just represents a resource that can be loaded.
......@@ -89,4 +89,4 @@ export class BinaryEditorModel extends EditorModel {
return TPromise.wrap(this);
}
}
\ No newline at end of file
}
......@@ -8,7 +8,7 @@ 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 } from 'vs/workbench/common/resources';
import { DataUri } from 'vs/base/common/resources';
/**
* An editor input to present data URIs in a binary editor. Data URIs have the form of:
......
......@@ -78,37 +78,3 @@ export class ResourceContextKey extends Disposable implements IContextKey<URI> {
return this._resourceKey.get();
}
}
/**
* Data URI related helpers.
*/
export namespace DataUri {
export const META_DATA_LABEL = 'label';
export const META_DATA_DESCRIPTION = 'description';
export const META_DATA_SIZE = 'size';
export const META_DATA_MIME = 'mime';
export function parseMetaData(dataUri: URI): Map<string, string> {
const metadata = new Map<string, string>();
// Given a URI of: data:image/png;size:2313;label:SomeLabel;description:SomeDescription;base64,77+9UE5...
// the metadata is: size:2313;label:SomeLabel;description:SomeDescription
const meta = dataUri.path.substring(dataUri.path.indexOf(';') + 1, dataUri.path.lastIndexOf(';'));
meta.split(';').forEach(property => {
const [key, value] = property.split(':');
if (key && value) {
metadata.set(key, value);
}
});
// Given a URI of: data:image/png;size:2313;label:SomeLabel;description:SomeDescription;base64,77+9UE5...
// the mime is: image/png
const mime = dataUri.path.substring(0, dataUri.path.indexOf(';'));
if (mime) {
metadata.set(META_DATA_MIME, mime);
}
return metadata;
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册