提交 f221ef23 编写于 作者: M Martin Aeschlimann

[icons] rename contribution point to 'iconThemes'

上级 a7272cc1
...@@ -34,7 +34,7 @@ ...@@ -34,7 +34,7 @@
"path": "./themes/hc_black.json" "path": "./themes/hc_black.json"
} }
], ],
"fileIcons": [ "iconThemes": [
{ {
"id": "vs-standard", "id": "vs-standard",
"label": "Visual Studio File Icons", "label": "Visual Studio File Icons",
......
...@@ -29,7 +29,6 @@ import pfs = require('vs/base/node/pfs'); ...@@ -29,7 +29,6 @@ import pfs = require('vs/base/node/pfs');
// implementation // implementation
const DEFAULT_THEME_ID = 'vs-dark vscode-theme-defaults-themes-dark_plus-json'; const DEFAULT_THEME_ID = 'vs-dark vscode-theme-defaults-themes-dark_plus-json';
const DEFAULT_FILE_ICONS = 'vs-standard';
const COLOR_THEME_CHANNEL = 'vscode:changeColorTheme'; const COLOR_THEME_CHANNEL = 'vscode:changeColorTheme';
const ICON_THEME_CHANNEL = 'vscode:changeIconTheme'; const ICON_THEME_CHANNEL = 'vscode:changeIconTheme';
...@@ -77,23 +76,23 @@ let themesExtPoint = ExtensionsRegistry.registerExtensionPoint<IThemeExtensionPo ...@@ -77,23 +76,23 @@ let themesExtPoint = ExtensionsRegistry.registerExtensionPoint<IThemeExtensionPo
} }
}); });
let fileIconsExtPoint = ExtensionsRegistry.registerExtensionPoint<IThemeExtensionPoint[]>('fileIcons', { let iconThemeExtPoint = ExtensionsRegistry.registerExtensionPoint<IThemeExtensionPoint[]>('iconThemes', {
description: nls.localize('vscode.extension.contributes.fileIcons', 'Contributes icon themes.'), description: nls.localize('vscode.extension.contributes.iconThemes', 'Contributes file icon themes.'),
type: 'array', type: 'array',
items: { items: {
type: 'object', type: 'object',
defaultSnippets: [{ body: { id: '{{id}}', label: '{{label}}', path: './fileicons/{{id}}-icon-theme.json' } }], defaultSnippets: [{ body: { id: '{{id}}', label: '{{label}}', path: './fileicons/{{id}}-icon-theme.json' } }],
properties: { properties: {
id: { id: {
description: nls.localize('vscode.extension.contributes.fileIcons.id', 'Id of the icon theme as used in the user settings.'), description: nls.localize('vscode.extension.contributes.iconThemes.id', 'Id of the icon theme as used in the user settings.'),
type: 'string' type: 'string'
}, },
label: { label: {
description: nls.localize('vscode.extension.contributes.fileIcons.label', 'Label of the icon theme as shown in the UI.'), description: nls.localize('vscode.extension.contributes.iconThemes.label', 'Label of the icon theme as shown in the UI.'),
type: 'string' type: 'string'
}, },
path: { path: {
description: nls.localize('vscode.extension.contributes.fileIcons.path', 'Path of the icon theme definition file. The path is relative to the extension folder and is typically \'./icons/awesome-icon-theme.json\'.'), description: nls.localize('vscode.extension.contributes.iconThemes.path', 'Path of the icon theme definition file. The path is relative to the extension folder and is typically \'./icons/awesome-icon-theme.json\'.'),
type: 'string' type: 'string'
} }
}, },
...@@ -145,7 +144,7 @@ interface FontDefinition { ...@@ -145,7 +144,7 @@ interface FontDefinition {
src: { path:string; format:string; }[]; src: { path:string; format:string; }[];
} }
interface FileIconsAssociation { interface IconsAssociation {
folder?: string; folder?: string;
file?: string; file?: string;
folderExpanded?: string; folderExpanded?: string;
...@@ -155,22 +154,22 @@ interface FileIconsAssociation { ...@@ -155,22 +154,22 @@ interface FileIconsAssociation {
languageIds?: {[languageId:string]: string; }; languageIds?: {[languageId:string]: string; };
} }
interface FileIconsDocument extends FileIconsAssociation { interface IconThemeDocument extends IconsAssociation {
iconDefinitions: { [key:string]: IconDefinition }; iconDefinitions: { [key:string]: IconDefinition };
fonts: FontDefinition[]; fonts: FontDefinition[];
light?: FileIconsAssociation; light?: IconsAssociation;
highContrast?: FileIconsAssociation; highContrast?: IconsAssociation;
} }
export class ThemeService implements IThemeService { export class ThemeService implements IThemeService {
_serviceBrand: any; _serviceBrand: any;
private knownThemes: IInternalThemeData[]; private knownColorThemes: IInternalThemeData[];
private currentTheme: string; private currentColorTheme: string;
private container: HTMLElement; private container: HTMLElement;
private onColorThemeChange: Emitter<string>; private onColorThemeChange: Emitter<string>;
private knownFileIconContributions: IInternalThemeData[]; private knownIconThemes: IInternalThemeData[];
private currentIconTheme: string; private currentIconTheme: string;
constructor( constructor(
...@@ -179,9 +178,9 @@ export class ThemeService implements IThemeService { ...@@ -179,9 +178,9 @@ export class ThemeService implements IThemeService {
@IStorageService private storageService: IStorageService, @IStorageService private storageService: IStorageService,
@ITelemetryService private telemetryService: ITelemetryService) { @ITelemetryService private telemetryService: ITelemetryService) {
this.knownThemes = []; this.knownColorThemes = [];
this.onColorThemeChange = new Emitter<string>(); this.onColorThemeChange = new Emitter<string>();
this.knownFileIconContributions = []; this.knownIconThemes = [];
this.currentIconTheme = ''; this.currentIconTheme = '';
themesExtPoint.setHandler((extensions) => { themesExtPoint.setHandler((extensions) => {
...@@ -196,9 +195,9 @@ export class ThemeService implements IThemeService { ...@@ -196,9 +195,9 @@ export class ThemeService implements IThemeService {
} }
}); });
fileIconsExtPoint.setHandler((extensions) => { iconThemeExtPoint.setHandler((extensions) => {
for (let ext of extensions) { for (let ext of extensions) {
this.onFileIcons(ext.description.extensionFolderPath, ext.description.id, ext.value, ext.collector); this.onIconThemes(ext.description.extensionFolderPath, ext.description.id, ext.value, ext.collector);
} }
}); });
...@@ -233,7 +232,7 @@ export class ThemeService implements IThemeService { ...@@ -233,7 +232,7 @@ export class ThemeService implements IThemeService {
if (!themeId) { if (!themeId) {
return TPromise.as(false); return TPromise.as(false);
} }
if (themeId === this.currentTheme) { if (themeId === this.currentColorTheme) {
if (broadcastToAllWindows) { if (broadcastToAllWindows) {
this.windowService.broadcast({ channel: COLOR_THEME_CHANNEL, payload: themeId }); this.windowService.broadcast({ channel: COLOR_THEME_CHANNEL, payload: themeId });
} }
...@@ -245,10 +244,10 @@ export class ThemeService implements IThemeService { ...@@ -245,10 +244,10 @@ export class ThemeService implements IThemeService {
let onApply = (newTheme: IInternalThemeData) => { let onApply = (newTheme: IInternalThemeData) => {
let newThemeId = newTheme.id; let newThemeId = newTheme.id;
if (this.container) { if (this.container) {
if (this.currentTheme) { if (this.currentColorTheme) {
$(this.container).removeClass(this.currentTheme); $(this.container).removeClass(this.currentColorTheme);
} }
this.currentTheme = newThemeId; this.currentColorTheme = newThemeId;
$(this.container).addClass(newThemeId); $(this.container).addClass(newThemeId);
} }
...@@ -265,7 +264,7 @@ export class ThemeService implements IThemeService { ...@@ -265,7 +264,7 @@ export class ThemeService implements IThemeService {
} }
public getColorTheme() { public getColorTheme() {
return this.currentTheme || this.storageService.get(COLOR_THEME_PREF, StorageScope.GLOBAL, DEFAULT_THEME_ID); return this.currentColorTheme || this.storageService.get(COLOR_THEME_PREF, StorageScope.GLOBAL, DEFAULT_THEME_ID);
} }
private findThemeData(themeId: string, defaultId?: string): TPromise<IInternalThemeData> { private findThemeData(themeId: string, defaultId?: string): TPromise<IInternalThemeData> {
...@@ -295,7 +294,7 @@ export class ThemeService implements IThemeService { ...@@ -295,7 +294,7 @@ export class ThemeService implements IThemeService {
public getColorThemes(): TPromise<IThemeData[]> { public getColorThemes(): TPromise<IThemeData[]> {
return this.extensionService.onReady().then(isReady => { return this.extensionService.onReady().then(isReady => {
return this.knownThemes; return this.knownColorThemes;
}); });
} }
...@@ -325,7 +324,7 @@ export class ThemeService implements IThemeService { ...@@ -325,7 +324,7 @@ export class ThemeService implements IThemeService {
} }
let themeSelector = toCSSSelector(extensionId + '-' + Paths.normalize(theme.path)); let themeSelector = toCSSSelector(extensionId + '-' + Paths.normalize(theme.path));
this.knownThemes.push({ this.knownColorThemes.push({
id: `${theme.uiTheme || defaultBaseTheme} ${themeSelector}`, id: `${theme.uiTheme || defaultBaseTheme} ${themeSelector}`,
label: theme.label || Paths.basename(theme.path), label: theme.label || Paths.basename(theme.path),
description: theme.description, description: theme.description,
...@@ -335,8 +334,8 @@ export class ThemeService implements IThemeService { ...@@ -335,8 +334,8 @@ export class ThemeService implements IThemeService {
}); });
} }
private onFileIcons(extensionFolderPath: string, extensionId: string, fileIcons: IThemeExtensionPoint[], collector: IExtensionMessageCollector): void { private onIconThemes(extensionFolderPath: string, extensionId: string, iconThemes: IThemeExtensionPoint[], collector: IExtensionMessageCollector): void {
if (!Array.isArray(fileIcons)) { if (!Array.isArray(iconThemes)) {
collector.error(nls.localize( collector.error(nls.localize(
'reqarray', 'reqarray',
"Extension point `{0}` must be an array.", "Extension point `{0}` must be an array.",
...@@ -344,35 +343,35 @@ export class ThemeService implements IThemeService { ...@@ -344,35 +343,35 @@ export class ThemeService implements IThemeService {
)); ));
return; return;
} }
fileIcons.forEach(fileIconSet => { iconThemes.forEach(iconTheme => {
if (!fileIconSet.path || (typeof fileIconSet.path !== 'string')) { if (!iconTheme.path || (typeof iconTheme.path !== 'string')) {
collector.error(nls.localize( collector.error(nls.localize(
'reqpath', 'reqpath',
"Expected string in `contributes.{0}.path`. Provided value: {1}", "Expected string in `contributes.{0}.path`. Provided value: {1}",
themesExtPoint.name, themesExtPoint.name,
String(fileIconSet.path) String(iconTheme.path)
)); ));
return; return;
} }
if (!fileIconSet.id || (typeof fileIconSet.id !== 'string')) { if (!iconTheme.id || (typeof iconTheme.id !== 'string')) {
collector.error(nls.localize( collector.error(nls.localize(
'reqid', 'reqid',
"Expected string in `contributes.{0}.id`. Provided value: {1}", "Expected string in `contributes.{0}.id`. Provided value: {1}",
themesExtPoint.name, themesExtPoint.name,
String(fileIconSet.path) String(iconTheme.path)
)); ));
return; return;
} }
let normalizedAbsolutePath = Paths.normalize(Paths.join(extensionFolderPath, fileIconSet.path)); let normalizedAbsolutePath = Paths.normalize(Paths.join(extensionFolderPath, iconTheme.path));
if (normalizedAbsolutePath.indexOf(extensionFolderPath) !== 0) { if (normalizedAbsolutePath.indexOf(extensionFolderPath) !== 0) {
collector.warn(nls.localize('invalid.path.1', "Expected `contributes.{0}.path` ({1}) to be included inside extension's folder ({2}). This might make the extension non-portable.", themesExtPoint.name, normalizedAbsolutePath, extensionFolderPath)); collector.warn(nls.localize('invalid.path.1', "Expected `contributes.{0}.path` ({1}) to be included inside extension's folder ({2}). This might make the extension non-portable.", themesExtPoint.name, normalizedAbsolutePath, extensionFolderPath));
} }
this.knownFileIconContributions.push({ this.knownIconThemes.push({
id: fileIconSet.id, id: iconTheme.id,
label: fileIconSet.label || Paths.basename(fileIconSet.path), label: iconTheme.label || Paths.basename(iconTheme.path),
description: fileIconSet.description, description: iconTheme.description,
path: normalizedAbsolutePath, path: normalizedAbsolutePath,
extensionId: extensionId extensionId: extensionId
}); });
...@@ -398,7 +397,7 @@ export class ThemeService implements IThemeService { ...@@ -398,7 +397,7 @@ export class ThemeService implements IThemeService {
public getFileIconThemes(): TPromise<IThemeData[]> { public getFileIconThemes(): TPromise<IThemeData[]> {
return this.extensionService.onReady().then(isReady => { return this.extensionService.onReady().then(isReady => {
return this.knownFileIconContributions; return this.knownIconThemes;
}); });
} }
...@@ -406,11 +405,11 @@ export class ThemeService implements IThemeService { ...@@ -406,11 +405,11 @@ export class ThemeService implements IThemeService {
return this.currentIconTheme || this.storageService.get(ICON_THEME_PREF, StorageScope.GLOBAL, ''); return this.currentIconTheme || this.storageService.get(ICON_THEME_PREF, StorageScope.GLOBAL, '');
} }
public setFileIconTheme(fileIcons: string, broadcastToAllWindows: boolean) : TPromise<boolean> { public setFileIconTheme(iconTheme: string, broadcastToAllWindows: boolean) : TPromise<boolean> {
fileIcons = fileIcons || ''; iconTheme = iconTheme || '';
if (fileIcons === this.currentIconTheme) { if (iconTheme === this.currentIconTheme) {
if (broadcastToAllWindows) { if (broadcastToAllWindows) {
this.windowService.broadcast({ channel: ICON_THEME_CHANNEL, payload: fileIcons }); this.windowService.broadcast({ channel: ICON_THEME_CHANNEL, payload: iconTheme });
} }
return TPromise.as(true); return TPromise.as(true);
} }
...@@ -425,11 +424,11 @@ export class ThemeService implements IThemeService { ...@@ -425,11 +424,11 @@ export class ThemeService implements IThemeService {
} }
}; };
this.currentIconTheme = fileIcons; this.currentIconTheme = iconTheme;
return this._updateFileIcons(onApply); return this._updateIconTheme(onApply);
} }
private _updateFileIcons(onApply: (theme:IInternalThemeData) => void) : TPromise<boolean> { private _updateIconTheme(onApply: (theme:IInternalThemeData) => void) : TPromise<boolean> {
return this.getFileIconThemes().then(allIconSets => { return this.getFileIconThemes().then(allIconSets => {
let iconSetData; let iconSetData;
for (let iconSet of allIconSets) { for (let iconSet of allIconSets) {
...@@ -438,56 +437,56 @@ export class ThemeService implements IThemeService { ...@@ -438,56 +437,56 @@ export class ThemeService implements IThemeService {
break; break;
} }
} }
return _applyFileIcons(iconSetData, onApply); return _applyIconTheme(iconSetData, onApply);
}); });
} }
} }
function _applyFileIcons(data: IInternalThemeData, onApply: (theme:IInternalThemeData) => void): TPromise<boolean> { function _applyIconTheme(data: IInternalThemeData, onApply: (theme:IInternalThemeData) => void): TPromise<boolean> {
if (!data) { if (!data) {
_applyRules('', fileIconRulesClassName); _applyRules('', iconThemeRulesClassName);
onApply(data); onApply(data);
return TPromise.as(true); return TPromise.as(true);
} }
if (data.styleSheetContent) { if (data.styleSheetContent) {
_applyRules(data.styleSheetContent, fileIconRulesClassName); _applyRules(data.styleSheetContent, iconThemeRulesClassName);
onApply(data); onApply(data);
return TPromise.as(true); return TPromise.as(true);
} }
return _loadFileIconsDocument(data.path).then(fileIconsDocument => { return _loadIconThemeDocument(data.path).then(iconThemeDocument => {
let styleSheetContent = _processFileIconsObject(data.id, data.path, fileIconsDocument); let styleSheetContent = _processIconThemeDocument(data.id, data.path, iconThemeDocument);
data.styleSheetContent = styleSheetContent; data.styleSheetContent = styleSheetContent;
_applyRules(styleSheetContent, fileIconRulesClassName); _applyRules(styleSheetContent, iconThemeRulesClassName);
onApply(data); onApply(data);
return true; return true;
}, error => { }, error => {
return TPromise.wrapError(nls.localize('error.cannotloadfileicons', "Unable to load {0}", data.path)); return TPromise.wrapError(nls.localize('error.cannotloadicontheme', "Unable to load {0}", data.path));
}); });
} }
function _loadFileIconsDocument(fileSetPath: string) : TPromise<FileIconsDocument> { function _loadIconThemeDocument(fileSetPath: string) : TPromise<IconThemeDocument> {
return pfs.readFile(fileSetPath).then(content => { return pfs.readFile(fileSetPath).then(content => {
let errors: Json.ParseError[] = []; let errors: Json.ParseError[] = [];
let contentValue = <ThemeDocument> Json.parse(content.toString(), errors); let contentValue = <ThemeDocument> Json.parse(content.toString(), errors);
if (errors.length > 0) { if (errors.length > 0) {
return TPromise.wrapError(new Error(nls.localize('error.cannotparsefileicons', "Problems parsing file icons file: {0}", errors.map(e => Json.getParseErrorMessage(e.error)).join(', ')))); return TPromise.wrapError(new Error(nls.localize('error.cannotparseicontheme', "Problems parsing file icons file: {0}", errors.map(e => Json.getParseErrorMessage(e.error)).join(', '))));
} }
return TPromise.as(contentValue); return TPromise.as(contentValue);
}); });
} }
function _processFileIconsObject(id: string, fileIconsPath: string, fileIconsDocument: FileIconsDocument) : string { function _processIconThemeDocument(id: string, iconThemeDocumentPath: string, iconThemeDocument: IconThemeDocument) : string {
if (!fileIconsDocument.iconDefinitions) { if (!iconThemeDocument.iconDefinitions) {
return ''; return '';
} }
let selectorByDefinitionId : {[def:string]:string[]} = {}; let selectorByDefinitionId : {[def:string]:string[]} = {};
function resolvePath(path: string) { function resolvePath(path: string) {
return Paths.join(Paths.dirname(fileIconsPath), path); return Paths.join(Paths.dirname(iconThemeDocumentPath), path);
} }
function collectSelectors(associations: FileIconsAssociation, baseThemeClassName?: string) { function collectSelectors(associations: IconsAssociation, baseThemeClassName?: string) {
function addSelector(selector: string, defId: string) { function addSelector(selector: string, defId: string) {
if (defId) { if (defId) {
let list = selectorByDefinitionId[defId]; let list = selectorByDefinitionId[defId];
...@@ -542,13 +541,13 @@ function _processFileIconsObject(id: string, fileIconsPath: string, fileIconsDoc ...@@ -542,13 +541,13 @@ function _processFileIconsObject(id: string, fileIconsPath: string, fileIconsDoc
} }
} }
} }
collectSelectors(fileIconsDocument); collectSelectors(iconThemeDocument);
collectSelectors(fileIconsDocument.light, '.vs'); collectSelectors(iconThemeDocument.light, '.vs');
collectSelectors(fileIconsDocument.highContrast, '.hc_black'); collectSelectors(iconThemeDocument.highContrast, '.hc_black');
let cssRules: string[] = []; let cssRules: string[] = [];
let fonts = fileIconsDocument.fonts; let fonts = iconThemeDocument.fonts;
if (Array.isArray(fonts)) { if (Array.isArray(fonts)) {
fonts.forEach(font => { fonts.forEach(font => {
let src = font.src.map(l => `url('${resolvePath(l.path)}') format('${l.format}')`).join(', '); let src = font.src.map(l => `url('${resolvePath(l.path)}') format('${l.format}')`).join(', ');
...@@ -559,7 +558,7 @@ function _processFileIconsObject(id: string, fileIconsPath: string, fileIconsDoc ...@@ -559,7 +558,7 @@ function _processFileIconsObject(id: string, fileIconsPath: string, fileIconsDoc
for (let defId in selectorByDefinitionId) { for (let defId in selectorByDefinitionId) {
let selectors = selectorByDefinitionId[defId]; let selectors = selectorByDefinitionId[defId];
let definition = fileIconsDocument.iconDefinitions[defId]; let definition = iconThemeDocument.iconDefinitions[defId];
if (definition) { if (definition) {
if (definition.iconPath) { if (definition.iconPath) {
cssRules.push(`${selectors.join(', ')} { content: ' '; background-image: url("${resolvePath(definition.iconPath)}"); }`); cssRules.push(`${selectors.join(', ')} { content: ' '; background-image: url("${resolvePath(definition.iconPath)}"); }`);
...@@ -750,7 +749,7 @@ function _settingsToStatements(settings: ThemeSettingStyle): string { ...@@ -750,7 +749,7 @@ function _settingsToStatements(settings: ThemeSettingStyle): string {
} }
let colorThemeRulesClassName = 'contributedColorTheme'; let colorThemeRulesClassName = 'contributedColorTheme';
let fileIconRulesClassName = 'contributedFileIcons'; let iconThemeRulesClassName = 'contributedIconTheme';
function _applyRules(styleSheetContent: string, rulesClassName: string) { function _applyRules(styleSheetContent: string, rulesClassName: string) {
let themeStyles = document.head.getElementsByClassName(rulesClassName); let themeStyles = document.head.getElementsByClassName(rulesClassName);
...@@ -816,9 +815,8 @@ class Color { ...@@ -816,9 +815,8 @@ class Color {
b: 255 - this.parsed.b, b: 255 - this.parsed.b,
a : this.parsed.a a : this.parsed.a
}); });
}
} }
}); }
const schemaId = 'vscode://schemas/icon-theme'; const schemaId = 'vscode://schemas/icon-theme';
const schema: IJSONSchema = { const schema: IJSONSchema = {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册