Skip to content

Commit

Permalink
implement data.table.notebook.examples quick pick display and example…
Browse files Browse the repository at this point in the history
… notebook loading (#75)
  • Loading branch information
RandomFractals committed Aug 1, 2021
1 parent 5c75e39 commit 5006b66
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 3 deletions.
51 changes: 51 additions & 0 deletions src/extension/commands.ts
Original file line number Diff line number Diff line change
@@ -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<void> {
const notebookQuickPickItems: Array<QuickPickItem> = [];
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);
}
}
}
1 change: 1 addition & 0 deletions src/extension/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`;
10 changes: 7 additions & 3 deletions src/extension/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`);
}

0 comments on commit 5006b66

Please sign in to comment.