vsc-material-theme/extensions/helpers/settings.ts

71 lines
2 KiB
TypeScript
Raw Normal View History

2018-04-20 20:07:36 +02:00
import * as vscode from 'vscode';
import {IDefaults} from './../interfaces/idefaults';
import {IThemeCustomSettings} 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(): IThemeCustomSettings {
return vscode.workspace.getConfiguration().get<IThemeCustomSettings>('materialTheme', {});
2018-04-20 20:07:36 +02:00
}
/**
* Get autoApplyIcons
*/
export function isAutoApplyEnable(): boolean {
return vscode.workspace.getConfiguration().get<boolean>('materialTheme.autoApplyIcons');
}
/**
* Get showReloadNotification
*/
export function isReloadNotificationEnable(): boolean {
return vscode.workspace.getConfiguration().get<boolean>('materialTheme.showReloadNotification');
}
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 {
return Boolean(Object.keys(defaults.accents).find(name => name === accentName));
2018-04-20 20:07:36 +02:00
}
/**
* Determines if the passing theme id is a material theme
2018-04-20 20:07:36 +02:00
*/
export function isMaterialTheme(themeName: string): boolean {
const packageJSON = getPackageJSON();
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 {
const packageJSON = getPackageJSON();
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
*/
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
*/
export function updateAccent(accentName: string): Thenable<string> {
return setCustomSetting('accent', accentName);
}