Skip to content

Commit 996907e

Browse files
Merge PRs GorvGoyl#78, GorvGoyl#88, GorvGoyl#90\n\n- Fixes PR integration conflicts\n- Migrates extension icons to standard VSCode codicons (GorvGoyl#90)\n- Adds new fold/unfold + PlantUML buttons (GorvGoyl#78)\n- Adds toggle maximize editor group button (GorvGoyl#88)\n- Sets activationEvent properly to onStartupFinished to correctly load up the extension on new versions of VSCode.
Co-authored-by: thexmeta <3031096+thexmeta@users.noreply.github.com>
1 parent d7f675a commit 996907e

3 files changed

Lines changed: 73 additions & 129 deletions

File tree

package.json

Lines changed: 50 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,51 @@
4444
"button"
4545
],
4646
"activationEvents": [
47-
"onStartupFinished"
47+
"onCommand:ShortcutMenuBar.navigateBack",
48+
"onCommand:ShortcutMenuBar.navigateForward",
49+
"onCommand:ShortcutMenuBar.switchHeaderSource",
50+
"onCommand:ShortcutMenuBar.save",
51+
"onCommand:ShortcutMenuBar.beautify",
52+
"onCommand:ShortcutMenuBar.toggleRenderWhitespace",
53+
"onCommand:ShortcutMenuBar.openFilesList",
54+
"onCommand:ShortcutMenuBar.toggleTerminal",
55+
"onCommand:ShortcutMenuBar.toggleActivityBar",
56+
"onCommand:ShortcutMenuBar.quickOpen",
57+
"onCommand:ShortcutMenuBar.findReplace",
58+
"onCommand:ShortcutMenuBar.undo",
59+
"onCommand:ShortcutMenuBar.redo",
60+
"onCommand:ShortcutMenuBar.commentLine",
61+
"onCommand:ShortcutMenuBar.saveAll",
62+
"onCommand:ShortcutMenuBar.formatWith",
63+
"onCommand:ShortcutMenuBar.openFile",
64+
"onCommand:ShortcutMenuBar.newFile",
65+
"onCommand:ShortcutMenuBar.goToDefinition",
66+
"onCommand:ShortcutMenuBar.cut",
67+
"onCommand:ShortcutMenuBar.copy",
68+
"onCommand:ShortcutMenuBar.paste",
69+
"onCommand:ShortcutMenuBar.compareWithSaved",
70+
"onCommand:ShortcutMenuBar.showCommands",
71+
"onCommand:ShortcutMenuBar.startDebugging",
72+
"onCommand:ShortcutMenuBar.indentLines",
73+
"onCommand:ShortcutMenuBar.outdentLines",
74+
"onCommand:ShortcutMenuBar.openSettings",
75+
"onCommand:ShortcutMenuBar.toggleWordWrap",
76+
"onCommand:ShortcutMenuBar.changeEncoding",
77+
"onCommand:ShortcutMenuBar.powershellRestartSession",
78+
"onCommand:ShortcutMenuBar.userButton10",
79+
"onCommand:ShortcutMenuBar.userButton01",
80+
"onCommand:ShortcutMenuBar.userButton02",
81+
"onCommand:ShortcutMenuBar.userButton03",
82+
"onCommand:ShortcutMenuBar.userButton04",
83+
"onCommand:ShortcutMenuBar.userButton05",
84+
"onCommand:ShortcutMenuBar.userButton06",
85+
"onCommand:ShortcutMenuBar.userButton07",
86+
"onCommand:ShortcutMenuBar.userButton08",
87+
"onCommand:ShortcutMenuBar.userButton09",
88+
"onCommand:ShortcutMenuBar.codeFold",
89+
"onCommand:ShortcutMenuBar.codeUnfold",
90+
"onCommand:ShortcutMenuBar.plantUmlPreview",
91+
"onCommand:ShortcutMenuBar.toggleMaximizeEditorGroup"
4892
],
4993
"main": "./out/extension.js",
5094
"contributes": {
@@ -489,10 +533,7 @@
489533
"command": "ShortcutMenuBar.showCommands",
490534
"title": "Open command pallet",
491535
"category": "ShortcutMenuBar",
492-
"icon": {
493-
"light": "images/commands_light.svg",
494-
"dark": "images/commands.svg"
495-
}
536+
"icon": "$(tools)"
496537
},
497538
{
498539
"command": "ShortcutMenuBar.startDebugging",
@@ -642,37 +683,25 @@
642683
"command": "ShortcutMenuBar.codeFold",
643684
"title": "Code fold",
644685
"category": "ShortcutMenuBar",
645-
"icon": {
646-
"light": "images/fold_light.svg",
647-
"dark": "images/fold.svg"
648-
}
686+
"icon": "$(fold-up)"
649687
},
650688
{
651689
"command": "ShortcutMenuBar.codeUnfold",
652690
"title": "Code unfold",
653691
"category": "ShortcutMenuBar",
654-
"icon": {
655-
"light": "images/unfold_light.svg",
656-
"dark": "images/unfold.svg"
657-
}
692+
"icon": "$(fold-down)"
658693
},
659694
{
660695
"command": "ShortcutMenuBar.plantUmlPreview",
661696
"title": "PlantUML Preview",
662697
"category": "ShortcutMenuBar",
663-
"icon": {
664-
"light": "images/plantUmlPreview_light.svg",
665-
"dark": "images/plantUmlPreview.svg"
666-
}
698+
"icon": "$(preview)"
667699
},
668700
{
669701
"command": "ShortcutMenuBar.toggleMaximizeEditorGroup",
670702
"title": "Toggle Maximize Editor Group",
671703
"category": "ShortcutMenuBar",
672-
"icon": {
673-
"light": "images/toggleMaximizeEditorGroup_light.svg",
674-
"dark": "images/toggleMaximizeEditorGroup.svg"
675-
}
704+
"icon": "$(chrome-maximize)"
676705
}
677706
],
678707
"keybindings": [

shortcut-menu-bar-3.0.4.vsix

-409 Bytes
Binary file not shown.

src/extension.ts

Lines changed: 23 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121

2222
// The module 'vscode' contains the VS Code extensibility API
2323
// Import the module and reference it with the alias vscode in your code below
24-
import fs = require("fs");
25-
import { basename, dirname, extname, join } from "path";
24+
// import fs = require("fs");
25+
import { basename, dirname, extname } from "path";
2626
import {
2727
commands,
2828
Disposable,
@@ -209,117 +209,32 @@ export function activate(context: ExtensionContext) {
209209
context.subscriptions.push(disposableSwitch);
210210

211211
// Adding 3 // user defined userButtons
212-
let registerUserCommand = (command: string, action: String) => {
213-
let disposableUserButtonCommand = commands.registerCommand(command, () => {
214-
const config = workspace.getConfiguration("ShortcutMenuBar");
215-
let command = config.get<String>(action + "Command");
216-
217-
// skip userButtons not set
218-
if (
219-
command === null ||
220-
command === undefined ||
221-
command.trimEnd() === ""
222-
) {
223-
window.showWarningMessage(
224-
`ShortcutMenuBar: User button ${action.replace(
225-
"userButton",
226-
""
227-
)} is not assigned`
228-
);
229-
return;
230-
}
231-
232-
let matches = /(\$\([\w-]+\))(.*)/g.exec(command.toString());
233-
if (matches !== null) {
234-
command = new String(matches[2]);
235-
}
236-
237-
const palettes = command.split(",");
238-
executeNext(action, palettes, 0);
239-
});
240-
context.subscriptions.push(disposableUserButtonCommand);
241-
};
212+
for (let index = 1; index <= 10; index++) {
213+
const printIndex = index !== 10 ? "0" + index : "" + index;
214+
let action = "userButton" + printIndex;
215+
let actionName = "ShortcutMenuBar." + action;
216+
let disposableUserButtonCommand = commands.registerCommand(
217+
actionName,
218+
() => {
219+
const config = workspace.getConfiguration("ShortcutMenuBar");
220+
let configName = action + "Command";
221+
const command = config.get<String>(configName);
242222

243-
enum RegisterUserCommands {
244-
Yes,
245-
No,
246-
}
247-
enum ReloadWindow {
248-
Yes,
249-
No,
250-
}
251-
let updateCommands = (
252-
registerCommands: RegisterUserCommands,
253-
reloadWindow: ReloadWindow
254-
) => {
255-
let configPath = join(context.extensionPath, "package.json");
256-
fs.readFile(configPath, "utf8", (err, data) => {
257-
if (!err) {
258-
const ext_config = JSON.parse(data);
223+
// skip userButtons not set
259224
if (
260-
ext_config.contributes !== undefined &&
261-
ext_config.contributes !== null &&
262-
ext_config.contributes.commands !== undefined &&
263-
ext_config.contributes.commands !== null
225+
command === null ||
226+
command === undefined ||
227+
command.trimEnd() === ""
264228
) {
265-
let needPatchExtension = false;
266-
const config = workspace.getConfiguration("ShortcutMenuBar");
267-
ext_config.contributes.commands.forEach((item) => {
268-
if (item.command === undefined || item.command === null) {
269-
return;
270-
}
271-
if (item.command.startsWith("ShortcutMenuBar.userButton")) {
272-
const action = item.command.replace("ShortcutMenuBar.", "");
273-
const command = config.get<String>(action + "Command");
274-
275-
if (registerCommands == RegisterUserCommands.Yes)
276-
registerUserCommand(item.command, action);
277-
278-
// skip userButtons not set
279-
if (
280-
command === null ||
281-
command === undefined ||
282-
command.trimEnd() === ""
283-
) {
284-
return;
285-
}
286-
287-
let matches = /(\$\([\w-]+\))(.*)/g.exec(command.toString());
288-
if (matches === null) {
289-
return;
290-
}
291-
292-
needPatchExtension = item.icon !== matches[1];
293-
item.icon = matches[1];
294-
}
295-
});
296-
297-
if (needPatchExtension) {
298-
const config = JSON.stringify(ext_config, null, 2);
299-
fs.writeFile(configPath, config, "utf8", (err) => {
300-
if (!err) {
301-
if (reloadWindow == ReloadWindow.Yes)
302-
commands.executeCommand("workbench.action.reloadWindow");
303-
else
304-
window.showInformationMessage(
305-
"You need restart VSCode to update toolbar icons"
306-
);
307-
}
308-
});
309-
}
229+
return;
310230
}
311-
}
312-
});
313-
};
314-
315-
updateCommands(RegisterUserCommands.Yes, ReloadWindow.Yes);
316231

317-
let configWatcher = workspace.onDidChangeConfiguration((event) => {
318-
if (event.affectsConfiguration("ShortcutMenuBar")) {
319-
updateCommands(RegisterUserCommands.No, ReloadWindow.No);
320-
}
321-
});
322-
context.subscriptions.push(configWatcher);
232+
const palettes = command.split(",");
233+
executeNext(action, palettes, 0);
234+
}
235+
);
236+
context.subscriptions.push(disposableUserButtonCommand);
237+
}
323238
}
324239

325240
// this method is called when your extension is deactivated

0 commit comments

Comments
 (0)