chore: Moves accents colours to defaults.json. Adds a reload window confirm message, this due to bugs.

This commit is contained in:
OctoD 2017-06-23 13:55:52 +02:00
parent 36826d2e2f
commit a412e4edde
14 changed files with 116 additions and 129 deletions

View file

@ -1,10 +1,8 @@
interface IIconObject {
iconPath: string
}
import { IThemeIconsItem } from "./itheme-icons-item";
export interface IThemeIconsAccents {
iconDefinitions: {
_folder_open: IIconObject;
_folder_open_build: IIconObject;
_folder_open: IThemeIconsItem;
_folder_open_build: IThemeIconsItem;
}
}

View file

@ -0,0 +1,3 @@
export interface IThemeIconsItem {
iconPath: string;
}

View file

@ -1,12 +1,10 @@
export interface IThemeIconsVariantsItem {
iconPath: string;
}
import { IThemeIconsItem } from "./itheme-icons-item";
export interface IThemeIconsVariants {
iconDefinitions: {
"_folder_dark": IThemeIconsVariantsItem;
"_folder_dark-build": IThemeIconsVariantsItem;
"_file_folder": IThemeIconsVariantsItem;
"_file_folder-build": IThemeIconsVariantsItem;
"_folder_dark": IThemeIconsItem;
"_folder_dark-build": IThemeIconsItem;
"_file_folder": IThemeIconsItem;
"_file_folder-build": IThemeIconsItem;
}
}

View file

