2018-04-20 20:07:36 +02:00
|
|
|
import * as vscode from 'vscode';
|
|
|
|
|
2018-05-03 11:39:51 +02:00
|
|
|
import {IDefaults} from './../interfaces/idefaults';
|
|
|
|
import {IThemeCustomProperties} from './../interfaces/itheme-custom-properties';
|
2018-04-20 20:07:36 +02:00
|
|
|
import {getPackageJSON} from './fs';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets saved accent
|
|
|
|
*/
|
|
|
|
export function getAccent(): string | undefined {
|
|
|
|
return getCustomSettings().accent;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets custom settings
|
|
|
|
*/
|
|
|
|
export function getCustomSettings(): IThemeCustomProperties {
|
2018-04-30 09:55:47 +02:00
|
|
|
return vscode.workspace.getConfiguration().get<IThemeCustomProperties>('materialTheme', {});
|
2018-04-20 20:07:36 +02:00
|
|
|
}
|
|
|
|
|
2018-05-18 13:47:22 +02:00
|
|
|
/**
|
|
|
|
* Get autoApplyIcons
|
|
|
|
*/
|
|
|
|
export function isAutoApplyEnable(): boolean {
|
2018-08-12 19:09:36 +02:00
|
|
|
return vscode.workspace.getConfiguration().get<boolean>('materialTheme.autoApplyIcons');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get showReloadNotification
|
|
|
|
*/
|
|
|
|
export function isReloadNotificationEnable(): boolean {
|
|
|
|
return vscode.workspace.getConfiguration().get<boolean>('materialTheme.showReloadNotification');
|
2018-05-18 13:47:22 +02:00
|
|
|
}
|
|
|
|
|
2018-04-20 20:07:36 +02:00
|
|
|
/**
|
|
|
|
* Checks if a given string could be an accent
|
|
|
|
*/
|
|
|
|
export function isAccent(accentName: string, defaults: IDefaults): boolean {
|
2018-05-18 13:47:22 +02:00
|
|
|
return Boolean(Object.keys(defaults.accents).find(name => name === accentName));
|
2018-04-20 20:07:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Determines if the passing theme label is a material theme
|
|
|
|
*/
|
|
|
|
export function isMaterialTheme(themeName: string): boolean {
|
2018-05-03 11:39:51 +02:00
|
|
|
const packageJSON = getPackageJSON();
|
2018-05-18 13:47:22 +02:00
|
|
|
return Boolean(packageJSON.contributes.themes.find(contrib => contrib.label === themeName));
|
2018-04-20 20:07:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Determines if the passing icons theme is a material theme
|
|
|
|
*/
|
|
|
|
export function isMaterialThemeIcons(themeIconsName: string): boolean {
|
2018-05-03 11:39:51 +02:00
|
|
|
const packageJSON = getPackageJSON();
|
2018-05-18 13:47:22 +02:00
|
|
|
return Boolean(packageJSON.contributes.iconThemes.find(contribute => contribute.id === themeIconsName));
|
2018-04-20 20:07:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets a custom property in custom settings
|
|
|
|
*/
|
2018-05-18 13:47:22 +02:00
|
|
|
export function setCustomSetting(settingName: string, value: any): Thenable<string> {
|
|
|
|
return vscode.workspace.getConfiguration().update(`materialTheme.${settingName}`, value, true).then(() => settingName);
|
2018-04-20 20:07:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Updates accent name
|
|
|
|
*/
|
2018-05-18 13:47:22 +02:00
|
|
|
export function updateAccent(accentName: string): Thenable<string> {
|
2018-08-16 09:11:38 +02:00
|
|
|
return setCustomSetting('accent', accentName);
|
2018-05-03 11:39:51 +02:00
|
|
|
}
|