From c648ab878a6e5d95743dcbdd7a3c8866c45d6860 Mon Sep 17 00:00:00 2001 From: OctoD Date: Mon, 29 May 2017 18:01:55 +0200 Subject: [PATCH] feat: adds theme accents config. --- .gulp/tasks/themes.ts | 2 +- extensions/accents-setter/commons.json | 20 ++++++ extensions/accents-setter/index.ts | 76 ++++++++++++++++++++++ extensions/interfaces/iaccents.ts | 4 ++ extensions/interfaces/icommons.ts | 5 ++ extensions/material.theme.config.ts | 12 ++-- src/themes/settings/commons.json | 5 -- src/themes/theme-template-color-theme.json | 12 ++-- 8 files changed, 116 insertions(+), 20 deletions(-) create mode 100644 extensions/accents-setter/commons.json create mode 100644 extensions/accents-setter/index.ts create mode 100644 extensions/interfaces/iaccents.ts create mode 100644 extensions/interfaces/icommons.ts delete mode 100644 src/themes/settings/commons.json diff --git a/.gulp/tasks/themes.ts b/.gulp/tasks/themes.ts index 09b9979..a934af9 100644 --- a/.gulp/tasks/themes.ts +++ b/.gulp/tasks/themes.ts @@ -10,7 +10,7 @@ import { CHARSET } from '../consts/files'; import { IThemeVariant } from './../interfaces/itheme-variant'; import paths from '../consts/paths'; -let commons = require('../../src/themes/settings/commons.json'); +let commons = require('../../extensions/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/accents-setter/commons.json new file mode 100644 index 0000000..7d97aad --- /dev/null +++ b/extensions/accents-setter/commons.json @@ -0,0 +1,20 @@ +{ + "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" + } +} diff --git a/extensions/accents-setter/index.ts b/extensions/accents-setter/index.ts new file mode 100644 index 0000000..3e14b4c --- /dev/null +++ b/extensions/accents-setter/index.ts @@ -0,0 +1,76 @@ +import * as vscode from 'vscode'; + +import { IGenericObject } from "../interfaces/igeneric-object"; +import { IThemeConfigCommons } from "../interfaces/icommons"; + +let themeConfigCommon: IThemeConfigCommons = require('./commons.json'); +let accentsProperties: IGenericObject = { + "activityBarBadge.background": undefined, + "list.activeSelectionForeground": undefined, + "list.inactiveSelectionForeground": undefined, + "list.highlightForeground": undefined, + "scrollbarSlider.activeBackground": undefined, + "editorSuggestWidget.highlightForeground": undefined, +} + +/** + * Assigns colours + * @param {string} colour + * @param {*} config + */ +function assignColorCustomizations(colour: string, config: any): void { + Object.keys(accentsProperties).forEach(propertyName => { + config[propertyName] = colour; + }); +} + +/** + * Sets workbench options + * @param {string} accentSelected + * @param {*} config + */ +function setWorkbenchOptions(accentSelected: string, config: any): void { + vscode.workspace.getConfiguration().update('workbench.colorCustomizations', config, true).then(() => { + vscode.window.showInformationMessage(`${ accentSelected } set`); + }, reason => { + vscode.window.showErrorMessage(reason); + }); +} + +/** + * VSCode command + */ +export const THEME_ACCENTS_SETTER = () => { + // shows the quick pick dropdown + let options: string[] = Object.keys(themeConfigCommon.accents); + let customColourKey: string = 'Custom colour'; + let purgeColourKey: string = 'Remove accents'; + + options.push(customColourKey); + options.push(purgeColourKey); + + vscode.window.showQuickPick(options).then(accentSelected => { + if (accentSelected === null || accentSelected === undefined) return; + + let config: any = vscode.workspace.getConfiguration().get('workbench.colorCustomizations'); + + switch(accentSelected) { + case customColourKey: + vscode.window.showInputBox().then(colourCode => { + if (colourCode === null || colourCode === undefined) return; + + assignColorCustomizations(colourCode, config); + setWorkbenchOptions(accentSelected, config); + }); + break; + case purgeColourKey: + assignColorCustomizations(undefined, config); + setWorkbenchOptions(accentSelected, config); + break; + default: + assignColorCustomizations(themeConfigCommon.accents[accentSelected], config); + setWorkbenchOptions(accentSelected, config); + break; + } + }); +} \ No newline at end of file diff --git a/extensions/interfaces/iaccents.ts b/extensions/interfaces/iaccents.ts new file mode 100644 index 0000000..633ff3d --- /dev/null +++ b/extensions/interfaces/iaccents.ts @@ -0,0 +1,4 @@ +export interface IAccents { + teal: string; + [index: string]: string; +} \ No newline at end of file diff --git a/extensions/interfaces/icommons.ts b/extensions/interfaces/icommons.ts new file mode 100644 index 0000000..4f2237a --- /dev/null +++ b/extensions/interfaces/icommons.ts @@ -0,0 +1,5 @@ +import { IAccents } from "./iaccents"; + +export interface IThemeConfigCommons { + accents: IAccents; +} \ No newline at end of file diff --git a/extensions/material.theme.config.ts b/extensions/material.theme.config.ts index 4e53126..484d090 100644 --- a/extensions/material.theme.config.ts +++ b/extensions/material.theme.config.ts @@ -1,7 +1,7 @@ import * as vscode from 'vscode'; -import { COMMAND_THEME_SETTER } from "./theme-setter/index"; import { IGenericObject } from "./interfaces/igeneric-object"; +import { THEME_ACCENTS_SETTER } from "./accents-setter/index"; enum Commands { ACCENTS, @@ -9,8 +9,7 @@ enum Commands { } const OPTIONS: IGenericObject = { - 'Change accents': Commands.ACCENTS, - 'Change color scheme': Commands.COLOR_THEME + 'Change accents': Commands.ACCENTS } export function activate(context: vscode.ExtensionContext) { @@ -20,11 +19,8 @@ export function activate(context: vscode.ExtensionContext) { vscode.window.showQuickPick(Object.keys(OPTIONS)).then(response => { // switching selected option switch(OPTIONS[response]) { - // case Commands.ACCENTS: - - // break; - case Commands.COLOR_THEME: - COMMAND_THEME_SETTER(); + case Commands.ACCENTS: + THEME_ACCENTS_SETTER(); break; } }); diff --git a/src/themes/settings/commons.json b/src/themes/settings/commons.json deleted file mode 100644 index b898b66..0000000 --- a/src/themes/settings/commons.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "accents": { - "teal": "#80CBC4" - } -} \ No newline at end of file diff --git a/src/themes/theme-template-color-theme.json b/src/themes/theme-template-color-theme.json index 3524d9a..39adcaa 100644 --- a/src/themes/theme-template-color-theme.json +++ b/src/themes/theme-template-color-theme.json @@ -704,7 +704,7 @@ "statusBar.foreground": "{{variant.scheme.statusbarForeground}}", "activityBar.background": "{{variant.scheme.background}}", "activityBar.foreground": "{{variant.scheme.foreground}}", - "activityBarBadge.background": "{{commons.accents.teal}}", + "activityBarBadge.background": "{{commons.accents.Teal}}", "activityBarBadge.foreground": "{{variant.scheme.base.black}}", "titleBar.activeBackground": "{{variant.scheme.background}}", "titleBar.activeForeground": "{{variant.scheme.comments}}", @@ -726,12 +726,12 @@ "list.hoverForeground": "{{variant.scheme.listHoverForeground}}", "list.hoverBackground": "{{variant.scheme.background}}", "list.activeSelectionBackground": "{{variant.scheme.background}}", - "list.activeSelectionForeground": "{{commons.accents.teal}}", - "list.inactiveSelectionForeground": "{{commons.accents.teal}}", + "list.activeSelectionForeground": "{{commons.accents.Teal}}", + "list.inactiveSelectionForeground": "{{commons.accents.Teal}}", "list.inactiveSelectionBackground": "{{variant.scheme.background}}", "list.focusBackground": "{{variant.scheme.foreground}}10", "list.focusForeground": "{{variant.scheme.foreground}}", - "list.highlightForeground": "{{commons.accents.teal}}", + "list.highlightForeground": "{{commons.accents.Teal}}", "terminal.ansiWhite": "{{variant.scheme.base.white}}", "terminal.ansiBlack": "{{variant.scheme.comments}}", "terminal.ansiBlue": "{{variant.scheme.base.blue}}", @@ -750,10 +750,10 @@ "terminal.ansiBrightYellow": "{{variant.scheme.base.yellow}}", "scrollbarSlider.background": "{{variant.scheme.scrollbars}}", "scrollbarSlider.hoverBackground": "{{variant.scheme.scrollbarsHover}}", - "scrollbarSlider.activeBackground": "{{commons.accents.teal}}50", + "scrollbarSlider.activeBackground": "{{commons.accents.Teal}}50", "editorSuggestWidget.background": "{{variant.scheme.background}}", "editorSuggestWidget.foreground": "{{variant.scheme.foreground}}", - "editorSuggestWidget.highlightForeground": "{{commons.accents.teal}}", + "editorSuggestWidget.highlightForeground": "{{commons.accents.Teal}}", "editorSuggestWidget.selectedBackground": "{{variant.scheme.lineHighlight}}50", "editorSuggestWidget.border": "{{variant.scheme.inputBorder}}",