diff --git a/src/extension/commands.ts b/src/extension/commands.ts new file mode 100644 index 0000000..199a7b4 --- /dev/null +++ b/src/extension/commands.ts @@ -0,0 +1,51 @@ +import { + ExtensionContext, + Disposable, + QuickPickItem, + ViewColumn, + Uri, + commands, + window, + workspace +} +from 'vscode'; +import * as fs from 'fs'; +import * as path from 'path'; +import * as config from './config'; +import * as constants from './constants'; + +let _context: ExtensionContext; + +export function registerCommands(context: ExtensionContext) { + _context = context; + registerCommand(constants.NotebookExamplesCommand, createNotebookExamplesCommand); +} + +function registerCommand(commandName: string, callback: (...args: any[]) => any, thisArg?: any): Disposable { + const command: Disposable = commands.registerCommand(commandName, callback); + _context.subscriptions.push(command); + return command; +} + +/** + * Displays buil-in Data Table Notebook Examples Quick Pick list. + */ + async function createNotebookExamplesCommand(): Promise { + const notebookQuickPickItems: Array = []; + config.notebookExamples.forEach(notebook => notebookQuickPickItems.push({ + label: `$(notebook) ${notebook.name}`, + description: notebook.description, + detail: notebook.file + })); + const selectedNotebook: QuickPickItem | undefined = + await window.showQuickPick(notebookQuickPickItems, {canPickMany: false}); + if (selectedNotebook) { + const notebookUrl: string | undefined = selectedNotebook.detail; + const extensionPath: string = _context.asAbsolutePath('./'); + if (notebookUrl) { + const notebookUri: Uri = Uri.file(path.join(extensionPath, notebookUrl)); + // open data table example notebook + commands.executeCommand(constants.VSCodeOpenCommand, notebookUri); + } + } +} diff --git a/src/extension/constants.ts b/src/extension/constants.ts index fcd59e3..9c1e4c5 100644 --- a/src/extension/constants.ts +++ b/src/extension/constants.ts @@ -8,3 +8,4 @@ export const ExtensionDisplayName: string = 'Data Table'; // command constants export const NotebookExamplesCommand: string = `${ExtensionId}.notebook.examples`; +export const VSCodeOpenCommand: string = `vscode.open`; diff --git a/src/extension/extension.ts b/src/extension/extension.ts index aa42120..1661e7e 100644 --- a/src/extension/extension.ts +++ b/src/extension/extension.ts @@ -2,12 +2,16 @@ import { ExtensionContext } from 'vscode'; - +import {registerCommands} from './commands'; +import * as constants from './constants'; export function activate(context: ExtensionContext) { - console.log('data.table: actived'); + console.log(`${constants.ExtensionId}: actived`); + + // register data table notebook commands + registerCommands(context); } export function deactivate() { - console.log('data.table: deactivated'); + console.log(`${constants.ExtensionId}: deactivated`); }