From c2a4ba12ac5c9df6678e0a1569802c0ab6c7edf3 Mon Sep 17 00:00:00 2001 From: OctoD Date: Sat, 17 Jun 2017 16:52:27 +0200 Subject: [PATCH] chore: Alters programmatically the current theme (colour, icons) to adapt it to accents and folders colours. --- .gulp/helpers/contribute-icon-theme.ts | 46 -- .gulp/tasks/icons-accents.ts | 37 +- .gulp/tasks/icons-variants.ts | 17 +- .gulp/tasks/icons.ts | 2 +- .gulp/tasks/themes.ts | 4 +- .../accents-setter/commons.json | 0 .../{ => commands}/accents-setter/index.ts | 70 +-- extensions/commands/theme-icons/index.ts | 50 ++ {.gulp => extensions}/consts/files.ts | 0 extensions/consts/paths.ts | 5 +- extensions/defaults.json | 29 + extensions/helpers/fs.ts | 80 +++ extensions/helpers/vscode.ts | 27 + extensions/interfaces/idefaults.ts | 33 ++ .../interfaces/ipackage.json.ts | 0 extensions/interfaces/ipaths.ts | 6 + extensions/interfaces/itheme-icons.ts | 513 ++++++++++++++++++ extensions/material.theme.config.ts | 6 +- package.json | 96 +--- 19 files changed, 815 insertions(+), 206 deletions(-) delete mode 100644 .gulp/helpers/contribute-icon-theme.ts rename extensions/{ => commands}/accents-setter/commons.json (100%) rename extensions/{ => commands}/accents-setter/index.ts (61%) create mode 100644 extensions/commands/theme-icons/index.ts rename {.gulp => extensions}/consts/files.ts (100%) create mode 100644 extensions/defaults.json create mode 100644 extensions/helpers/fs.ts create mode 100644 extensions/helpers/vscode.ts create mode 100644 extensions/interfaces/idefaults.ts rename {.gulp => extensions}/interfaces/ipackage.json.ts (100%) create mode 100644 extensions/interfaces/itheme-icons.ts diff --git a/.gulp/helpers/contribute-icon-theme.ts b/.gulp/helpers/contribute-icon-theme.ts deleted file mode 100644 index 6982fb8..0000000 --- a/.gulp/helpers/contribute-icon-theme.ts +++ /dev/null @@ -1,46 +0,0 @@ -import * as fs from 'fs' -import * as path from 'path' - -import { IPackageJSON, IPackageJSONThemeIcons } from "../interfaces/ipackage.json"; - -import { CHARSET } from "../consts/files"; - -/** - * @export - * @param {string} id - * @param {string} label - * @param {string} path - * @param {IPackageJSON} topackage - * @returns {IPackageJSON} - */ -export function addContributeIconTheme(id: string, label: string, path: string, topackage: IPackageJSON): IPackageJSON { - let contribute: IPackageJSONThemeIcons = { id, label, path }; - - if (id === null || id === undefined) { - throw new TypeError(`addContributeIconTheme: variable id must be a string, got ${ Object.prototype.toString.call(id) }`); - } - - if (label === null || label === undefined) { - throw new TypeError(`addContributeIconTheme: variable label must be a string, got ${ Object.prototype.toString.call(label) }`); - } - - if (path === null || path === undefined) { - throw new TypeError(`addContributeIconTheme: variable path must be a string, got ${ Object.prototype.toString.call(path) }`); - } - - if (topackage === null || topackage === undefined) { - throw new TypeError(`addContributeIconTheme: variable topackage must be a string, got ${ Object.prototype.toString.call(topackage) }`); - } - - topackage.contributes.iconThemes.push(contribute); - - return topackage; -} - -/** - * @export - * @param {IPackageJSON} packageJSON - */ -export function writePackageJSON(packageJSON: IPackageJSON): void { - fs.writeFileSync(path.join(process.cwd(), './package.json'), JSON.stringify(packageJSON, null, 2), CHARSET); -} \ No newline at end of file diff --git a/.gulp/tasks/icons-accents.ts b/.gulp/tasks/icons-accents.ts index 07cb42b..3500b62 100644 --- a/.gulp/tasks/icons-accents.ts +++ b/.gulp/tasks/icons-accents.ts @@ -3,24 +3,25 @@ import * as gulp from 'gulp'; import * as gutil from 'gulp-util'; import * as path from 'path'; -import { IPackageJSON, IPackageJSONThemeIcons } from "../interfaces/ipackage.json"; import { MESSAGE_GENERATED, MESSAGE_ICON_ACCENTS_ERROR } from "../consts/log"; -import { addContributeIconTheme, writePackageJSON } from "../helpers/contribute-icon-theme"; -import { CHARSET } from "../consts/files"; +import { CHARSET } from "../../extensions/consts/files"; import { IThemeConfigCommons } from '../../extensions/interfaces/icommons'; import { IThemeIconsAccents } from "../interfaces/itheme-icons-accents"; import PATHS from '../../extensions/consts/paths' -const BASE_ICON_THEME_PATH: string = path.join(process.cwd(), PATHS.THEMES, './Material-Theme-Icons.json'); -const THEME_COMMONS: IThemeConfigCommons = require('../../extensions/accents-setter/commons.json'); -const PACKAGE_JSON: IPackageJSON = require('../../package.json'); +// import { IPackageJSON } from "../../extensions/interfaces/ipackage.json"; +// import { writePackageJSON } from "../helpers/contribute-icon-theme"; -const PACKAGE_JSON_ICON_THEME: IPackageJSONThemeIcons = { - id: "material-theme-icons", - label: "Material Theme Icons", - path: "./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 PACKAGE_JSON: IPackageJSON = require('../../package.json'); + +// const PACKAGE_JSON_ICON_THEME: IPackageJSONThemeIcons = { +// id: "material-theme-icons", +// label: "Material Theme Icons", +// path: "./themes/Material-Theme-Icons.json" +// } /** * Normalizes icon path @@ -88,7 +89,7 @@ function writeSVGIcon(fromFile: string, toFile: string, accent: string): void { export default gulp.task('build:icons.accents', cb => { let basetheme: IThemeIconsAccents; - PACKAGE_JSON.contributes.iconThemes = [ PACKAGE_JSON_ICON_THEME ]; + // PACKAGE_JSON.contributes.iconThemes = [ PACKAGE_JSON_ICON_THEME ]; try { basetheme = require(BASE_ICON_THEME_PATH); @@ -98,9 +99,9 @@ export default gulp.task('build:icons.accents', cb => { let themecopy: IThemeIconsAccents = JSON.parse(JSON.stringify(basetheme)); let themePath: string = path.join(PATHS.THEMES, `./Material-Theme-Icons-${ key }.json`); - let id: string = `${ PACKAGE_JSON_ICON_THEME.id }-${ key.replace(/\s+/g, '-').toLowerCase() }`; - let label: string = `${ PACKAGE_JSON_ICON_THEME.label } - ${ key } accent`; - let themepathJSON: string = `./${ themePath }`; + // let id: string = `${ PACKAGE_JSON_ICON_THEME.id }-${ key.replace(/\s+/g, '-').toLowerCase() }`; + // let label: string = `${ PACKAGE_JSON_ICON_THEME.label } - ${ key } accent`; + // let themepathJSON: string = `./${ themePath }`; themecopy.iconDefinitions._folder_open.iconPath = replaceNameWithAccent(basetheme.iconDefinitions._folder_open.iconPath, iconName); themecopy.iconDefinitions._folder_open_build.iconPath = replaceNameWithAccent(basetheme.iconDefinitions._folder_open_build.iconPath, iconName); @@ -108,14 +109,14 @@ export default gulp.task('build:icons.accents', cb => { writeSVGIcon(basetheme.iconDefinitions._folder_open.iconPath, themecopy.iconDefinitions._folder_open.iconPath, key); writeSVGIcon(basetheme.iconDefinitions._folder_open_build.iconPath, themecopy.iconDefinitions._folder_open_build.iconPath, key); - fs.writeFileSync(themePath, JSON.stringify(themecopy)); + // fs.writeFileSync(themePath, JSON.stringify(themecopy)); - addContributeIconTheme(id, label, themepathJSON, PACKAGE_JSON); + // addContributeIconTheme(id, label, themepathJSON, PACKAGE_JSON); gutil.log(gutil.colors.green(MESSAGE_GENERATED, themePath)); }); - writePackageJSON(PACKAGE_JSON); + // writePackageJSON(PACKAGE_JSON); } catch (error) { // http://ragefaces.memesoftware.com/faces/large/misc-le-fu-l.png diff --git a/.gulp/tasks/icons-variants.ts b/.gulp/tasks/icons-variants.ts index d867c23..32ddc88 100644 --- a/.gulp/tasks/icons-variants.ts +++ b/.gulp/tasks/icons-variants.ts @@ -2,11 +2,9 @@ import * as fs from 'fs'; import * as gulp from 'gulp'; import * as path from 'path'; -import { addContributeIconTheme, writePackageJSON } from "../helpers/contribute-icon-theme"; - -import { CHARSET } from "../consts/files"; +import { CHARSET } from "../../extensions/consts/files"; import { IGenericObject } from "../../extensions/interfaces/igeneric-object"; -import { IPackageJSON } from "../interfaces/ipackage.json"; +import { IPackageJSON } from "../../extensions/interfaces/ipackage.json"; import { IThemeIconsVariants } from "../interfaces/itheme-icons-variants"; import PATHS from '../../extensions/consts/paths' @@ -38,29 +36,18 @@ export default gulp.task('build:icons.variants', callback => { let basepath: string = path.join(process.cwd(), contribute.path); let basetheme: IThemeIconsVariants = require(basepath); - let themepath: string = path.join(process.cwd(), contribute.path.replace('.json', `.${ variantName }.json`)); let theme: IThemeIconsVariants = JSON.parse(JSON.stringify(basetheme)); - let contributeID: string = `${ contribute.id }-${ variantName.toLowerCase() }`; - let contributeLabel: string = `${ contribute.label } - ${ variantName }` - let contributePath: string = path.relative(process.cwd(), themepath); - theme.iconDefinitions._folder_dark.iconPath = theme.iconDefinitions._folder_dark.iconPath.replace('.svg', `${ variantName }.svg`); theme.iconDefinitions._file_folder.iconPath = theme.iconDefinitions._file_folder.iconPath.replace('.svg', `${ variantName }.svg`); theme.iconDefinitions["_file_folder-build"].iconPath = theme.iconDefinitions["_file_folder-build"].iconPath.replace('.svg', `${ variantName }.svg`); - fs.writeFileSync(themepath, JSON.stringify(theme), CHARSET); - writeIconVariant(basetheme.iconDefinitions._folder_dark.iconPath, theme.iconDefinitions._folder_dark.iconPath, variants[variantName]); writeIconVariant(basetheme.iconDefinitions._file_folder.iconPath, theme.iconDefinitions._file_folder.iconPath, variants[variantName]); writeIconVariant(basetheme.iconDefinitions["_file_folder-build"].iconPath, theme.iconDefinitions["_file_folder-build"].iconPath, variants[variantName]); - - addContributeIconTheme(contributeID, contributeLabel, contributePath, PACKAGE_JSON); }); }); - writePackageJSON(PACKAGE_JSON); - } catch (error) { callback(error); return; diff --git a/.gulp/tasks/icons.ts b/.gulp/tasks/icons.ts index 63c6460..7bd6e59 100644 --- a/.gulp/tasks/icons.ts +++ b/.gulp/tasks/icons.ts @@ -6,7 +6,7 @@ import * as path from 'path'; import { HR, MESSAGE_GENERATED, MESSAGE_ICON_ERROR } from './../consts/log'; -import { CHARSET } from '../consts/files'; +import { CHARSET } from "../../extensions/consts/files"; import { IIcon } from './../interfaces/iicon'; import { IPlainObject } from '../interfaces/iplain-object'; import paths from '../../extensions/consts/paths'; diff --git a/.gulp/tasks/themes.ts b/.gulp/tasks/themes.ts index d58c5e3..9b062d7 100644 --- a/.gulp/tasks/themes.ts +++ b/.gulp/tasks/themes.ts @@ -6,11 +6,11 @@ import * as path from 'path'; import { HR, MESSAGE_GENERATED, MESSAGE_THEME_VARIANT_PARSE_ERROR } from './../consts/log'; -import { CHARSET } from '../consts/files'; +import { CHARSET } from "../../extensions/consts/files"; import { IThemeVariant } from './../interfaces/itheme-variant'; import paths from '../../extensions/consts/paths'; -let commons = require('../../extensions/accents-setter/commons.json'); +let commons = require('../../extensions/commands/accents-setter/commons.json'); let themeTemplateFileContent: string = fs.readFileSync(path.join(paths.SRC, `/themes/theme-template-color-theme.json`), CHARSET); let themeVariants: IThemeVariant[] = []; diff --git a/extensions/accents-setter/commons.json b/extensions/commands/accents-setter/commons.json similarity index 100% rename from extensions/accents-setter/commons.json rename to extensions/commands/accents-setter/commons.json diff --git a/extensions/accents-setter/index.ts b/extensions/commands/accents-setter/index.ts similarity index 61% rename from extensions/accents-setter/index.ts rename to extensions/commands/accents-setter/index.ts index bc9d667..35eb420 100644 --- a/extensions/accents-setter/index.ts +++ b/extensions/commands/accents-setter/index.ts @@ -1,8 +1,11 @@ import * as vscode from 'vscode'; -import { IAccentCustomProperty } from "../interfaces/iaccent-custom-property"; -import { IGenericObject } from "../interfaces/igeneric-object"; -import { IThemeConfigCommons } from "../interfaces/icommons"; +import { getCurrentThemeID, getCurrentThemeIconsID, reloadWindow } from "../../helpers/vscode"; +import { getDefaultValues, getPackageJSON, getThemeIconsByContributeID, getThemeIconsContribute, writeFile } from "../../helpers/fs"; + +import {IAccentCustomProperty} from '../../interfaces/iaccent-custom-property'; +import {IGenericObject} from '../../interfaces/igeneric-object'; +import {IThemeConfigCommons} from '../../interfaces/icommons'; const REGEXP_HEX: RegExp = /^#([0-9A-F]{6}|[0-9A-F]{8})$/i; @@ -62,45 +65,44 @@ function assignColorCustomizations(colour: string, config: any): void { }); } -/** - * Gets the accented icon theme name - * @param accentName - */ -function accentedThemeName(accentName: string): string { - return `material-theme-icons-${ accentName.replace(/\s+/g, '-').toLowerCase() }`; -} - /** * Assigns related icons theme name by accent name * @param accentName */ -function assignIconTheme(accentName: string | undefined): void { - let accentValue: string; - let cacheKey: string = 'materialTheme.cache.workbench.iconTheme'; - let cache: any = vscode.workspace.getConfiguration().inspect(cacheKey); - let currentTheme: any = vscode.workspace.getConfiguration().inspect('workbench.colorTheme'); - let materialThemeName: string = 'Material Theme'; +export function assignIconTheme(accentName: string | undefined): void { + // let accentValue: string; + let cacheKey: string = 'materialTheme.cache.workbench.accent'; + let themeIconsID: string = getCurrentThemeIconsID(); + let themeID: string = getCurrentThemeID(); + let packageJSON = getPackageJSON(); - if (!cache.globalValue && accentName !== undefined) { - vscode.workspace.getConfiguration().update(cacheKey, vscode.workspace.getConfiguration().get('workbench.iconTheme'), true).then(() => {}, reason => vscode.window.showErrorMessage(reason)); - } + if (packageJSON.contributes.iconThemes.filter(contribute => contribute.id === themeIconsID).length > 0) { + let defaults = getDefaultValues(); + let theme = getThemeIconsByContributeID(themeIconsID); + let themeContribute = getThemeIconsContribute(themeIconsID); - if (accentName === undefined && cache.globalValue) { - accentValue = vscode.workspace.getConfiguration().get(cacheKey); - vscode.workspace.getConfiguration().update(cacheKey, undefined, true); - } else if (accentName !== undefined) { - accentValue = accentedThemeName(accentName); - - if (!!currentTheme.globalValue && currentTheme.globalValue.indexOf(materialThemeName) >= 0) { - let variantName: string | undefined = currentTheme.globalValue.split(materialThemeName)[1]; - - accentValue = `${ accentValue }-${ !!variantName ? variantName.trim().toLowerCase() : 'default' }`; + 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; } - } - vscode.workspace.getConfiguration().update('workbench.iconTheme', accentValue, true).then(() => {}, reason => { - vscode.window.showErrorMessage(reason); - }); + writeFile(themeContribute.path, JSON.stringify(theme)); + + vscode.workspace.getConfiguration().update(cacheKey, accentName, true); + + vscode.workspace.getConfiguration().update('workbench.iconTheme', themeIconsID, true).then(() => { + // In order to load modified icons we will have to reload the whole window. + if (packageJSON.contributes.themes.filter(theme => theme.label === themeID).length > 0 && packageJSON.contributes.iconThemes.filter(theme => theme.id === themeIconsID).length > 0) { + reloadWindow(); + } + }); + } else { + vscode.workspace.getConfiguration().update(cacheKey, accentName, true); + } } /** diff --git a/extensions/commands/theme-icons/index.ts b/extensions/commands/theme-icons/index.ts new file mode 100644 index 0000000..428b98f --- /dev/null +++ b/extensions/commands/theme-icons/index.ts @@ -0,0 +1,50 @@ +import * as fs from 'fs'; +import * as vscode from 'vscode'; + +import { getAbsolutePath, getDefaultValues, getPackageJSON, getThemeIconsByContributeID, getThemeIconsContribute } from "../../helpers/fs"; +import { getCurrentThemeID, getCurrentThemeIconsID, reloadWindow } from "../../helpers/vscode"; + +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(cacheKey); + let themeID: string = getCurrentThemeID(); + let themeIconsID: string = getCurrentThemeIconsID(); + + if (themeIconsID && /material-theme/i.test(themeIconsID)) { + let defaults = getDefaultValues(); + let packageJSON = getPackageJSON(); + 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); + + 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); + } + + 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 (packageJSON.contributes.themes.filter(theme => theme.label === themeID).length > 0 && packageJSON.contributes.iconThemes.filter(theme => theme.id ===themeIconsID).length > 0) { + reloadWindow(); + } + }); + } + }); +} \ No newline at end of file diff --git a/.gulp/consts/files.ts b/extensions/consts/files.ts similarity index 100% rename from .gulp/consts/files.ts rename to extensions/consts/files.ts diff --git a/extensions/consts/paths.ts b/extensions/consts/paths.ts index 1fcf397..4f673e9 100644 --- a/extensions/consts/paths.ts +++ b/extensions/consts/paths.ts @@ -1,10 +1,13 @@ +import * as path from 'path'; + import { IPaths } from '../interfaces/ipaths'; -const PATHS: IPaths = { +export const PATHS: IPaths = { DIST: './dist', ICONS: './icons', SRC: './src', THEMES: './themes', + VSIX_DIR: path.join(__dirname, '../../'), }; export default PATHS; diff --git a/extensions/defaults.json b/extensions/defaults.json new file mode 100644 index 0000000..e2a2584 --- /dev/null +++ b/extensions/defaults.json @@ -0,0 +1,29 @@ +{ + "icons": { + "theme": { + "iconDefinitions": { + "_folder_dark": { + "iconPath": "../icons/folder.svg" + }, + "_file_folder": { + "iconPath": "../icons/folder.svg" + }, + "_file_folder-build": { + "iconPath": "../icons/folder-build.svg" + }, + "_folder_open": { + "iconPath": "../icons/folder-outline.svg" + }, + "_folder_open_build": { + "iconPath": "../icons/folder-outline-build.svg" + } + } + } + }, + "themeVariants": { + "Darker": "#424242", + "Default": "#4A616C", + "Light": "#90A4AE", + "Palenight": "#4E5579" + } +} \ No newline at end of file diff --git a/extensions/helpers/fs.ts b/extensions/helpers/fs.ts new file mode 100644 index 0000000..ee422b3 --- /dev/null +++ b/extensions/helpers/fs.ts @@ -0,0 +1,80 @@ +import * as fs from 'fs' +import * as path from 'path' + +import { IPackageJSON, IPackageJSONThemeIcons } from "../interfaces/ipackage.json"; + +import { CHARSET } from "../consts/files"; +import { IDefaults } from "../interfaces/idefaults"; +import { IThemeIcons } from "../interfaces/itheme-icons"; +import { PATHS } from "../consts/paths"; + +/** + * Gets default value + * @export + * @returns {IDefaults} + */ +export function getDefaultValues(): IDefaults { + let defaults: IDefaults = require(path.join(PATHS.VSIX_DIR, './extensions/defaults.json')); + + if (defaults === undefined || defaults === null) { + throw new Error('Cannot find defaults params'); + } + + return defaults; +} + +/** + * Gets an absolute path + * + * @export + * @param {string} input + * @returns {string} + */ +export function getAbsolutePath(input: string): string { + return path.join(PATHS.VSIX_DIR, input); +} + +/** + * Gets a theme content by a given contribute ID + * + * @export + * @param {string} ID + * @returns {IThemeIcons} + */ +export function getThemeIconsByContributeID(ID: string): IThemeIcons | null { + let contribute: IPackageJSONThemeIcons = getThemeIconsContribute(ID) + return contribute !== null ? require(path.join(PATHS.VSIX_DIR, contribute.path)) : null; +} + +/** + * Gets a theme by name + * @export + * @param {string} name + * @returns {IThemeIcons} + */ +export function getThemeIconsContribute(ID: string): IPackageJSONThemeIcons { + let contributes = getPackageJSON().contributes.iconThemes.filter(contribute => contribute.id === ID); + return contributes[0] !== undefined ? contributes[0] : null; +} + +/** + * Gets package JSON + * @export + * @returns {*} + */ +export function getPackageJSON(): IPackageJSON { + let packageJSON: IPackageJSON = require(path.join(PATHS.VSIX_DIR, './package.json')); + return packageJSON; +} + +/** + * Writes a file inside the vsix directory + * @export + * @param {string} filename + * @param {string} filecontent + */ +export function writeFile(filename: string, filecontent: string): void { + filename = path.join(PATHS.VSIX_DIR, filename); + console.log(arguments) + fs.writeFileSync(filename, filecontent, CHARSET); +} \ No newline at end of file diff --git a/extensions/helpers/vscode.ts b/extensions/helpers/vscode.ts new file mode 100644 index 0000000..03d9a4a --- /dev/null +++ b/extensions/helpers/vscode.ts @@ -0,0 +1,27 @@ +import * as vscode from 'vscode' + +/** + * Gets your current theme ID + * @export + * @returns {string} + */ +export function getCurrentThemeID(): string { + return vscode.workspace.getConfiguration().get('workbench.colorTheme'); +} + +/** + * Gets your current icons theme ID + * @export + * @returns {string} + */ +export function getCurrentThemeIconsID(): string { + return vscode.workspace.getConfiguration().get('workbench.iconTheme'); +} + +/** + * Reloads current vscode window. + * @export + */ +export function reloadWindow(): void { + vscode.commands.executeCommand('workbench.action.reloadWindow'); +} \ No newline at end of file diff --git a/extensions/interfaces/idefaults.ts b/extensions/interfaces/idefaults.ts new file mode 100644 index 0000000..6a07b1b --- /dev/null +++ b/extensions/interfaces/idefaults.ts @@ -0,0 +1,33 @@ +export interface IDefaults { + icons: IDefaultsThemeIcons; + themeVariants: IDefaultsThemeVariant; +} + +export interface IDefaultsThemeIcons { + theme: { + iconDefinitions: { + _folder_open: { + iconPath: string; + } + _folder_open_build: { + iconPath: string; + } + _folder_dark: { + iconPath: string; + } + "_file_folder-build": { + iconPath: string; + } + _file_folder: { + iconPath: string; + } + } + } +} + +export interface IDefaultsThemeVariant { + Darker: string; + Default: string; + Light: string; + Palenight: string; +} \ No newline at end of file diff --git a/.gulp/interfaces/ipackage.json.ts b/extensions/interfaces/ipackage.json.ts similarity index 100% rename from .gulp/interfaces/ipackage.json.ts rename to extensions/interfaces/ipackage.json.ts diff --git a/extensions/interfaces/ipaths.ts b/extensions/interfaces/ipaths.ts index 0bb68f0..ba3d072 100644 --- a/extensions/interfaces/ipaths.ts +++ b/extensions/interfaces/ipaths.ts @@ -23,4 +23,10 @@ export interface IPaths { * @memberof IPaths */ THEMES: string; + /** + * Extension directory + * @type {string} + * @memberof IPaths + */ + VSIX_DIR: string; } \ No newline at end of file diff --git a/extensions/interfaces/itheme-icons.ts b/extensions/interfaces/itheme-icons.ts new file mode 100644 index 0000000..7e870ae --- /dev/null +++ b/extensions/interfaces/itheme-icons.ts @@ -0,0 +1,513 @@ +export interface IThemeIconsIconPath { + iconPath: string; +} + +export interface IThemeIcons { + "iconDefinitions": + { + "_folder_dark": IThemeIconsIconPath; + "_folder_dark_build": IThemeIconsIconPath; + "_folder_light": IThemeIconsIconPath; + "_folder_light_build": IThemeIconsIconPath; + "_folder_open": IThemeIconsIconPath; + "_folder_open_build": IThemeIconsIconPath; + "_file_dark": IThemeIconsIconPath; + "_file_actionscript": IThemeIconsIconPath; + "_file_ai": IThemeIconsIconPath; + "_file_android": IThemeIconsIconPath; + "_file_angular": IThemeIconsIconPath; + "_file_applescript": IThemeIconsIconPath; + "_file_arduino": IThemeIconsIconPath; + "_file_assembly": IThemeIconsIconPath; + "_file_autohotkey": IThemeIconsIconPath; + "_file_bower": IThemeIconsIconPath; + "_file_c": IThemeIconsIconPath; + "_file_certificate": IThemeIconsIconPath; + "_file_changelog": IThemeIconsIconPath; + "_file_clojure": IThemeIconsIconPath; + "_file_cmake": IThemeIconsIconPath; + "_file_cmd": IThemeIconsIconPath; + "_file_coffee": IThemeIconsIconPath; + "_file_console": IThemeIconsIconPath; + "_file_contributing": IThemeIconsIconPath; + "_file_cpp": IThemeIconsIconPath; + "_file_credits": IThemeIconsIconPath; + "_file_csharp": IThemeIconsIconPath; + "_file_css-map": IThemeIconsIconPath; + "_file_css": IThemeIconsIconPath; + "_file_dart": IThemeIconsIconPath; + "_file_database": IThemeIconsIconPath; + "_file_dlang": IThemeIconsIconPath; + "_file_docker": IThemeIconsIconPath; + "_file_document": IThemeIconsIconPath; + "_file_email": IThemeIconsIconPath; + "_file_exe": IThemeIconsIconPath; + "_file_favicon": IThemeIconsIconPath; + "_file_file": IThemeIconsIconPath; + "_file_flash": IThemeIconsIconPath; + "_file_flow": IThemeIconsIconPath; + "_file_folder-build": IThemeIconsIconPath; + "_file_folder-light-build": IThemeIconsIconPath; + "_file_folder-light": IThemeIconsIconPath; + "_file_folder-outline-build": IThemeIconsIconPath; + "_file_folder-outline": IThemeIconsIconPath; + "_file_folder": IThemeIconsIconPath; + "_file_font": IThemeIconsIconPath; + "_file_fsharp": IThemeIconsIconPath; + "_file_git": IThemeIconsIconPath; + "_file_github": IThemeIconsIconPath; + "_file_go": IThemeIconsIconPath; + "_file_gopher": IThemeIconsIconPath; + "_file_gradle": IThemeIconsIconPath; + "_file_graphql": IThemeIconsIconPath; + "_file_groovy": IThemeIconsIconPath; + "_file_grunt": IThemeIconsIconPath; + "_file_gulp": IThemeIconsIconPath; + "_file_haml": IThemeIconsIconPath; + "_file_haskell": IThemeIconsIconPath; + "_file_html": IThemeIconsIconPath; + "_file_image": IThemeIconsIconPath; + "_file_ionic": IThemeIconsIconPath; + "_file_java": IThemeIconsIconPath; + "_file_javascript-map": IThemeIconsIconPath; + "_file_js": IThemeIconsIconPath; + "_file_json": IThemeIconsIconPath; + "_file_key": IThemeIconsIconPath; + "_file_kotlin": IThemeIconsIconPath; + "_file_less": IThemeIconsIconPath; + "_file_lib": IThemeIconsIconPath; + "_file_license": IThemeIconsIconPath; + "_file_lua": IThemeIconsIconPath; + "_file_markdown": IThemeIconsIconPath; + "_file_markup": IThemeIconsIconPath; + "_file_movie": IThemeIconsIconPath; + "_file_music": IThemeIconsIconPath; + "_file_mustache": IThemeIconsIconPath; + "_file_mxml": IThemeIconsIconPath; + "_file_nodejs": IThemeIconsIconPath; + "_file_npm": IThemeIconsIconPath; + "_file_ocaml": IThemeIconsIconPath; + "_file_pdf": IThemeIconsIconPath; + "_file_php": IThemeIconsIconPath; + "_file_polymer": IThemeIconsIconPath; + "_file_postcss": IThemeIconsIconPath; + "_file_powerpoint": IThemeIconsIconPath; + "_file_pp": IThemeIconsIconPath; + "_file_procfile": IThemeIconsIconPath; + "_file_pug": IThemeIconsIconPath; + "_file_python": IThemeIconsIconPath; + "_file_r": IThemeIconsIconPath; + "_file_rails": IThemeIconsIconPath; + "_file_raml": IThemeIconsIconPath; + "_file_react": IThemeIconsIconPath; + "_file_readme": IThemeIconsIconPath; + "_file_ruby": IThemeIconsIconPath; + "_file_rust": IThemeIconsIconPath; + "_file_sass": IThemeIconsIconPath; + "_file_settings": IThemeIconsIconPath; + "_file_sketch": IThemeIconsIconPath; + "_file_star": IThemeIconsIconPath; + "_file_stylus": IThemeIconsIconPath; + "_file_sublime": IThemeIconsIconPath; + "_file_svg": IThemeIconsIconPath; + "_file_swc": IThemeIconsIconPath; + "_file_swift": IThemeIconsIconPath; + "_file_swig": IThemeIconsIconPath; + "_file_table": IThemeIconsIconPath; + "_file_tex": IThemeIconsIconPath; + "_file_todo": IThemeIconsIconPath; + "_file_tune": IThemeIconsIconPath; + "_file_twig": IThemeIconsIconPath; + "_file_typescript": IThemeIconsIconPath; + "_file_typescript_def": IThemeIconsIconPath; + "_file_url": IThemeIconsIconPath; + "_file_virtual": IThemeIconsIconPath; + "_file_visualstudio": IThemeIconsIconPath; + "_file_vue": IThemeIconsIconPath; + "_file_webpack": IThemeIconsIconPath; + "_file_word": IThemeIconsIconPath; + "_file_xaml": IThemeIconsIconPath; + "_file_xml": IThemeIconsIconPath; + "_file_yaml": IThemeIconsIconPath; + "_file_yarn": IThemeIconsIconPath; + "_file_zip": IThemeIconsIconPath; + }; + "fileExtensions": + { + "cmd": string; + "mustache": string; + "rails": string; + "styl": string; + "twig": string; + "swig": string; + "sketch": string; + "do": string; + "sublime-settings": string; + "sublime-theme": string; + "sublime-commands": string; + "sublime-menu": string; + "html": string; + "jade": string; + "pug": string; + "md": string; + "md.rendered": string; + "markdown": string; + "markdown.rendered": string; + "css": string; + "postcss": string; + "scss": string; + "sass": string; + "less": string; + "json": string; + "yaml": string; + "YAML-tmLanguage": string; + "yml": string; + "xml": string; + "plist": string; + "xsd": string; + "dtd": string; + "xsl": string; + "xslt": string; + "resx": string; + "iml": string; + "xquery": string; + "tmLanguage": string; + "png": string; + "jpeg": string; + "jpg": string; + "gif": string; + "svg": string; + "eps": string; + "ai": string; + "ico": string; + "tif": string; + "tiff": string; + "psd": string; + "psb": string; + "ami": string; + "apx": string; + "bmp": string; + "bpg": string; + "brk": string; + "cur": string; + "dds": string; + "dng": string; + "exr": string; + "fpx": string; + "gbr": string; + "img": string; + "jbig2": string; + "jb2": string; + "jng": string; + "jxr": string; + "pbm": string; + "pgf": string; + "pic": string; + "raw": string; + "webp": string; + "php": string; + "js": string; + "ejs": string; + "jsx": string; + "ini": string; + "dlc": string; + "dll": string; + "config": string; + "conf": string; + "esx": string; + "ts": string; + "tsx": string; + "d.ts": string; + "pdf": string; + "xlsx": string; + "xls": string; + "csv": string; + "vscodeignore": string; + "vsixmanifest": string; + "suo": string; + "sln": string; + "pdb": string; + "cs": string; + "csx": string; + "csproj": string; + "zip": string; + "tar": string; + "gz": string; + "xz": string; + "bzip2": string; + "gzip": string; + "7z": string; + "7zip": string; + "pzip": string; + "wim": string; + "rar": string; + "tgz": string; + "exe": string; + "msi": string; + "java": string; + "jar": string; + "jsp": string; + "c": string; + "h": string; + "m": string; + "cc": string; + "cpp": string; + "c++": string; + "hpp": string; + "mm": string; + "cxx": string; + "go": string; + "py": string; + "url": string; + "sh": string; + "bat": string; + "ps1": string; + "fish": string; + "bash": string; + "gradle": string; + "doc": string; + "docx": string; + "rtf": string; + "properties": string; + "prop": string; + "settings": string; + "sql": string; + "accdb": string; + "mdb": string; + "cer": string; + "cert": string; + "crt": string; + "pub": string; + "key": string; + "pem": string; + "asc": string; + "woff": string; + "woff2": string; + "ttf": string; + "eot": string; + "suit": string; + "otf": string; + "bmap": string; + "fnt": string; + "odttf": string; + "ttc": string; + "font": string; + "fonts": string; + "sui": string; + "ntf": string; + "mrf": string; + "lib": string; + "rb": string; + "erb": string; + "fs": string; + "fsx": string; + "fsi": string; + "fsproj": string; + "manifest": string; + "swift": string; + "ino": string; + "dockerignore": string; + "tex": string; + "bib": string; + "pptx": string; + "ppt": string; + "pptm": string; + "potx": string; + "pot": string; + "potm": string; + "ppsx": string; + "ppsm": string; + "pps": string; + "ppam": string; + "ppa": string; + "webm": string; + "mkv": string; + "flv": string; + "vob": string; + "ogv": string; + "ogg": string; + "gifv": string; + "avi": string; + "mov": string; + "qt": string; + "wmv": string; + "yuv": string; + "rm": string; + "rmvb": string; + "mp4": string; + "m4v": string; + "mpg": string; + "mp2": string; + "mpeg": string; + "mpe": string; + "mpv": string; + "m2v": string; + "vdi": string; + "vbox": string; + "vbox-prev": string; + "ics": string; + "mp3": string; + "flac": string; + "m4a": string; + "wma": string; + "aiff": string; + "coffee": string; + "txt": string; + "sqlite": string; + "graphql": string; + "gql": string; + "props": string; + "toml": string; + "rs": string; + "raml": string; + "xaml": string; + "prefs": string; + "hs": string; + "kt": string; + "project": string; + "patch": string; + "dockerfile": string; + "vb": string; + "lua": string; + "clj": string; + "groovy": string; + "r": string; + "rst": string; + "dart": string; + "as": string; + "mxml": string; + "ahk": string; + "swf": string; + "swc": string; + "cmake": string; + "asm": string; + "a51": string; + "inc": string; + "nasm": string; + "s": string; + "ms": string; + "agc": string; + "ags": string; + "aea": string; + "argus": string; + "mitigus": string; + "binsource": string; + "vue": string; + "ml": string; + "mli": string; + "cmx": string; + "js.map": string; + "css.map": string; + "tmTheme": string; + "pp": string; + "applescript": string; + "haml": string }; + "fileNames": + { "gruntfile.js": string; + "bower.json": string; + ".bowerrc": string; + "webpack.js": string; + "webpack.config.js": string; + "webpack.dev.js": string; + "webpack.prod.js": string; + "webpack.common.js": string; + "webpackfile.js": string; + "ionic.config.json": string; + ".io-config.json": string; + "gulpfile.js": string; + "gulpfile.babel.js": string; + "package.json": string; + "gradle.properties": string; + "gradlew": string; + ".jscsrc": string; + ".jshintrc": string; + ".jshintignore": string; + ".npmignore": string; + "tsconfig.json": string; + "tslint.json": string; + "androidmanifest.xml": string; + "gradle-wrapper.properties": string; + ".editorconfig": string; + "procfile": string; + ".env": string; + "dockerfile": string; + "license": string; + "license.md": string; + "license.md.rendered": string; + "license.txt": string; + ".babelrc": string; + ".eslintrc": string; + ".buildignore": string; + ".htaccess": string; + "composer.lock": string; + ".gitignore": string; + ".gitconfig": string; + ".gitattributes": string; + ".gitmodules": string; + ".gitkeep": string; + "yarn.lock": string; + ".yarnclean": string; + ".yarn-integrity": string; + "yarn-error.log": string; + "contributing.md": string; + "contributing.md.rendered": string; + "readme.md": string; + "readme.md.rendered": string; + ".mailmap": string; + "makefile": string; + "changelog": string; + "changelog.md": string; + "changelog.md.rendered": string; + "CREDITS": string; + "credits.txt": string; + "credits.md": string; + "credits.md.rendered": string; + ".flowconfig": string; + ".jsbeautifyrc": string; + "git-history": string; + "angular-cli.json": string; + "app.module.ts": string; + "favicon.ico": string }; + "file": string; + "folder": string; + "folderExpanded": string; + "languageIds": + { "git": string }; + "light": + { + "folderExpanded": string; + "folder": string; + "folderNames": + { "node_modules": string; + ".git": string; + ".github": string; + ".gulp": string; + "bower_components": string; + "build": string; + "dist": string }; + "folderNamesExpanded": + { "node_modules": string; + ".git": string; + ".github": string; + ".gulp": string; + "bower_components": string; + "build": string; + "dist": string } + }; + "folderNames": + { "node_modules": string; + ".git": string; + ".github": string; + ".gulp": string; + "bower_components": string; + "build": string; + "dist": string }; + "folderNamesExpanded": + { "node_modules": string; + ".git": string; + ".github": string; + ".gulp": string; + "bower_components": string; + "build": string; + "dist": string } +} diff --git a/extensions/material.theme.config.ts b/extensions/material.theme.config.ts index feefed0..5170c49 100644 --- a/extensions/material.theme.config.ts +++ b/extensions/material.theme.config.ts @@ -1,7 +1,8 @@ import * as vscode from 'vscode'; import { IGenericObject } from "./interfaces/igeneric-object"; -import { THEME_ACCENTS_SETTER } from "./accents-setter/index"; +import { THEME_ACCENTS_SETTER } from "./commands/accents-setter/index"; +import { THEME_CHANGE_LISTENER } from "./commands/theme-icons/index"; enum Commands { ACCENTS, @@ -25,5 +26,8 @@ export function activate(context: vscode.ExtensionContext) { } }); }); + + THEME_CHANGE_LISTENER(); + context.subscriptions.push(command); } diff --git a/package.json b/package.json index a425167..b27b40f 100644 --- a/package.json +++ b/package.json @@ -42,7 +42,7 @@ "Other" ], "activationEvents": [ - "onCommand:material.theme.config" + "*" ], "main": "./extensions/material.theme.config", "contributes": { @@ -55,17 +55,17 @@ ], "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.iconTheme": { - "default": "", - "type": "string", - "title": "Previous icon theme", - "description": "Keeps in cache your previous icon theme." } } }, @@ -93,89 +93,9 @@ ], "iconThemes": [ { - "id": "material-theme-icons", + "id": "eq-material-theme-icons", "label": "Material Theme Icons", "path": "./themes/Material-Theme-Icons.json" - }, - { - "id": "material-theme-icons-acid-lime", - "label": "Material Theme Icons - Acid Lime accent", - "path": "./themes/Material-Theme-Icons-Acid Lime.json" - }, - { - "id": "material-theme-icons-blue", - "label": "Material Theme Icons - Blue accent", - "path": "./themes/Material-Theme-Icons-Blue.json" - }, - { - "id": "material-theme-icons-breaking-bad", - "label": "Material Theme Icons - Breaking Bad accent", - "path": "./themes/Material-Theme-Icons-Breaking Bad.json" - }, - { - "id": "material-theme-icons-bright-teal", - "label": "Material Theme Icons - Bright Teal accent", - "path": "./themes/Material-Theme-Icons-Bright Teal.json" - }, - { - "id": "material-theme-icons-cyan", - "label": "Material Theme Icons - Cyan accent", - "path": "./themes/Material-Theme-Icons-Cyan.json" - }, - { - "id": "material-theme-icons-graphite", - "label": "Material Theme Icons - Graphite accent", - "path": "./themes/Material-Theme-Icons-Graphite.json" - }, - { - "id": "material-theme-icons-indigo", - "label": "Material Theme Icons - Indigo accent", - "path": "./themes/Material-Theme-Icons-Indigo.json" - }, - { - "id": "material-theme-icons-lime", - "label": "Material Theme Icons - Lime accent", - "path": "./themes/Material-Theme-Icons-Lime.json" - }, - { - "id": "material-theme-icons-orange", - "label": "Material Theme Icons - Orange accent", - "path": "./themes/Material-Theme-Icons-Orange.json" - }, - { - "id": "material-theme-icons-pink", - "label": "Material Theme Icons - Pink accent", - "path": "./themes/Material-Theme-Icons-Pink.json" - }, - { - "id": "material-theme-icons-purple", - "label": "Material Theme Icons - Purple accent", - "path": "./themes/Material-Theme-Icons-Purple.json" - }, - { - "id": "material-theme-icons-red", - "label": "Material Theme Icons - Red accent", - "path": "./themes/Material-Theme-Icons-Red.json" - }, - { - "id": "material-theme-icons-sky", - "label": "Material Theme Icons - Sky accent", - "path": "./themes/Material-Theme-Icons-Sky.json" - }, - { - "id": "material-theme-icons-tomato", - "label": "Material Theme Icons - Tomato accent", - "path": "./themes/Material-Theme-Icons-Tomato.json" - }, - { - "id": "material-theme-icons-teal", - "label": "Material Theme Icons - Teal accent", - "path": "./themes/Material-Theme-Icons-Teal.json" - }, - { - "id": "material-theme-icons-yellow", - "label": "Material Theme Icons - Yellow accent", - "path": "./themes/Material-Theme-Icons-Yellow.json" } ] },