|
| 1 | +import { |
| 2 | + ExtensionContext, |
| 3 | + Disposable, |
| 4 | + QuickPickItem, |
| 5 | + ViewColumn, |
| 6 | + Uri, |
| 7 | + commands, |
| 8 | + window, |
| 9 | + workspace |
| 10 | +} |
| 11 | +from 'vscode'; |
| 12 | +import * as fs from 'fs'; |
| 13 | +import * as path from 'path'; |
| 14 | +import * as config from './config'; |
| 15 | +import * as constants from './constants'; |
| 16 | + |
| 17 | +let _context: ExtensionContext; |
| 18 | + |
| 19 | +export function registerCommands(context: ExtensionContext) { |
| 20 | + _context = context; |
| 21 | + registerCommand(constants.NotebookExamplesCommand, createNotebookExamplesCommand); |
| 22 | +} |
| 23 | + |
| 24 | +function registerCommand(commandName: string, callback: (...args: any[]) => any, thisArg?: any): Disposable { |
| 25 | + const command: Disposable = commands.registerCommand(commandName, callback); |
| 26 | + _context.subscriptions.push(command); |
| 27 | + return command; |
| 28 | +} |
| 29 | + |
| 30 | +/** |
| 31 | + * Displays buil-in Data Table Notebook Examples Quick Pick list. |
| 32 | + */ |
| 33 | + async function createNotebookExamplesCommand(): Promise<void> { |
| 34 | + const notebookQuickPickItems: Array<QuickPickItem> = []; |
| 35 | + config.notebookExamples.forEach(notebook => notebookQuickPickItems.push({ |
| 36 | + label: `$(notebook) ${notebook.name}`, |
| 37 | + description: notebook.description, |
| 38 | + detail: notebook.file |
| 39 | + })); |
| 40 | + const selectedNotebook: QuickPickItem | undefined = |
| 41 | + await window.showQuickPick(notebookQuickPickItems, {canPickMany: false}); |
| 42 | + if (selectedNotebook) { |
| 43 | + const notebookUrl: string | undefined = selectedNotebook.detail; |
| 44 | + const extensionPath: string = _context.asAbsolutePath('./'); |
| 45 | + if (notebookUrl) { |
| 46 | + const notebookUri: Uri = Uri.file(path.join(extensionPath, notebookUrl)); |
| 47 | + // open data table example notebook |
| 48 | + commands.executeCommand(constants.VSCodeOpenCommand, notebookUri); |
| 49 | + } |
| 50 | + } |
| 51 | +} |
0 commit comments