@ -6,7 +6,7 @@ import * as path from 'path';
import { MESSAGE_GENERATED, MESSAGE_ICON_ACCENTS_ERROR } from "../consts/log";
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 PATHS from '../../extensions/consts/paths'
@ -14,7 +14,7 @@ import PATHS from '../../extensions/consts/paths'
// import { writePackageJSON } from "../helpers/contribute-icon-theme";
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_ICON_THEME: IPackageJSONThemeIcons = {
@ -79,7 +79,7 @@ function replaceWhiteSpaces(input: string): string {
*/
function writeSVGIcon(fromFile: string, toFile: string, accent: string): void {
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);
fs.writeFileSync(toFile, content);
@ -94,7 +94,7 @@ export default gulp.task('build:icons.accents', cb => {
try {
basetheme = require(BASE_ICON_THEME_PATH);
Object.keys(THEME_COMMONS.accents).forEach(key => {
Object.keys(DEFAULTS.accents).forEach(key => {
let iconName = replaceWhiteSpaces(key);
let themecopy: IThemeIconsAccents = JSON.parse(JSON.stringify(basetheme));
let themePath: string = path.join(PATHS.THEMES, `./Material-Theme-Icons-${ key }.json`);

View file

@ -7,8 +7,8 @@ import * as path from 'path';
import { HR, MESSAGE_GENERATED, MESSAGE_ICON_ERROR } from './../consts/log';
import { CHARSET } from "../../extensions/consts/files";
import { IGenericObject } from "../../extensions/interfaces/igeneric-object";
import { IIcon } from './../interfaces/iicon';
import { IPlainObject } from '../interfaces/iplain-object';
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 icons: IIcon[] = fileNames.map(fileName => iconFactory(fileName));
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';
icons[icons.length - 1].last = true;

View file

@ -7,10 +7,11 @@ import * as path from 'path';
import { HR, MESSAGE_GENERATED, MESSAGE_THEME_VARIANT_PARSE_ERROR } from './../consts/log';
import { CHARSET } from "../../extensions/consts/files";
import { IDefaults } from "../../extensions/interfaces/idefaults";
import { IThemeVariant } from './../interfaces/itheme-variant';
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 themeVariants: IThemeVariant[] = [];

View file

@ -1,16 +1,13 @@
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 { IDefaults } from "../../interfaces/idefaults";
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;
let themeConfigCommon: IThemeConfigCommons = require('./commons.json');
let themeConfigCommon: IDefaults = require('../../defaults.json');
let accentsProperties: IGenericObject<IAccentCustomProperty> = {
"activityBarBadge.background": {
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
* @param {(string | null | undefined)} colour
@ -123,9 +84,12 @@ function isValidColour(colour: string | null | undefined): boolean {
* @param {string} accentSelected
* @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.window.showInformationMessage(`${ accentSelected } set`);
// let message: string = accentSelected !== undefined ? `${ accentSelected } set` : `Accents removed`;
updateAccent(accentSelected);
// vscode.window.showInformationMessage(message).then(() => {
// });
}, reason => {
vscode.window.showErrorMessage(reason);
});
@ -164,13 +128,12 @@ export const THEME_ACCENTS_SETTER = () => {
// break;
case purgeColourKey:
assignColorCustomizations(undefined, config);
setWorkbenchOptions(accentSelected, config);
assignIconTheme(undefined);
setWorkbenchOptions(undefined, config);
break;
default:
assignColorCustomizations(themeConfigCommon.accents[accentSelected], config);
setWorkbenchOptions(accentSelected, config);
assignIconTheme(accentSelected);
// assignIconTheme(accentSelected);
break;
}
});

View file

@ -3,50 +3,51 @@ import * as vscode from 'vscode';
import { getAbsolutePath, getDefaultValues, getThemeIconsByContributeID, getThemeIconsContribute } from "../../helpers/fs";
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 { IPackageJSONThemeIcons } from "../../interfaces/ipackage.json";
import { IThemeIcons } from "../../interfaces/itheme-icons";
import { assignIconTheme } from "../accents-setter/index";
export const THEME_CHANGE_LISTENER = () => {
vscode.workspace.onDidChangeConfiguration(() => {
let cacheKey: string = 'materialTheme.cache.workbench.accent';
let cache = vscode.workspace.getConfiguration().get<any>(cacheKey);
let themeID: string = getCurrentThemeID();
let themeIconsID: string = getCurrentThemeIconsID();
if (themeIconsID && /material-theme/i.test(themeIconsID)) {
let customSettings = getCustomSettings();
let defaults = getDefaultValues();
let accentName = customSettings.accent;
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);
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._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`);
if (!!cache && cache.globalValue) {
assignIconTheme(cacheKey);
}
updateSettingsTheme(themeID);
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();
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);
});
}
});
}

View file

@ -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": {
"theme": {
"iconDefinitions": {

View file

@ -1,5 +1,6 @@
import * as vscode from 'vscode';
import { IDefaults } from "../interfaces/idefaults";
import { IThemeCustomProperties } from "../interfaces/itheme-custom-properties";
import { getPackageJSON } from "./fs";
@ -8,8 +9,8 @@ import { getPackageJSON } from "./fs";
* @export
* @returns {(string | null)}
*/
export function getAccent(): string | null {
return vscode.workspace.getConfiguration().get<string>('materialTheme.cache.workbench.accent', null);
export function getAccent(): string | undefined {
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
* @param {string} accentName
* @returns {boolean}
*/
export function hasAccentChanged(accentName: string): boolean {
return accentName !== getAccent();
export function isAccent(accentName: string, defaults: IDefaults): boolean {
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
* @param {string} settingname
* @param {*} value
*/
export function setCustomSetting(settingname: string, value: any): void {
export function setCustomSetting(settingname: string, value: any): Thenable<void> {
let settings: any = getCustomSettings();
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();
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
* @param {string} accentName
*/
export function updateAccent(accentName: string): void {
vscode.workspace.getConfiguration().update('materialTheme.cache.workbench.accent', accentName, true);
}
export function updateAccent(accentName: string): Thenable<void> {
let config: IThemeCustomProperties = {};
let prevaccent = getAccent();
/**
* Updates theme name to custom settings
* @export
* @param {string} themeName
*/
export function updateSettingsTheme(themeName: string): void {
setCustomSetting('themeColours', themeName);
}
if (prevaccent !== undefined && prevaccent !== accentName) {
config.accentPrevious = prevaccent;
} else if (accentName === undefined) {
config.accentPrevious = undefined;
}
/**
* Updates icons theme name to custom settings
* @export
* @param {string} themeName
*/
export function updateSettingsThemeIcons(themeName: string): void {
setCustomSetting('themeIcons', themeName);
config.accent = accentName;
return setCustomSettings(config);
}

View file

@ -1,8 +1,14 @@
export interface IDefaults {
accents: IAccents;
icons: IDefaultsThemeIcons;
themeVariants: IDefaultsThemeVariant;
}
export interface IAccents {
teal: string;
[index: string]: string;
}
export interface IDefaultsThemeIcons {
theme: {
iconDefinitions: {

View file

@ -1,4 +1,6 @@
export interface IThemeCustomProperties {
accent?: string;
accentPrevious?: string;
themeColours?: string;
themeIcons?: string;
}

View file

@ -54,23 +54,11 @@
],
"configuration": {
"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": {
"default": {},
"type": "object",
"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