fix: "Remove accents" command now will remove custom color conf (#289)
This commit is contained in:
parent
c8a23ef3d0
commit
85238745fe
5 changed files with 41 additions and 42 deletions
3
extensions/commands/accents-setter/consts.ts
Normal file
3
extensions/commands/accents-setter/consts.ts
Normal file
|
@ -0,0 +1,3 @@
|
|||
export default {
|
||||
PURGE_KEY: 'Remove accents'
|
||||
};
|
|
@ -1,29 +1,27 @@
|
|||
import * as vscode from 'vscode';
|
||||
|
||||
import {updateAccent} from './../../helpers/settings';
|
||||
import {getDefaultValues, getAccentsProperties} from './../../helpers/fs';
|
||||
import consts from './consts';
|
||||
|
||||
const REGEXP_HEX: RegExp = /^#([0-9A-F]{6}|[0-9A-F]{8})$/i;
|
||||
|
||||
/**
|
||||
* Assigns colours
|
||||
*/
|
||||
const assignColorCustomizations = (colour: string, config: any): void => {
|
||||
const assignColorCustomizations = (colour: string): Object => {
|
||||
const accentsProperties = getAccentsProperties();
|
||||
const newColour = isValidColour(colour) ? colour : undefined;
|
||||
|
||||
Object.keys(accentsProperties).forEach(propertyName => {
|
||||
const accent = accentsProperties[propertyName];
|
||||
return Object.keys(accentsProperties).reduce((acc: any, propName) => {
|
||||
const accent = accentsProperties[propName];
|
||||
let colorProp = newColour;
|
||||
|
||||
if (colour && accent.alpha < 100) {
|
||||
colorProp = `${ colour }${ accent.alpha > 10 ? accent.alpha : `0${ accent.alpha }` }`;
|
||||
}
|
||||
|
||||
if (accent) {
|
||||
config[propertyName] = colorProp;
|
||||
}
|
||||
});
|
||||
acc[propName] = colorProp;
|
||||
return acc;
|
||||
}, {});
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -38,43 +36,32 @@ const isValidColour = (colour: string | null | undefined): boolean =>
|
|||
const setWorkbenchOptions = (config: any): Thenable<boolean> =>
|
||||
vscode.workspace.getConfiguration().update('workbench.colorCustomizations', config, true)
|
||||
.then(() => true, reason => vscode.window.showErrorMessage(reason));
|
||||
|
||||
/**
|
||||
* VSCode command
|
||||
*/
|
||||
export default async (accent?: string): Promise<boolean> => {
|
||||
const themeConfigCommon = getDefaultValues();
|
||||
const purgeColourKey: string = 'Remove accents';
|
||||
const shouldUpdateAccent = Boolean(!accent);
|
||||
let accentToSelect = accent;
|
||||
|
||||
// If called without accent shows the quick pick dropdown and wait response
|
||||
if (!accentToSelect) {
|
||||
const options: string[] = Object.keys(themeConfigCommon.accents).concat(purgeColourKey);
|
||||
const accentSelected = await vscode.window.showQuickPick(options);
|
||||
|
||||
if (accentSelected === null || accentSelected === undefined) {
|
||||
return Promise.resolve(null);
|
||||
}
|
||||
|
||||
accentToSelect = accentSelected;
|
||||
}
|
||||
|
||||
const config: any = vscode.workspace.getConfiguration().get('workbench.colorCustomizations');
|
||||
|
||||
switch (accentToSelect) {
|
||||
case purgeColourKey:
|
||||
assignColorCustomizations(undefined, config);
|
||||
return setWorkbenchOptions(config)
|
||||
.then(() => updateAccent(undefined))
|
||||
.then(() => Promise.resolve(true));
|
||||
default:
|
||||
assignColorCustomizations(themeConfigCommon.accents[accentToSelect], config);
|
||||
return setWorkbenchOptions(config)
|
||||
.then(() =>
|
||||
shouldUpdateAccent ? updateAccent(accentToSelect) : Promise.resolve(accentToSelect)
|
||||
)
|
||||
switch (accent) {
|
||||
case consts.PURGE_KEY: {
|
||||
const newConfig = {
|
||||
...config,
|
||||
...assignColorCustomizations(undefined)
|
||||
};
|
||||
|
||||
return setWorkbenchOptions(newConfig)
|
||||
.then(() => Promise.resolve(true));
|
||||
}
|
||||
default: {
|
||||
const newConfig = {
|
||||
...config,
|
||||
...assignColorCustomizations(themeConfigCommon.accents[accent])
|
||||
};
|
||||
|
||||
return setWorkbenchOptions(newConfig)
|
||||
.then(() => Boolean(accent));
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
|
9
extensions/commands/accents-setter/quick-pick.ts
Normal file
9
extensions/commands/accents-setter/quick-pick.ts
Normal file
|
@ -0,0 +1,9 @@
|
|||
import * as vscode from 'vscode';
|
||||
import {getDefaultValues} from '../../helpers/fs';
|
||||
import consts from './consts';
|
||||
|
||||
export default async () => {
|
||||
const themeConfigCommon = getDefaultValues();
|
||||
const options: string[] = Object.keys(themeConfigCommon.accents).concat(consts.PURGE_KEY);
|
||||
return vscode.window.showQuickPick(options);
|
||||
};
|
|
@ -1,3 +1,4 @@
|
|||
export {default as accentsSetter} from './accents-setter';
|
||||
export {default as accentsQuickPick} from './accents-setter/quick-pick';
|
||||
export {default as fixIcons} from './theme-icons';
|
||||
export {default as toggleApplyIcons} from './toggle-apply-icons';
|
||||
|
|
|
@ -5,13 +5,12 @@ import {
|
|||
} from 'vscode';
|
||||
|
||||
import * as ThemeCommands from './commands';
|
||||
import {setCustomSetting} from './helpers/settings';
|
||||
import {setCustomSetting, updateAccent} from './helpers/settings';
|
||||
import {onChangeConfiguration} from './helpers/configuration-change';
|
||||
import {changelogMessage, installationMessage} from './helpers/messages';
|
||||
import checkInstallation from './helpers/check-installation';
|
||||
import writeChangelog from './helpers/write-changelog';
|
||||
import {ReleaseNotesWebview} from './webviews/ReleaseNotes';
|
||||
import handleAutoapply from './helpers/handle-autoapply';
|
||||
|
||||
export async function activate(context: ExtensionContext) {
|
||||
const config = Workspace.getConfiguration();
|
||||
|
@ -42,8 +41,8 @@ export async function activate(context: ExtensionContext) {
|
|||
|
||||
// Registering commands
|
||||
Commands.registerCommand('materialTheme.setAccent', async () => {
|
||||
const wasSet = await ThemeCommands.accentsSetter();
|
||||
handleAutoapply(wasSet);
|
||||
const accentPicked = await ThemeCommands.accentsQuickPick();
|
||||
await updateAccent(accentPicked);
|
||||
});
|
||||
Commands.registerCommand('materialTheme.fixIcons', () => ThemeCommands.fixIcons());
|
||||
Commands.registerCommand('materialTheme.toggleApplyIcons', () => ThemeCommands.toggleApplyIcons());
|
||||
|
|
Loading…
Reference in a new issue