mirror of
				https://github.com/We-Dont-Byte/Mind_Reader.git
				synced 2025-02-04 10:38:42 +00:00 
			
		
		
		
	Add persistent accessibility pane (#9)
* Add persistent accessibility pane This will facilitate more extensive usage of the menu than the context menu.
This commit is contained in:
		
							
								
								
									
										47
									
								
								src/accessNodeProvider.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										47
									
								
								src/accessNodeProvider.ts
									
									
									
									
									
										Normal file
									
								
							@@ -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<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);
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
@@ -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() {}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user