vsc-material-theme/extensions/material.theme.config.ts
2018-04-21 18:22:34 +02:00

58 lines
1.9 KiB
TypeScript

import * as vscode from 'vscode';
import { IGenericObject } from "./interfaces/igeneric-object";
import { THEME_ACCENTS_SETTER } from "./commands/accents-setter/index";
import { THEME_ICONS } from "./commands/theme-icons/index";
import { shouldShowChangelog, showChangelog } from './helpers/changelog';
import { reloadWindow, getCurrentThemeID, setIconsID } from "./helpers/vscode";
enum Commands {
ACCENTS,
CHANGELOG
}
const OPTIONS: IGenericObject<number> = {
'🖍 Change accent color': Commands.ACCENTS,
'🚧 Show changelog': Commands.CHANGELOG
}
const isMaterialTheme = (currentTheme: string): boolean =>
currentTheme.includes('Material Theme');
export function activate(context: vscode.ExtensionContext) {
if (vscode.workspace.getConfiguration().has('materialTheme.cache.workbench.accent')) {
vscode.workspace.getConfiguration().update('materialTheme.cache.workbench.accent', undefined, true);
}
vscode.workspace.onDidChangeConfiguration(async event => {
const isColorTheme = event.affectsConfiguration('workbench.colorTheme');
const currentTheme = getCurrentThemeID();
if (isColorTheme && isMaterialTheme(currentTheme)) {
await setIconsID('eq-material-theme-icons');
await THEME_ICONS().catch(error => console.trace(error));
reloadWindow();
}
});
if (shouldShowChangelog()) {
showChangelog();
}
// registering the command
let command = vscode.commands.registerCommand('material.theme.config', () => {
// the user is going to choose what aspect of theme to config
vscode.window.showQuickPick(Object.keys(OPTIONS)).then(response => {
// switching selected option
switch(OPTIONS[response]) {
case Commands.ACCENTS:
THEME_ACCENTS_SETTER();
break;
case Commands.CHANGELOG:
showChangelog();
break;
}
});
});
context.subscriptions.push(command);
}