Feat/split commands (#177)

* feat(split-commands): splitting commands in package.json and rewrite

* chore(cleanup): removed useless function

* chore(old-conf): delete old configuration
This commit is contained in:
Alessio Occhipinti 2018-04-30 09:55:47 +02:00 committed by Mattia Astorino
parent c4e1dbe106
commit 1af7cf94e3
3 changed files with 58 additions and 76 deletions

View file

@ -19,7 +19,7 @@ export function getAccent(): string | undefined {
* @returns {*}
*/
export function getCustomSettings(): IThemeCustomProperties {
return vscode.workspace.getConfiguration().get<IThemeCustomProperties>('materialTheme.cache.workbench.settings', {});
return vscode.workspace.getConfiguration().get<IThemeCustomProperties>('materialTheme', {});
}
/**
@ -58,27 +58,11 @@ export function isMaterialThemeIcons(themeIconsName: string): boolean {
/**
* Sets a custom property in custom settings
* @export
* @param {string} settingname
* @param {string} settingName
* @param {*} value
*/
export function setCustomSetting(settingname: string, value: any): Thenable<void> {
let settings: any = getCustomSettings();
settings[settingname] = value;
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);
export function setCustomSetting(settingName: string, value: any): Thenable<void> {
return vscode.workspace.getConfiguration().update(`materialTheme.${settingName}`, value, true);
}
/**
@ -87,7 +71,7 @@ export function setCustomSettings(settingsObject: IThemeCustomProperties): Thena
* @param {string} accentName
*/
export function updateAccent(accentName: string): Thenable<void> {
const prevaccent = getAccent();
return setCustomSetting('accentPrevious', prevaccent)
.then(() => setCustomSetting('accent', accentName));
const prevAccent = getAccent();
return setCustomSetting('accentPrevious', prevAccent)
.then(() => setCustomSetting('accent', accentName))
}

View file

@ -1,63 +1,45 @@
import * as vscode from 'vscode';
import {
workspace as Workspace,
commands as Commands
} 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,
THEME_ICONS
}
const OPTIONS: IGenericObject<number> = {
'🎨 Change accent color': Commands.ACCENTS,
'🛠 Fix file icons': Commands.THEME_ICONS,
'🚧 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);
}
export function activate() {
const config = Workspace.getConfiguration();
vscode.workspace.onDidChangeConfiguration(async event => {
// Listen on set theme: when the theme is Material Theme, just adjust icon and accent.
Workspace.onDidChangeConfiguration(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();
setIconsID('eq-material-theme-icons')
.then(() => THEME_ICONS().catch(error => console.trace(error)))
.then(() => reloadWindow());
}
});
// Delete old configuration, must remove with next major release
if (config.has('materialTheme.cache.workbench')) {
config.update('materialTheme.cache.workbench', undefined, true);
}
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;
case Commands.THEME_ICONS:
THEME_ICONS().then(() => reloadWindow()).catch(error => console.trace(error))
break;
}
});
});
context.subscriptions.push(command);
// Registering commands
Commands.registerCommand('materialTheme.setAccent', () => THEME_ACCENTS_SETTER());
Commands.registerCommand('materialTheme.fixIcons', () =>
THEME_ICONS()
.then(() => reloadWindow())
.catch(err => console.trace(err))
);
Commands.registerCommand('materialTheme.showChangelog', () => showChangelog());
}

View file

@ -45,24 +45,40 @@
"Other"
],
"activationEvents": [
"*"
"onCommand:materialTheme.setAccent",
"onCommand:materialTheme.fixIcons",
"onCommand:materialTheme.showChangelog"
],
"main": "./extensions/material.theme.config.js",
"contributes": {
"commands": [
{
"category": "🎨 Material Theme",
"command": "material.theme.config",
"title": "Configuration"
}
{
"command": "materialTheme.setAccent",
"title": "Set accent color for Material Theme",
"category": "🎨 Material Theme"
},
{
"command": "materialTheme.fixIcons",
"title": "Fix icons color when needed",
"category": "🎨 Material Theme"
},
{
"command": "materialTheme.showChangelog",
"title": "Show changelog",
"category": "🎨 Material Theme"
}
],
"configuration": {
"type": "object",
"title": "Material Theme configuration",
"properties": {
"materialTheme.cache.workbench.settings": {
"default": {},
"type": "object",
"title": "Custom material theme settings",
"description": "Material theme settings object."
"materialTheme.accent": {
"type": "string",
"description": "Current accent color selected"
},
"materialTheme.accentPrevious": {
"type": "string",
"description": "Previous accent color selected"
}
}
},