2017-05-29 18:01:55 +02:00
|
|
|
import * as vscode from 'vscode';
|
|
|
|
|
2017-06-17 16:52:27 +02:00
|
|
|
import {IAccentCustomProperty} from '../../interfaces/iaccent-custom-property';
|
2017-06-23 13:55:52 +02:00
|
|
|
import { IDefaults } from "../../interfaces/idefaults";
|
2017-06-17 16:52:27 +02:00
|
|
|
import {IGenericObject} from '../../interfaces/igeneric-object';
|
2017-07-21 20:20:17 +02:00
|
|
|
import { updateAccent, isMaterialTheme, isMaterialThemeIcons } from "../../helpers/settings";
|
2017-07-24 11:05:15 +02:00
|
|
|
import { getCurrentThemeID, getCurrentThemeIconsID, reloadWindow } from "../../helpers/vscode";
|
2017-07-21 20:20:17 +02:00
|
|
|
import { THEME_ICONS } from "../theme-icons/index";
|
2017-05-29 18:01:55 +02:00
|
|
|
|
2017-06-06 15:28:17 +02:00
|
|
|
const REGEXP_HEX: RegExp = /^#([0-9A-F]{6}|[0-9A-F]{8})$/i;
|
|
|
|
|
2017-06-23 13:55:52 +02:00
|
|
|
let themeConfigCommon: IDefaults = require('../../defaults.json');
|
2017-06-06 15:28:17 +02:00
|
|
|
let accentsProperties: IGenericObject<IAccentCustomProperty> = {
|
|
|
|
"activityBarBadge.background": {
|
|
|
|
alpha: 100,
|
|
|
|
value: undefined
|
|
|
|
},
|
|
|
|
"list.activeSelectionForeground": {
|
|
|
|
alpha: 100,
|
|
|
|
value: undefined
|
|
|
|
},
|
|
|
|
"list.inactiveSelectionForeground": {
|
|
|
|
alpha: 100,
|
|
|
|
value: undefined
|
|
|
|
},
|
|
|
|
"list.highlightForeground": {
|
|
|
|
alpha: 100,
|
|
|
|
value: undefined
|
|
|
|
},
|
|
|
|
"scrollbarSlider.activeBackground": {
|
2017-06-06 15:36:38 +02:00
|
|
|
alpha: 50,
|
2017-06-06 15:28:17 +02:00
|
|
|
value: undefined
|
|
|
|
},
|
|
|
|
"editorSuggestWidget.highlightForeground": {
|
|
|
|
alpha: 100,
|
|
|
|
value: undefined
|
|
|
|
},
|
|
|
|
"textLink.foreground": {
|
2017-06-06 15:36:38 +02:00
|
|
|
alpha: 100,
|
2017-06-06 15:28:17 +02:00
|
|
|
value: undefined
|
|
|
|
},
|
2017-06-21 11:48:43 +02:00
|
|
|
"progressBar.background": {
|
2017-06-20 09:16:55 +02:00
|
|
|
alpha: 100,
|
|
|
|
value: undefined
|
2017-06-30 16:33:12 +02:00
|
|
|
},
|
|
|
|
"pickerGroup.foreground": {
|
|
|
|
alpha: 100,
|
|
|
|
value: undefined
|
2017-09-11 14:43:33 +02:00
|
|
|
},
|
|
|
|
"tab.activeBorder": {
|
|
|
|
alpha: 100,
|
|
|
|
value: undefined
|
2017-06-20 09:55:06 +02:00
|
|
|
}
|
2017-05-29 18:01:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Assigns colours
|
|
|
|
* @param {string} colour
|
|
|
|
* @param {*} config
|
|
|
|
*/
|
|
|
|
function assignColorCustomizations(colour: string, config: any): void {
|
2017-06-08 10:08:46 +02:00
|
|
|
if (!isValidColour(colour)) {
|
|
|
|
colour = undefined;
|
|
|
|
}
|
|
|
|
|
2017-05-29 18:01:55 +02:00
|
|
|
Object.keys(accentsProperties).forEach(propertyName => {
|
2017-06-06 15:28:17 +02:00
|
|
|
let accent: IAccentCustomProperty = accentsProperties[propertyName];
|
2017-06-08 10:08:46 +02:00
|
|
|
let _colour = colour;
|
2017-06-06 15:28:17 +02:00
|
|
|
|
|
|
|
if (colour && accent.alpha < 100) {
|
2017-06-08 10:08:46 +02:00
|
|
|
_colour = `${ colour }${ accent.alpha > 10 ? accent.alpha : `0${ accent.alpha }` }`;
|
2017-06-06 15:28:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (accent) {
|
2017-06-08 10:08:46 +02:00
|
|
|
config[propertyName] = _colour;
|
2017-06-06 15:28:17 +02:00
|
|
|
}
|
2017-05-29 18:01:55 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-06-06 15:28:17 +02:00
|
|
|
/**
|
|
|
|
* Determines if a string is a valid colour
|
|
|
|
* @param {(string | null | undefined)} colour
|
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
|
|
|
function isValidColour(colour: string | null | undefined): boolean {
|
|
|
|
if (typeof colour === 'string' && REGEXP_HEX.test(colour)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-05-29 18:01:55 +02:00
|
|
|
/**
|
|
|
|
* Sets workbench options
|
|
|
|
* @param {string} accentSelected
|
|
|
|
* @param {*} config
|
|
|
|
*/
|
2017-06-23 13:55:52 +02:00
|
|
|
function setWorkbenchOptions(accentSelected: string | undefined, config: any): void {
|
2017-05-29 18:01:55 +02:00
|
|
|
vscode.workspace.getConfiguration().update('workbench.colorCustomizations', config, true).then(() => {
|
2017-07-21 20:20:17 +02:00
|
|
|
let themeID = getCurrentThemeID()
|
|
|
|
let themeIconsID = getCurrentThemeIconsID()
|
|
|
|
|
2017-10-26 22:50:08 +02:00
|
|
|
updateAccent(accentSelected).then(() => {
|
|
|
|
if (isMaterialTheme(themeID) && isMaterialThemeIcons(themeIconsID)) {
|
|
|
|
THEME_ICONS().then(() => reloadWindow());
|
|
|
|
}
|
|
|
|
});
|
2017-05-29 18:01:55 +02:00
|
|
|
}, 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 purgeColourKey: string = 'Remove accents';
|
|
|
|
|
|
|
|
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 purgeColourKey:
|
|
|
|
assignColorCustomizations(undefined, config);
|
2017-06-23 13:55:52 +02:00
|
|
|
setWorkbenchOptions(undefined, config);
|
2017-05-29 18:01:55 +02:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
assignColorCustomizations(themeConfigCommon.accents[accentSelected], config);
|
|
|
|
setWorkbenchOptions(accentSelected, config);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|