2017-06-17 16:52:27 +02:00
|
|
|
import * as fs from 'fs';
|
|
|
|
import * as vscode from 'vscode';
|
|
|
|
|
2017-06-20 14:39:45 +02:00
|
|
|
import { getAbsolutePath, getDefaultValues, getThemeIconsByContributeID, getThemeIconsContribute } from "../../helpers/fs";
|
2017-06-17 16:52:27 +02:00
|
|
|
import { getCurrentThemeID, getCurrentThemeIconsID, reloadWindow } from "../../helpers/vscode";
|
2017-06-23 13:55:52 +02:00
|
|
|
import { getCustomSettings, isAccent, shouldReloadWindow } from "../../helpers/settings";
|
2017-06-17 16:52:27 +02:00
|
|
|
|
|
|
|
import { CHARSET } from "../../consts/files";
|
|
|
|
import { IPackageJSONThemeIcons } from "../../interfaces/ipackage.json";
|
|
|
|
import { IThemeIcons } from "../../interfaces/itheme-icons";
|
|
|
|
|
|
|
|
export const THEME_CHANGE_LISTENER = () => {
|
|
|
|
vscode.workspace.onDidChangeConfiguration(() => {
|
|
|
|
let themeID: string = getCurrentThemeID();
|
|
|
|
let themeIconsID: string = getCurrentThemeIconsID();
|
|
|
|
|
|
|
|
if (themeIconsID && /material-theme/i.test(themeIconsID)) {
|
2017-06-23 13:55:52 +02:00
|
|
|
let customSettings = getCustomSettings();
|
2017-06-17 16:52:27 +02:00
|
|
|
let defaults = getDefaultValues();
|
2017-06-23 13:55:52 +02:00
|
|
|
let accentName = customSettings.accent;
|
2017-06-17 16:52:27 +02:00
|
|
|
let variantNames: string[] = themeID.split('Material Theme');
|
|
|
|
let variantName: string = variantNames[1] === undefined ? '' : variantNames[1].trim();
|
|
|
|
let themeContribute: IPackageJSONThemeIcons = getThemeIconsContribute(themeIconsID);
|
|
|
|
let theme: IThemeIcons = getThemeIconsByContributeID(themeIconsID);
|
|
|
|
let themepath: string = getAbsolutePath(themeContribute.path);
|
2017-06-23 13:55:52 +02:00
|
|
|
|
|
|
|
if (isAccent(accentName, defaults)) {
|
|
|
|
let _accentName = accentName.replace(/\s+/, '-');
|
|
|
|
theme.iconDefinitions._folder_open.iconPath = defaults.icons.theme.iconDefinitions._folder_open.iconPath.replace('.svg', `.accent.${ _accentName }.svg`);
|
|
|
|
theme.iconDefinitions._folder_open_build.iconPath = defaults.icons.theme.iconDefinitions._folder_open_build.iconPath.replace('.svg', `.accent.${ _accentName }.svg`);
|
|
|
|
} else {
|
|
|
|
theme.iconDefinitions._folder_open.iconPath = defaults.icons.theme.iconDefinitions._folder_open.iconPath;
|
|
|
|
theme.iconDefinitions._folder_open_build.iconPath = defaults.icons.theme.iconDefinitions._folder_open_build.iconPath;
|
|
|
|
}
|
2017-06-17 16:52:27 +02:00
|
|
|
|
|
|
|
theme.iconDefinitions._folder_dark.iconPath = defaults.icons.theme.iconDefinitions._folder_dark.iconPath.replace('.svg', `${ variantName }.svg`);
|
|
|
|
theme.iconDefinitions._file_folder.iconPath = defaults.icons.theme.iconDefinitions._file_folder.iconPath.replace('.svg', `${ variantName }.svg`);
|
|
|
|
theme.iconDefinitions["_file_folder-build"].iconPath = defaults.icons.theme.iconDefinitions["_file_folder-build"].iconPath.replace('.svg', `${ variantName }.svg`);
|
|
|
|
|
2017-06-23 13:55:52 +02:00
|
|
|
fs.writeFile(themepath, JSON.stringify(theme), { encoding: CHARSET }, (error) => {
|
|
|
|
if (error) {
|
|
|
|
console.trace(error);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (shouldReloadWindow(themeID, themeIconsID)) {
|
|
|
|
vscode.window.showInformationMessage('Material theme requires VS Code reload in order to look very good').then(() => {
|
|
|
|
reloadWindow();
|
|
|
|
}, (error) => {
|
|
|
|
console.log(error);
|
|
|
|
});
|
2017-06-17 16:52:27 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|