feat: Adds theme changer command

This commit is contained in:
OctoD roth 2017-05-28 16:50:44 +02:00
parent 6ba22488b5
commit cb68fdc5e3
5 changed files with 75 additions and 0 deletions

View file

@ -0,0 +1,3 @@
export interface IGenericObject<TValue> {
[index: string]: TValue;
}

View file

@ -0,0 +1,33 @@
import * as vscode from 'vscode';
import { COMMAND_THEME_SETTER } from "./theme-setter/index";
import { IGenericObject } from "./interfaces/igeneric-object";
enum Commands {
ACCENTS,
COLOR_THEME
}
const OPTIONS: IGenericObject<number> = {
'Change accents': Commands.ACCENTS,
'Change color scheme': Commands.COLOR_THEME
}
export function activate(context: vscode.ExtensionContext) {
// 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:
// break;
case Commands.COLOR_THEME:
COMMAND_THEME_SETTER();
break;
}
});
});
context.subscriptions.push(command);
}

View file

@ -0,0 +1,18 @@
import * as vscode from 'vscode';
import { THEMES } from './themes';
export const COMMAND_THEME_SETTER = () => {
vscode.window.showQuickPick(Object.keys(THEMES)).then(themeSelected => {
vscode.workspace.getConfiguration().update('workbench.colorTheme', THEMES[themeSelected], true).then(() => {
if (themeSelected === undefined) return;
vscode.window.showInformationMessage(`${ themeSelected } theme set.`);
}, () => {
if (themeSelected === undefined) return;
vscode.window.showErrorMessage(`Cannot set theme ${ themeSelected }, please report this bug to the Material theme devs.`);
});
});
};

View file

@ -0,0 +1,8 @@
import { IGenericObject } from "../interfaces/igeneric-object";
export const THEMES: IGenericObject<string> = {
Default: 'Material Theme',
Darker: 'Material Theme Darker',
Lighter: 'Material Theme Lighter',
'Pale night': 'Material Theme Palenight'
}

View file

@ -31,6 +31,7 @@
"build-icons": "npm run remove-icons && npm run minimize-icons && gulp build:icons && npm run minimize-json", "build-icons": "npm run remove-icons && npm run minimize-icons && gulp build:icons && npm run minimize-json",
"build-themes": "gulp build:themes", "build-themes": "gulp build:themes",
"release": "npm run bump && npm run changelog", "release": "npm run bump && npm run changelog",
"postinstall": "node ./node_modules/vscode/bin/instal",
"changelog": "gulp changelog", "changelog": "gulp changelog",
"bump": "gulp bump" "bump": "gulp bump"
}, },
@ -38,7 +39,18 @@
"Themes", "Themes",
"Other" "Other"
], ],
"activationEvents": [
"onCommand:material.theme.config"
],
"main": "./extensions/material.theme.config",
"contributes": { "contributes": {
"commands": [
{
"category": "Material theme",
"command": "material.theme.config",
"title": "Material theme settings"
}
],
"themes": [ "themes": [
{ {
"label": "Material Theme", "label": "Material Theme",
@ -104,6 +116,7 @@
"run-sequence": "^1.2.2", "run-sequence": "^1.2.2",
"svgo": "^0.7.1", "svgo": "^0.7.1",
"typescript": "2.3.3", "typescript": "2.3.3",
"vscode": "^1.1.0",
"yamljs": "^0.2.10", "yamljs": "^0.2.10",
"yargs": "^7.1.0" "yargs": "^7.1.0"
} }