From c0f23d6de15144d7ca9b95657f3f0069ea7dbefa Mon Sep 17 00:00:00 2001 From: Jake Grossman Date: Thu, 18 Nov 2021 00:33:55 -0600 Subject: [PATCH] Add persistent accessibility pane (#9) * Add persistent accessibility pane This will facilitate more extensive usage of the menu than the context menu. --- media/dep.svg | 14 ++++++++++++ package.json | 21 ++++++++++++++++- src/accessNodeProvider.ts | 47 +++++++++++++++++++++++++++++++++++++++ src/extension.ts | 6 +++++ 4 files changed, 87 insertions(+), 1 deletion(-) create mode 100644 media/dep.svg create mode 100644 src/accessNodeProvider.ts diff --git a/media/dep.svg b/media/dep.svg new file mode 100644 index 0000000..53e5be5 --- /dev/null +++ b/media/dep.svg @@ -0,0 +1,14 @@ + + + + Slice + Created with Sketch. + + + + + + + + + diff --git a/package.json b/package.json index b7a7e4f..8fd1068 100644 --- a/package.json +++ b/package.json @@ -268,7 +268,26 @@ "markdownDescription": "Specifies the serial port path to use if `#mindreader.connectAutomatically#` is not set." } } - } + }, + "views": { + "accessActions": [ + { + "id": "accessActions", + "name": "Access Actions", + "icon": "media/dep.svg", + "contextualTitle": "Accessibility Menu Actions" + } + ] + }, + "viewsContainers": { + "activitybar": [ + { + "id": "accessActions", + "title": "Access Actions", + "icon": "media/dep.svg" + } + ] + } }, "scripts": { "vscode:prepublish": "npm run compile", diff --git a/src/accessNodeProvider.ts b/src/accessNodeProvider.ts new file mode 100644 index 0000000..9b0db83 --- /dev/null +++ b/src/accessNodeProvider.ts @@ -0,0 +1,47 @@ +import * as vscode from 'vscode'; + +// list of all actions +let actions: AccessAction[] = []; + +class AccessAction extends vscode.TreeItem { + constructor( + public readonly label: string, + public readonly command: vscode.Command + ) { + super(label, vscode.TreeItemCollapsibleState.None); + } +}; + +export default class AccessNodeProvider implements vscode.TreeDataProvider { + public getTreeItem(a: AccessAction): vscode.TreeItem { + return a; + } + + public async getChildren(): Promise { + if (actions.length === 0) { + // fetch and cache mind-reader options + let cmds: string[] = await vscode.commands.getCommands(true); // get non-builtin commands + cmds = cmds.filter(x => x.startsWith('mind-reader')); // filter mind-reader commands + + cmds.forEach(c => { + let humanReadable = c.replace(/^mind-reader\./, ''); // strip extensions name + + // Convert camelCaseText to Title Case Text + humanReadable = humanReadable.replace(/([A-Z])/g, ' $1'); + humanReadable = humanReadable.charAt(0).toUpperCase() + humanReadable.slice(1); + + // add item to actions + actions.push(new AccessAction( + humanReadable, + { + title: humanReadable, + command: c, + tooltip: humanReadable + } + )); + }); + } + + return Promise.resolve(actions); + } +} diff --git a/src/extension.ts b/src/extension.ts index 5767437..ffeab0f 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -3,6 +3,8 @@ import * as vscode from 'vscode'; import * as pl from './pylex'; import commands from './commands'; +import AccessNodeProvider from './accessNodeProvider' + let parser: pl.Parser = new pl.Parser(); export function activate(context: vscode.ExtensionContext) { @@ -19,6 +21,10 @@ export function activate(context: vscode.ExtensionContext) { ); context.subscriptions.push(disposable); }); + + let provider = new AccessNodeProvider(); + vscode.window.registerTreeDataProvider('accessActions', provider); + } export function deactivate() {}