Skip to content

Commit 4fe451d

Browse files
committed
move DataUri so that getIconClasses can be moved, microsoft#44860
1 parent ade6047 commit 4fe451d

5 files changed

Lines changed: 40 additions & 40 deletions

File tree

src/vs/base/common/resources.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,3 +185,38 @@ export function isMalformedFileUri(candidate: URI): URI | undefined {
185185
}
186186
return void 0;
187187
}
188+
189+
190+
/**
191+
* Data URI related helpers.
192+
*/
193+
export namespace DataUri {
194+
195+
export const META_DATA_LABEL = 'label';
196+
export const META_DATA_DESCRIPTION = 'description';
197+
export const META_DATA_SIZE = 'size';
198+
export const META_DATA_MIME = 'mime';
199+
200+
export function parseMetaData(dataUri: URI): Map<string, string> {
201+
const metadata = new Map<string, string>();
202+
203+
// Given a URI of: data:image/png;size:2313;label:SomeLabel;description:SomeDescription;base64,77+9UE5...
204+
// the metadata is: size:2313;label:SomeLabel;description:SomeDescription
205+
const meta = dataUri.path.substring(dataUri.path.indexOf(';') + 1, dataUri.path.lastIndexOf(';'));
206+
meta.split(';').forEach(property => {
207+
const [key, value] = property.split(':');
208+
if (key && value) {
209+
metadata.set(key, value);
210+
}
211+
});
212+
213+
// Given a URI of: data:image/png;size:2313;label:SomeLabel;description:SomeDescription;base64,77+9UE5...
214+
// the mime is: image/png
215+
const mime = dataUri.path.substring(0, dataUri.path.indexOf(';'));
216+
if (mime) {
217+
metadata.set(META_DATA_MIME, mime);
218+
}
219+
220+
return metadata;
221+
}
222+
}

src/vs/workbench/browser/labels.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import { FileKind, FILES_ASSOCIATIONS_CONFIG } from 'vs/platform/files/common/fi
2020
import { ITextModel } from 'vs/editor/common/model';
2121
import { IThemeService } from 'vs/platform/theme/common/themeService';
2222
import { Event, Emitter } from 'vs/base/common/event';
23-
import { DataUri } from 'vs/workbench/common/resources';
2423
import { ILabelService } from 'vs/platform/label/common/label';
2524

2625
export interface IResourceLabel {
@@ -318,8 +317,8 @@ export function getIconClasses(modelService: IModelService, modeService: IModeSe
318317
let name: string;
319318
let path: string;
320319
if (resource.scheme === Schemas.data) {
321-
const metadata = DataUri.parseMetaData(resource);
322-
name = metadata.get(DataUri.META_DATA_LABEL);
320+
const metadata = resources.DataUri.parseMetaData(resource);
321+
name = metadata.get(resources.DataUri.META_DATA_LABEL);
323322
path = name;
324323
} else {
325324
name = cssEscape(resources.basenameOrAuthority(resource).toLowerCase());

src/vs/workbench/common/editor/binaryEditorModel.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { EditorModel } from 'vs/workbench/common/editor';
88
import { URI } from 'vs/base/common/uri';
99
import { IFileService } from 'vs/platform/files/common/files';
1010
import { Schemas } from 'vs/base/common/network';
11-
import { DataUri } from 'vs/workbench/common/resources';
11+
import { DataUri } from 'vs/base/common/resources';
1212

1313
/**
1414
* An editor model that just represents a resource that can be loaded.
@@ -89,4 +89,4 @@ export class BinaryEditorModel extends EditorModel {
8989

9090
return TPromise.wrap(this);
9191
}
92-
}
92+
}

src/vs/workbench/common/editor/dataUriEditorInput.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { EditorInput } from 'vs/workbench/common/editor';
88
import { URI } from 'vs/base/common/uri';
99
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
1010
import { BinaryEditorModel } from 'vs/workbench/common/editor/binaryEditorModel';
11-
import { DataUri } from 'vs/workbench/common/resources';
11+
import { DataUri } from 'vs/base/common/resources';
1212

1313
/**
1414
* An editor input to present data URIs in a binary editor. Data URIs have the form of:

src/vs/workbench/common/resources.ts

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -78,37 +78,3 @@ export class ResourceContextKey extends Disposable implements IContextKey<URI> {
7878
return this._resourceKey.get();
7979
}
8080
}
81-
82-
/**
83-
* Data URI related helpers.
84-
*/
85-
export namespace DataUri {
86-
87-
export const META_DATA_LABEL = 'label';
88-
export const META_DATA_DESCRIPTION = 'description';
89-
export const META_DATA_SIZE = 'size';
90-
export const META_DATA_MIME = 'mime';
91-
92-
export function parseMetaData(dataUri: URI): Map<string, string> {
93-
const metadata = new Map<string, string>();
94-
95-
// Given a URI of: data:image/png;size:2313;label:SomeLabel;description:SomeDescription;base64,77+9UE5...
96-
// the metadata is: size:2313;label:SomeLabel;description:SomeDescription
97-
const meta = dataUri.path.substring(dataUri.path.indexOf(';') + 1, dataUri.path.lastIndexOf(';'));
98-
meta.split(';').forEach(property => {
99-
const [key, value] = property.split(':');
100-
if (key && value) {
101-
metadata.set(key, value);
102-
}
103-
});
104-
105-
// Given a URI of: data:image/png;size:2313;label:SomeLabel;description:SomeDescription;base64,77+9UE5...
106-
// the mime is: image/png
107-
const mime = dataUri.path.substring(0, dataUri.path.indexOf(';'));
108-
if (mime) {
109-
metadata.set(META_DATA_MIME, mime);
110-
}
111-
112-
return metadata;
113-
}
114-
}

0 commit comments

Comments
 (0)