From c2f159bbe6965598e9084192a0e1e5332d87efef Mon Sep 17 00:00:00 2001 From: jakergrossman Date: Thu, 18 Nov 2021 15:59:04 -0600 Subject: [PATCH] Split MindReader view into accessability and hub sub-views --- package.json | 12 +++++++--- src/accessNodeProvider.ts | 47 -------------------------------------- src/commandNodeProvider.ts | 41 +++++++++++++++++++++++++++++++++ src/extension.ts | 36 ++++++++++++++++++++++++++--- src/log.ts | 23 +++++++++++++++++++ 5 files changed, 106 insertions(+), 53 deletions(-) delete mode 100644 src/accessNodeProvider.ts create mode 100644 src/commandNodeProvider.ts create mode 100644 src/log.ts diff --git a/package.json b/package.json index 2c21fa6..38dc7d0 100644 --- a/package.json +++ b/package.json @@ -216,20 +216,26 @@ } }, "views": { - "accessActions": [ + "MindReader": [ { "id": "accessActions", "name": "Access Actions", "icon": "media/dep.svg", "contextualTitle": "Accessibility Menu Actions" + }, + { + "id": "hubActions", + "name": "Hub Actions", + "icon": "media/dep.svg", + "contextualTitle": "Hub Connection Actions" } ] }, "viewsContainers": { "activitybar": [ { - "id": "accessActions", - "title": "Access Actions", + "id": "MindReader", + "title": "MindReader Actions", "icon": "media/dep.svg" } ] diff --git a/src/accessNodeProvider.ts b/src/accessNodeProvider.ts deleted file mode 100644 index 9b0db83..0000000 --- a/src/accessNodeProvider.ts +++ /dev/null @@ -1,47 +0,0 @@ -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/commandNodeProvider.ts b/src/commandNodeProvider.ts new file mode 100644 index 0000000..bf43d14 --- /dev/null +++ b/src/commandNodeProvider.ts @@ -0,0 +1,41 @@ +import * as vscode from 'vscode'; + +export class CommandItem extends vscode.TreeItem { + constructor( + public readonly label: string, + public readonly command: vscode.Command + ) { + super(label, vscode.TreeItemCollapsibleState.None); + } +}; + +export default class CommandNodeProvider implements vscode.TreeDataProvider { + private items: CommandItem[] = []; + + public constructor(commands: string[]) { + // build and cache command items + for (const c of commands) { + console.log(commands.length); + // Convert camelCaseText to Title Case Text + let humanReadable = c.replace(/([A-Z])/g, ' $1'); + humanReadable = humanReadable.charAt(0).toUpperCase() + humanReadable.slice(1); + + this.items.push(new CommandItem( + humanReadable, + { + title: humanReadable, + command: 'mind-reader.' + c, + tooltip: humanReadable + } + )); + } + } + + public getTreeItem(item: CommandItem): vscode.TreeItem { + return item; + } + + public async getChildren(): Promise { + return Promise.resolve(this.items); + } +} diff --git a/src/extension.ts b/src/extension.ts index d527a33..adfbf5f 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -3,7 +3,7 @@ import * as pl from './pylex'; import commands from './commands'; -import AccessNodeProvider from './accessNodeProvider'; +import CommandNodeProvider from './commandNodeProvider'; import Logger from './log'; // Output Logger @@ -27,8 +27,38 @@ export function activate(context: vscode.ExtensionContext) { context.subscriptions.push(disposable); }); - let provider = new AccessNodeProvider(); - vscode.window.registerTreeDataProvider('accessActions', provider); + // list of all commands to present in the access pane + const accessActions: string[] = [ + 'increaseFontScale', + 'decreaseFontScale', + 'resetFontScale', + + 'increaseEditorScale', + 'decreaseEditorScale', + 'resetEditorScale', + + 'selectTheme', + + 'runLineContext', + 'runCursorContext', + ]; + + let accessProvider = new CommandNodeProvider(accessActions); + vscode.window.registerTreeDataProvider('accessActions', accessProvider); + + + // list of all commands to present in the hub pane + const hubCommands: string[] = [ + 'connectHub', + 'diconnectHub', + 'uploadCurrentFile', + 'runProgram', + 'stopExecution', + 'deleteProgram', + ]; + + let hubProvider = new CommandNodeProvider(hubCommands); + vscode.window.registerTreeDataProvider('hubActions', hubProvider); } export function deactivate() {} diff --git a/src/log.ts b/src/log.ts new file mode 100644 index 0000000..a774776 --- /dev/null +++ b/src/log.ts @@ -0,0 +1,23 @@ +import * as vscode from 'vscode'; + +export default class Logger { + constructor( + public readonly outputChannel: vscode.OutputChannel + ) { } + + public log(text: string): void { + this.outputChannel.appendLine(text); + } + + public info(text: string): void { + this.outputChannel.appendLine('[INFO]\r' + text); + } + + public warn(text: string): void { + this.outputChannel.appendLine('[WARNING]\r' + text); + } + + public error(text: string): void { + this.outputChannel.appendLine('[ERROR]\r' + text); + } +}