chore: Moves accents colours to defaults.json. Adds a reload window confirm message, this due to bugs.
This commit is contained in:
parent
36826d2e2f
commit
a412e4edde
14 changed files with 116 additions and 129 deletions
|
@ -1,10 +1,8 @@
|
||||||
interface IIconObject {
|
import { IThemeIconsItem } from "./itheme-icons-item";
|
||||||
iconPath: string
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface IThemeIconsAccents {
|
export interface IThemeIconsAccents {
|
||||||
iconDefinitions: {
|
iconDefinitions: {
|
||||||
_folder_open: IIconObject;
|
_folder_open: IThemeIconsItem;
|
||||||
_folder_open_build: IIconObject;
|
_folder_open_build: IThemeIconsItem;
|
||||||
}
|
}
|
||||||
}
|
}
|
3
.gulp/interfaces/itheme-icons-item.ts
Normal file
3
.gulp/interfaces/itheme-icons-item.ts
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
export interface IThemeIconsItem {
|
||||||
|
iconPath: string;
|
||||||
|
}
|
|
@ -1,12 +1,10 @@
|
||||||
export interface IThemeIconsVariantsItem {
|
import { IThemeIconsItem } from "./itheme-icons-item";
|
||||||
iconPath: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface IThemeIconsVariants {
|
export interface IThemeIconsVariants {
|
||||||
iconDefinitions: {
|
iconDefinitions: {
|
||||||
"_folder_dark": IThemeIconsVariantsItem;
|
"_folder_dark": IThemeIconsItem;
|
||||||
"_folder_dark-build": IThemeIconsVariantsItem;
|
"_folder_dark-build": IThemeIconsItem;
|
||||||
"_file_folder": IThemeIconsVariantsItem;
|
"_file_folder": IThemeIconsItem;
|
||||||
"_file_folder-build": IThemeIconsVariantsItem;
|
"_file_folder-build": IThemeIconsItem;
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -6,7 +6,7 @@ import * as path from 'path';
|
||||||
import { MESSAGE_GENERATED, MESSAGE_ICON_ACCENTS_ERROR } from "../consts/log";
|
import { MESSAGE_GENERATED, MESSAGE_ICON_ACCENTS_ERROR } from "../consts/log";
|
||||||
|
|
||||||
import { CHARSET } from "../../extensions/consts/files";
|
import { CHARSET } from "../../extensions/consts/files";
|
||||||
import { IThemeConfigCommons } from '../../extensions/interfaces/icommons';
|
import { IDefaults } from "../../extensions/interfaces/idefaults";
|
||||||
import { IThemeIconsAccents } from "../interfaces/itheme-icons-accents";
|
import { IThemeIconsAccents } from "../interfaces/itheme-icons-accents";
|
||||||
import PATHS from '../../extensions/consts/paths'
|
import PATHS from '../../extensions/consts/paths'
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@ import PATHS from '../../extensions/consts/paths'
|
||||||
// import { writePackageJSON } from "../helpers/contribute-icon-theme";
|
// import { writePackageJSON } from "../helpers/contribute-icon-theme";
|
||||||
|
|
||||||
const BASE_ICON_THEME_PATH: string = path.join(process.cwd(), PATHS.THEMES, './Material-Theme-Icons.json');
|
const BASE_ICON_THEME_PATH: string = path.join(process.cwd(), PATHS.THEMES, './Material-Theme-Icons.json');
|
||||||
const THEME_COMMONS: IThemeConfigCommons = require('../../extensions/commands/accents-setter/commons.json');
|
const DEFAULTS: IDefaults = require('../../extensions/defaults.json');
|
||||||
// const PACKAGE_JSON: IPackageJSON = require('../../package.json');
|
// const PACKAGE_JSON: IPackageJSON = require('../../package.json');
|
||||||
|
|
||||||
// const PACKAGE_JSON_ICON_THEME: IPackageJSONThemeIcons = {
|
// const PACKAGE_JSON_ICON_THEME: IPackageJSONThemeIcons = {
|
||||||
|
@ -79,7 +79,7 @@ function replaceWhiteSpaces(input: string): string {
|
||||||
*/
|
*/
|
||||||
function writeSVGIcon(fromFile: string, toFile: string, accent: string): void {
|
function writeSVGIcon(fromFile: string, toFile: string, accent: string): void {
|
||||||
let fileContent: string = fs.readFileSync(normalizeIconPath(fromFile), CHARSET);
|
let fileContent: string = fs.readFileSync(normalizeIconPath(fromFile), CHARSET);
|
||||||
let content: string = replaceSVGColour(fileContent, THEME_COMMONS.accents[accent]);
|
let content: string = replaceSVGColour(fileContent, DEFAULTS.accents[accent]);
|
||||||
toFile = normalizeIconPath(toFile);
|
toFile = normalizeIconPath(toFile);
|
||||||
|
|
||||||
fs.writeFileSync(toFile, content);
|
fs.writeFileSync(toFile, content);
|
||||||
|
@ -94,7 +94,7 @@ export default gulp.task('build:icons.accents', cb => {
|
||||||
try {
|
try {
|
||||||
basetheme = require(BASE_ICON_THEME_PATH);
|
basetheme = require(BASE_ICON_THEME_PATH);
|
||||||
|
|
||||||
Object.keys(THEME_COMMONS.accents).forEach(key => {
|
Object.keys(DEFAULTS.accents).forEach(key => {
|
||||||
let iconName = replaceWhiteSpaces(key);
|
let iconName = replaceWhiteSpaces(key);
|
||||||
let themecopy: IThemeIconsAccents = JSON.parse(JSON.stringify(basetheme));
|
let themecopy: IThemeIconsAccents = JSON.parse(JSON.stringify(basetheme));
|
||||||
let themePath: string = path.join(PATHS.THEMES, `./Material-Theme-Icons-${ key }.json`);
|
let themePath: string = path.join(PATHS.THEMES, `./Material-Theme-Icons-${ key }.json`);
|
||||||
|
|
|
@ -7,8 +7,8 @@ import * as path from 'path';
|
||||||
import { HR, MESSAGE_GENERATED, MESSAGE_ICON_ERROR } from './../consts/log';
|
import { HR, MESSAGE_GENERATED, MESSAGE_ICON_ERROR } from './../consts/log';
|
||||||
|
|
||||||
import { CHARSET } from "../../extensions/consts/files";
|
import { CHARSET } from "../../extensions/consts/files";
|
||||||
|
import { IGenericObject } from "../../extensions/interfaces/igeneric-object";
|
||||||
import { IIcon } from './../interfaces/iicon';
|
import { IIcon } from './../interfaces/iicon';
|
||||||
import { IPlainObject } from '../interfaces/iplain-object';
|
|
||||||
import paths from '../../extensions/consts/paths';
|
import paths from '../../extensions/consts/paths';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -32,7 +32,7 @@ export default gulp.task('build:icons', cb => {
|
||||||
let fileNames: string[] = fs.readdirSync(path.join(paths.SRC, `./icons/svgs`));
|
let fileNames: string[] = fs.readdirSync(path.join(paths.SRC, `./icons/svgs`));
|
||||||
let icons: IIcon[] = fileNames.map(fileName => iconFactory(fileName));
|
let icons: IIcon[] = fileNames.map(fileName => iconFactory(fileName));
|
||||||
let partials: string[] = fs.readdirSync(path.join(paths.SRC, `./icons/partials`));
|
let partials: string[] = fs.readdirSync(path.join(paths.SRC, `./icons/partials`));
|
||||||
let partialsData: IPlainObject = {};
|
let partialsData: IGenericObject<any> = {};
|
||||||
let pathTemp: string = './themes/.material-theme-icons.tmp';
|
let pathTemp: string = './themes/.material-theme-icons.tmp';
|
||||||
|
|
||||||
icons[icons.length - 1].last = true;
|
icons[icons.length - 1].last = true;
|
||||||
|
|
|
@ -7,10 +7,11 @@ import * as path from 'path';
|
||||||
import { HR, MESSAGE_GENERATED, MESSAGE_THEME_VARIANT_PARSE_ERROR } from './../consts/log';
|
import { HR, MESSAGE_GENERATED, MESSAGE_THEME_VARIANT_PARSE_ERROR } from './../consts/log';
|
||||||
|
|
||||||
import { CHARSET } from "../../extensions/consts/files";
|
import { CHARSET } from "../../extensions/consts/files";
|
||||||
|
import { IDefaults } from "../../extensions/interfaces/idefaults";
|
||||||
import { IThemeVariant } from './../interfaces/itheme-variant';
|
import { IThemeVariant } from './../interfaces/itheme-variant';
|
||||||
import paths from '../../extensions/consts/paths';
|
import paths from '../../extensions/consts/paths';
|
||||||
|
|
||||||
let commons = require('../../extensions/commands/accents-setter/commons.json');
|
let commons: IDefaults = require('../../extensions/defaults.json');
|
||||||
|
|
||||||
let themeTemplateFileContent: string = fs.readFileSync(path.join(paths.SRC, `/themes/theme-template-color-theme.json`), CHARSET);
|
let themeTemplateFileContent: string = fs.readFileSync(path.join(paths.SRC, `/themes/theme-template-color-theme.json`), CHARSET);
|
||||||
let themeVariants: IThemeVariant[] = [];
|
let themeVariants: IThemeVariant[] = [];
|
||||||
|
|
|
@ -1,16 +1,13 @@
|
||||||
import * as vscode from 'vscode';
|
import * as vscode from 'vscode';
|
||||||
|
|
||||||
import { getCurrentThemeIconsID, reloadWindow } from "../../helpers/vscode";
|
|
||||||
import { getDefaultValues, getThemeIconsByContributeID, getThemeIconsContribute, writeFile } from "../../helpers/fs";
|
|
||||||
import { hasAccentChanged, isMaterialThemeIcons, updateAccent } from "../../helpers/settings";
|
|
||||||
|
|
||||||
import {IAccentCustomProperty} from '../../interfaces/iaccent-custom-property';
|
import {IAccentCustomProperty} from '../../interfaces/iaccent-custom-property';
|
||||||
|
import { IDefaults } from "../../interfaces/idefaults";
|
||||||
import {IGenericObject} from '../../interfaces/igeneric-object';
|
import {IGenericObject} from '../../interfaces/igeneric-object';
|
||||||
import {IThemeConfigCommons} from '../../interfaces/icommons';
|
import { updateAccent } from "../../helpers/settings";
|
||||||
|
|
||||||
const REGEXP_HEX: RegExp = /^#([0-9A-F]{6}|[0-9A-F]{8})$/i;
|
const REGEXP_HEX: RegExp = /^#([0-9A-F]{6}|[0-9A-F]{8})$/i;
|
||||||
|
|
||||||
let themeConfigCommon: IThemeConfigCommons = require('./commons.json');
|
let themeConfigCommon: IDefaults = require('../../defaults.json');
|
||||||
let accentsProperties: IGenericObject<IAccentCustomProperty> = {
|
let accentsProperties: IGenericObject<IAccentCustomProperty> = {
|
||||||
"activityBarBadge.background": {
|
"activityBarBadge.background": {
|
||||||
alpha: 100,
|
alpha: 100,
|
||||||
|
@ -70,42 +67,6 @@ function assignColorCustomizations(colour: string, config: any): void {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Assigns related icons theme name by accent name
|
|
||||||
* @param accentName
|
|
||||||
*/
|
|
||||||
export function assignIconTheme(accentName: string | undefined): void {
|
|
||||||
// let accentValue: string;
|
|
||||||
let themeIconsID: string = getCurrentThemeIconsID();
|
|
||||||
|
|
||||||
if (isMaterialThemeIcons(themeIconsID)) {
|
|
||||||
let defaults = getDefaultValues();
|
|
||||||
let theme = getThemeIconsByContributeID(themeIconsID);
|
|
||||||
let themeContribute = getThemeIconsContribute(themeIconsID);
|
|
||||||
|
|
||||||
if (accentName !== undefined) {
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
writeFile(themeContribute.path, JSON.stringify(theme));
|
|
||||||
|
|
||||||
// updateAccent(accentName);
|
|
||||||
|
|
||||||
if (hasAccentChanged(accentName)) {
|
|
||||||
reloadWindow();
|
|
||||||
}
|
|
||||||
// vscode.workspace.getConfiguration().update('workbench.iconTheme', themeIconsID, true).then(() => {
|
|
||||||
// In order to load modified icons we will have to reload the whole window.
|
|
||||||
// });
|
|
||||||
}
|
|
||||||
updateAccent(accentName);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determines if a string is a valid colour
|
* Determines if a string is a valid colour
|
||||||
* @param {(string | null | undefined)} colour
|
* @param {(string | null | undefined)} colour
|
||||||
|
@ -123,9 +84,12 @@ function isValidColour(colour: string | null | undefined): boolean {
|
||||||
* @param {string} accentSelected
|
* @param {string} accentSelected
|
||||||
* @param {*} config
|
* @param {*} config
|
||||||
*/
|
*/
|
||||||
function setWorkbenchOptions(accentSelected: string, config: any): void {
|
function setWorkbenchOptions(accentSelected: string | undefined, config: any): void {
|
||||||
vscode.workspace.getConfiguration().update('workbench.colorCustomizations', config, true).then(() => {
|
vscode.workspace.getConfiguration().update('workbench.colorCustomizations', config, true).then(() => {
|
||||||
vscode.window.showInformationMessage(`${ accentSelected } set`);
|
// let message: string = accentSelected !== undefined ? `${ accentSelected } set` : `Accents removed`;
|
||||||
|
updateAccent(accentSelected);
|
||||||
|
// vscode.window.showInformationMessage(message).then(() => {
|
||||||
|
// });
|
||||||
}, reason => {
|
}, reason => {
|
||||||
vscode.window.showErrorMessage(reason);
|
vscode.window.showErrorMessage(reason);
|
||||||
});
|
});
|
||||||
|
@ -164,13 +128,12 @@ export const THEME_ACCENTS_SETTER = () => {
|
||||||
// break;
|
// break;
|
||||||
case purgeColourKey:
|
case purgeColourKey:
|
||||||
assignColorCustomizations(undefined, config);
|
assignColorCustomizations(undefined, config);
|
||||||
setWorkbenchOptions(accentSelected, config);
|
setWorkbenchOptions(undefined, config);
|
||||||
assignIconTheme(undefined);
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
assignColorCustomizations(themeConfigCommon.accents[accentSelected], config);
|
assignColorCustomizations(themeConfigCommon.accents[accentSelected], config);
|
||||||
setWorkbenchOptions(accentSelected, config);
|
setWorkbenchOptions(accentSelected, config);
|
||||||
assignIconTheme(accentSelected);
|
// assignIconTheme(accentSelected);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -3,50 +3,51 @@ import * as vscode from 'vscode';
|
||||||
|
|
||||||
import { getAbsolutePath, getDefaultValues, getThemeIconsByContributeID, getThemeIconsContribute } from "../../helpers/fs";
|
import { getAbsolutePath, getDefaultValues, getThemeIconsByContributeID, getThemeIconsContribute } from "../../helpers/fs";
|
||||||
import { getCurrentThemeID, getCurrentThemeIconsID, reloadWindow } from "../../helpers/vscode";
|
import { getCurrentThemeID, getCurrentThemeIconsID, reloadWindow } from "../../helpers/vscode";
|
||||||
import { shouldReloadWindow, updateSettingsTheme, updateSettingsThemeIcons } from "../../helpers/settings";
|
import { getCustomSettings, isAccent, shouldReloadWindow } from "../../helpers/settings";
|
||||||
|
|
||||||
import { CHARSET } from "../../consts/files";
|
import { CHARSET } from "../../consts/files";
|
||||||
import { IPackageJSONThemeIcons } from "../../interfaces/ipackage.json";
|
import { IPackageJSONThemeIcons } from "../../interfaces/ipackage.json";
|
||||||
import { IThemeIcons } from "../../interfaces/itheme-icons";
|
import { IThemeIcons } from "../../interfaces/itheme-icons";
|
||||||
import { assignIconTheme } from "../accents-setter/index";
|
|
||||||
|
|
||||||
export const THEME_CHANGE_LISTENER = () => {
|
export const THEME_CHANGE_LISTENER = () => {
|
||||||
vscode.workspace.onDidChangeConfiguration(() => {
|
vscode.workspace.onDidChangeConfiguration(() => {
|
||||||
let cacheKey: string = 'materialTheme.cache.workbench.accent';
|
|
||||||
let cache = vscode.workspace.getConfiguration().get<any>(cacheKey);
|
|
||||||
let themeID: string = getCurrentThemeID();
|
let themeID: string = getCurrentThemeID();
|
||||||
let themeIconsID: string = getCurrentThemeIconsID();
|
let themeIconsID: string = getCurrentThemeIconsID();
|
||||||
|
|
||||||
if (themeIconsID && /material-theme/i.test(themeIconsID)) {
|
if (themeIconsID && /material-theme/i.test(themeIconsID)) {
|
||||||
|
let customSettings = getCustomSettings();
|
||||||
let defaults = getDefaultValues();
|
let defaults = getDefaultValues();
|
||||||
|
let accentName = customSettings.accent;
|
||||||
let variantNames: string[] = themeID.split('Material Theme');
|
let variantNames: string[] = themeID.split('Material Theme');
|
||||||
let variantName: string = variantNames[1] === undefined ? '' : variantNames[1].trim();
|
let variantName: string = variantNames[1] === undefined ? '' : variantNames[1].trim();
|
||||||
let themeContribute: IPackageJSONThemeIcons = getThemeIconsContribute(themeIconsID);
|
let themeContribute: IPackageJSONThemeIcons = getThemeIconsContribute(themeIconsID);
|
||||||
let theme: IThemeIcons = getThemeIconsByContributeID(themeIconsID);
|
let theme: IThemeIcons = getThemeIconsByContributeID(themeIconsID);
|
||||||
let themepath: string = getAbsolutePath(themeContribute.path);
|
let themepath: string = getAbsolutePath(themeContribute.path);
|
||||||
let shouldReload: boolean = shouldReloadWindow(themeID, themeIconsID);
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
theme.iconDefinitions._folder_dark.iconPath = defaults.icons.theme.iconDefinitions._folder_dark.iconPath.replace('.svg', `${ variantName }.svg`);
|
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.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`);
|
theme.iconDefinitions["_file_folder-build"].iconPath = defaults.icons.theme.iconDefinitions["_file_folder-build"].iconPath.replace('.svg', `${ variantName }.svg`);
|
||||||
|
|
||||||
if (!!cache && cache.globalValue) {
|
fs.writeFile(themepath, JSON.stringify(theme), { encoding: CHARSET }, (error) => {
|
||||||
assignIconTheme(cacheKey);
|
if (error) {
|
||||||
|
console.trace(error);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
if (shouldReloadWindow(themeID, themeIconsID)) {
|
||||||
updateSettingsTheme(themeID);
|
vscode.window.showInformationMessage('Material theme requires VS Code reload in order to look very good').then(() => {
|
||||||
updateSettingsThemeIcons(themeIconsID);
|
|
||||||
|
|
||||||
console.log(
|
|
||||||
theme.iconDefinitions._folder_dark.iconPath
|
|
||||||
, theme.iconDefinitions._file_folder.iconPath
|
|
||||||
)
|
|
||||||
|
|
||||||
fs.writeFileSync(themepath, JSON.stringify(theme), CHARSET);
|
|
||||||
|
|
||||||
vscode.workspace.getConfiguration().update('workbench.iconTheme', themeIconsID, true).then(() => {
|
|
||||||
if (shouldReload) {
|
|
||||||
reloadWindow();
|
reloadWindow();
|
||||||
|
}, (error) => {
|
||||||
|
console.log(error);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,22 @@
|
||||||
{
|
{
|
||||||
|
"accents": {
|
||||||
|
"Acid Lime": "#C6FF00",
|
||||||
|
"Blue": "#2979FF",
|
||||||
|
"Breaking Bad": "#388E3C",
|
||||||
|
"Bright Teal": "#64FFDA",
|
||||||
|
"Cyan": "#00BCD4",
|
||||||
|
"Graphite": "#616161",
|
||||||
|
"Indigo": "#5C6BC0",
|
||||||
|
"Lime": "#7CB342",
|
||||||
|
"Orange": "#FF7042",
|
||||||
|
"Pink": "#FF4081",
|
||||||
|
"Purple": "#AB47BC",
|
||||||
|
"Red": "#E57373",
|
||||||
|
"Sky": "#84FFFF",
|
||||||
|
"Tomato": "#F44336",
|
||||||
|
"Teal": "#80CBC4",
|
||||||
|
"Yellow": "#FFA000"
|
||||||
|
},
|
||||||
"icons": {
|
"icons": {
|
||||||
"theme": {
|
"theme": {
|
||||||
"iconDefinitions": {
|
"iconDefinitions": {
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import * as vscode from 'vscode';
|
import * as vscode from 'vscode';
|
||||||
|
|
||||||
|
import { IDefaults } from "../interfaces/idefaults";
|
||||||
import { IThemeCustomProperties } from "../interfaces/itheme-custom-properties";
|
import { IThemeCustomProperties } from "../interfaces/itheme-custom-properties";
|
||||||
import { getPackageJSON } from "./fs";
|
import { getPackageJSON } from "./fs";
|
||||||
|
|
||||||
|
@ -8,8 +9,8 @@ import { getPackageJSON } from "./fs";
|
||||||
* @export
|
* @export
|
||||||
* @returns {(string | null)}
|
* @returns {(string | null)}
|
||||||
*/
|
*/
|
||||||
export function getAccent(): string | null {
|
export function getAccent(): string | undefined {
|
||||||
return vscode.workspace.getConfiguration().get<string>('materialTheme.cache.workbench.accent', null);
|
return getCustomSettings().accent;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -22,13 +23,14 @@ export function getCustomSettings(): IThemeCustomProperties {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determines if the accent name has changed
|
* Checks if a given string could be an accent
|
||||||
|
*
|
||||||
* @export
|
* @export
|
||||||
* @param {string} accentName
|
* @param {string} accentName
|
||||||
* @returns {boolean}
|
* @returns {boolean}
|
||||||
*/
|
*/
|
||||||
export function hasAccentChanged(accentName: string): boolean {
|
export function isAccent(accentName: string, defaults: IDefaults): boolean {
|
||||||
return accentName !== getAccent();
|
return Object.keys(defaults.accents).filter(name => name === accentName).length > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -54,15 +56,29 @@ export function isMaterialThemeIcons(themeIconsName: string): boolean {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets custom properties in custom settings
|
* Sets a custom property in custom settings
|
||||||
* @export
|
* @export
|
||||||
* @param {string} settingname
|
* @param {string} settingname
|
||||||
* @param {*} value
|
* @param {*} value
|
||||||
*/
|
*/
|
||||||
export function setCustomSetting(settingname: string, value: any): void {
|
export function setCustomSetting(settingname: string, value: any): Thenable<void> {
|
||||||
let settings: any = getCustomSettings();
|
let settings: any = getCustomSettings();
|
||||||
settings[settingname] = value;
|
settings[settingname] = value;
|
||||||
vscode.workspace.getConfiguration().update('materialTheme.cache.workbench.settings', settings, true);
|
return vscode.workspace.getConfiguration().update('materialTheme.cache.workbench.settings', settings, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets custom properties in custom settings
|
||||||
|
* @export
|
||||||
|
* @param {*} settingsObject
|
||||||
|
* @returns {Thenable<void>}
|
||||||
|
*/
|
||||||
|
export function setCustomSettings(settingsObject: IThemeCustomProperties): Thenable<void> {
|
||||||
|
let settings: any = getCustomSettings();
|
||||||
|
|
||||||
|
Object.keys(settingsObject).forEach(key => settings[key] = (settingsObject as any)[key]);
|
||||||
|
|
||||||
|
return vscode.workspace.getConfiguration().update('materialTheme.cache.workbench.settings', settings, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -80,7 +96,7 @@ export function shouldReloadWindow(themeColour: string, themeIcons: string): boo
|
||||||
|
|
||||||
let customSettings = getCustomSettings();
|
let customSettings = getCustomSettings();
|
||||||
|
|
||||||
return customSettings.themeColours !== themeColour || customSettings.themeIcons !== themeIcons;
|
return customSettings.themeColours !== themeColour || customSettings.themeIcons !== themeIcons || customSettings.accent !== customSettings.accentPrevious;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -88,24 +104,17 @@ export function shouldReloadWindow(themeColour: string, themeIcons: string): boo
|
||||||
* @export
|
* @export
|
||||||
* @param {string} accentName
|
* @param {string} accentName
|
||||||
*/
|
*/
|
||||||
export function updateAccent(accentName: string): void {
|
export function updateAccent(accentName: string): Thenable<void> {
|
||||||
vscode.workspace.getConfiguration().update('materialTheme.cache.workbench.accent', accentName, true);
|
let config: IThemeCustomProperties = {};
|
||||||
|
let prevaccent = getAccent();
|
||||||
|
|
||||||
|
if (prevaccent !== undefined && prevaccent !== accentName) {
|
||||||
|
config.accentPrevious = prevaccent;
|
||||||
|
} else if (accentName === undefined) {
|
||||||
|
config.accentPrevious = undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
config.accent = accentName;
|
||||||
* Updates theme name to custom settings
|
|
||||||
* @export
|
|
||||||
* @param {string} themeName
|
|
||||||
*/
|
|
||||||
export function updateSettingsTheme(themeName: string): void {
|
|
||||||
setCustomSetting('themeColours', themeName);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
return setCustomSettings(config);
|
||||||
* Updates icons theme name to custom settings
|
|
||||||
* @export
|
|
||||||
* @param {string} themeName
|
|
||||||
*/
|
|
||||||
export function updateSettingsThemeIcons(themeName: string): void {
|
|
||||||
setCustomSetting('themeIcons', themeName);
|
|
||||||
}
|
}
|
|
@ -1,8 +1,14 @@
|
||||||
export interface IDefaults {
|
export interface IDefaults {
|
||||||
|
accents: IAccents;
|
||||||
icons: IDefaultsThemeIcons;
|
icons: IDefaultsThemeIcons;
|
||||||
themeVariants: IDefaultsThemeVariant;
|
themeVariants: IDefaultsThemeVariant;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface IAccents {
|
||||||
|
teal: string;
|
||||||
|
[index: string]: string;
|
||||||
|
}
|
||||||
|
|
||||||
export interface IDefaultsThemeIcons {
|
export interface IDefaultsThemeIcons {
|
||||||
theme: {
|
theme: {
|
||||||
iconDefinitions: {
|
iconDefinitions: {
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
export interface IThemeCustomProperties {
|
export interface IThemeCustomProperties {
|
||||||
|
accent?: string;
|
||||||
|
accentPrevious?: string;
|
||||||
themeColours?: string;
|
themeColours?: string;
|
||||||
themeIcons?: string;
|
themeIcons?: string;
|
||||||
}
|
}
|
14
package.json
14
package.json
|
@ -54,23 +54,11 @@
|
||||||
],
|
],
|
||||||
"configuration": {
|
"configuration": {
|
||||||
"properties": {
|
"properties": {
|
||||||
"materialTheme.cache.workbench.accent": {
|
|
||||||
"default": "",
|
|
||||||
"type": "string",
|
|
||||||
"title": "Accent selected",
|
|
||||||
"description": "Theme's current accent."
|
|
||||||
},
|
|
||||||
"materialTheme.cache.workbench.colorCustomizations": {
|
|
||||||
"default": {},
|
|
||||||
"type": "object",
|
|
||||||
"title": "Previous color customizations",
|
|
||||||
"description": "Keeps in cache your previous color customizations."
|
|
||||||
},
|
|
||||||
"materialTheme.cache.workbench.settings": {
|
"materialTheme.cache.workbench.settings": {
|
||||||
"default": {},
|
"default": {},
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"title": "Custom material theme settings",
|
"title": "Custom material theme settings",
|
||||||
"description": "Keeps in cache your previous color customizations."
|
"description": "Material theme settings object."
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
File diff suppressed because one or more lines are too long
Loading…
Reference in a new issue