mirror of
https://github.com/We-Dont-Byte/Mind_Reader.git
synced 2024-11-15 03:35:59 +00:00
Split MindReader view into accessability and hub sub-views
This commit is contained in:
parent
90af5cba4a
commit
c2f159bbe6
12
package.json
12
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"
|
||||
}
|
||||
]
|
||||
|
@ -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<AccessAction> {
|
||||
public getTreeItem(a: AccessAction): vscode.TreeItem {
|
||||
return a;
|
||||
}
|
||||
|
||||
public async getChildren(): Promise<AccessAction[]> {
|
||||
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);
|
||||
}
|
||||
}
|
41
src/commandNodeProvider.ts
Normal file
41
src/commandNodeProvider.ts
Normal file
@ -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<CommandItem> {
|
||||
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<CommandItem[]> {
|
||||
return Promise.resolve(this.items);
|
||||
}
|
||||
}
|
@ -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() {}
|
||||
|
23
src/log.ts
Normal file
23
src/log.ts
Normal file
@ -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);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user