Skip to content

Commit e7d12a5

Browse files
committed
Refactored code
1 parent c2c43f3 commit e7d12a5

5 files changed

Lines changed: 23 additions & 63 deletions

File tree

src/commands/activate.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import * as i18n from './../i18n';
55
import * as outdatedMessage from './../messages/outdated';
66

77
/** Activate the icon theme by changing the settings for the iconTheme. */
8-
export const activateIconTheme = () => {
8+
export const activateIcons = () => {
99
if (!versioning.checkVersionSupport('1.10.0')) {
1010
outdatedMessage.showOutdatedMessage();
1111
console.error('Outdated version of vscode!');

src/commands/index.ts

Lines changed: 16 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as vscode from 'vscode';
2-
import { activateIconTheme } from './activate';
2+
import { activateIcons } from './activate';
33
import { toggleFolderArrows } from './folderArrows';
44
import { changeFolderColor } from './folderColor';
55
import { changeFolderTheme } from './folders';
@@ -9,59 +9,19 @@ import { changeOpacity } from './opacity';
99
import { restoreDefaultConfig } from './restoreConfig';
1010
import { changeSaturation } from './saturation';
1111

12-
// Activate theme
13-
const activateThemeCommand = vscode.commands.registerCommand('material-icon-theme.activateIcons', () => {
14-
activateIconTheme();
12+
const commands = {
13+
activateIcons,
14+
toggleIconPacks,
15+
changeFolderTheme,
16+
changeFolderColor,
17+
restoreDefaultConfig,
18+
toggleFolderArrows,
19+
changeOpacity,
20+
toggleGrayscale,
21+
changeSaturation
22+
};
23+
24+
export const registered = Object.keys(commands).map(commandName => {
25+
const callCommand = () => commands[commandName]();
26+
return vscode.commands.registerCommand(`material-icon-theme.${commandName}`, callCommand);
1527
});
16-
17-
// Icon packs
18-
const toggleIconPacksCommand = vscode.commands.registerCommand('material-icon-theme.toggleIconPacks', () => {
19-
toggleIconPacks();
20-
});
21-
22-
// Folder themes
23-
const changeFolderThemeCommand = vscode.commands.registerCommand('material-icon-theme.changeFolderTheme', () => {
24-
changeFolderTheme();
25-
});
26-
27-
// Folder color
28-
const toggleFolderColorCommand = vscode.commands.registerCommand('material-icon-theme.changeFolderColor', () => {
29-
changeFolderColor();
30-
});
31-
32-
// Reset config
33-
const restoreDefaultConfigCommand = vscode.commands.registerCommand('material-icon-theme.restoreDefaultConfig', () => {
34-
restoreDefaultConfig();
35-
});
36-
37-
// Toggle the arrows near the folder icons
38-
const hidesExplorerArrowsCommand = vscode.commands.registerCommand('material-icon-theme.hidesExplorerArrows', () => {
39-
toggleFolderArrows();
40-
});
41-
42-
// Change the opacity of the icons
43-
const changeOpacityCommand = vscode.commands.registerCommand('material-icon-theme.opacity', () => {
44-
changeOpacity();
45-
});
46-
47-
// Toggle grayscale icons
48-
const grayscaleCommand = vscode.commands.registerCommand('material-icon-theme.grayscale', () => {
49-
toggleGrayscale();
50-
});
51-
52-
// Change the saturation of the icons
53-
const changeSaturationCommand = vscode.commands.registerCommand('material-icon-theme.saturation', () => {
54-
changeSaturation();
55-
});
56-
57-
export const commands = [
58-
activateThemeCommand,
59-
toggleIconPacksCommand,
60-
changeFolderThemeCommand,
61-
toggleFolderColorCommand,
62-
restoreDefaultConfigCommand,
63-
hidesExplorerArrowsCommand,
64-
changeOpacityCommand,
65-
grayscaleCommand,
66-
changeSaturationCommand
67-
];

src/extension.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ export const activate = async (context: vscode.ExtensionContext) => {
1717
const status = await checkThemeStatus(context.globalState);
1818
showStartMessages(status);
1919

20-
// Register the extension commands
21-
context.subscriptions.push(...commands.commands);
20+
// Subscribe to the extension commands
21+
context.subscriptions.push(...commands.registered);
2222

2323
// Initially trigger the config change detection
2424
detectConfigChanges();

src/messages/update.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as opn from 'opn';
22
import * as vscode from 'vscode';
3-
import { activateIconTheme } from '../commands/activate';
3+
import { activateIcons } from '../commands/activate';
44
import * as helpers from './../helpers';
55
import * as versioning from './../helpers/versioning';
66
import * as i18n from './../i18n';
@@ -26,7 +26,7 @@ export const showUpdateMessage = () => {
2626
const handleUpdateMessageActions = (value) => {
2727
switch (value) {
2828
case i18n.translate('activate'):
29-
activateIconTheme();
29+
activateIcons();
3030
break;
3131

3232
case i18n.translate('readChangelog'):

src/messages/welcome.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as opn from 'opn';
22
import * as vscode from 'vscode';
3-
import { activateIconTheme } from '../commands/activate';
3+
import { activateIcons } from '../commands/activate';
44
import * as helpers from './../helpers';
55
import * as versioning from './../helpers/versioning';
66
import * as i18n from './../i18n';
@@ -25,7 +25,7 @@ export const showWelcomeMessage = () => {
2525
const handleWelcomeMessageActions = (value) => {
2626
switch (value) {
2727
case i18n.translate('activate'):
28-
activateIconTheme();
28+
activateIcons();
2929
break;
3030

3131
case i18n.translate('howToActivate'):

0 commit comments

Comments
 (0)