Skip to content

Commit 5006b66

Browse files
implement data.table.notebook.examples quick pick display and example notebook loading (#75)
1 parent 5c75e39 commit 5006b66

File tree

3 files changed

+59
-3
lines changed

3 files changed

+59
-3
lines changed

src/extension/commands.ts

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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+
}

src/extension/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ export const ExtensionDisplayName: string = 'Data Table';
88

99
// command constants
1010
export const NotebookExamplesCommand: string = `${ExtensionId}.notebook.examples`;
11+
export const VSCodeOpenCommand: string = `vscode.open`;

src/extension/extension.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,16 @@ import {
22
ExtensionContext
33
}
44
from 'vscode';
5-
5+
import {registerCommands} from './commands';
6+
import * as constants from './constants';
67

78
export function activate(context: ExtensionContext) {
8-
console.log('data.table: actived');
9+
console.log(`${constants.ExtensionId}: actived`);
10+
11+
// register data table notebook commands
12+
registerCommands(context);
913
}
1014

1115
export function deactivate() {
12-
console.log('data.table: deactivated');
16+
console.log(`${constants.ExtensionId}: deactivated`);
1317
}

0 commit comments

Comments
 (0)