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
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if a given string could be an accent
|
|
|
|
*/
|
|
|
|
export function isAccent(accentName: string, defaults: IDefaults): boolean {
|
|
|
|
return Object.keys(defaults.accents).filter(name => name === accentName).length > 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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-04-20 20:07:36 +02:00
|
|
|
return packageJSON.contributes.themes.filter(contrib => contrib.label === themeName).length > 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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-04-20 20:07:36 +02:00
|
|
|
return packageJSON.contributes.iconThemes.filter(contribute => contribute.id === themeIconsName).length > 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets a custom property in custom settings
|
|
|
|
*/
|
2018-04-30 09:55:47 +02:00
|
|
|
export function setCustomSetting(settingName: string, value: any): Thenable<void> {
|
|
|
|
return vscode.workspace.getConfiguration().update(`materialTheme.${settingName}`, value, true);
|
2018-04-20 20:07:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Updates accent name
|
|
|
|
*/
|
|
|
|
export function updateAccent(accentName: string): Thenable<void> {
|
2018-04-30 09:55:47 +02:00
|
|
|
const prevAccent = getAccent();
|
|
|
|
return setCustomSetting('accentPrevious', prevAccent)
|
2018-05-03 11:39:51 +02:00
|
|
|
.then(() => setCustomSetting('accent', accentName));
|
|
|
|
}
|