diff --git a/extensions/notebook/package.json b/extensions/notebook/package.json index 40c230a40b..395d664ace 100644 --- a/extensions/notebook/package.json +++ b/extensions/notebook/package.json @@ -57,7 +57,8 @@ }, { "command": "notebook.command.runactivecell", - "title": "%notebook.command.runactivecell%" + "title": "%notebook.command.runactivecell%", + "icon": "resources/dark/touchbar_run_cell.png" }, { "command": "notebook.command.addcode", @@ -67,6 +68,11 @@ "command": "notebook.command.addtext", "title": "%notebook.command.addtext%" }, + { + "command": "notebook.command.addcell", + "title": "%notebook.command.addcell%", + "icon": "resources/dark/touchbar_add_cell.png" + }, { "command": "jupyter.cmd.analyzeNotebook", "title": "%title.analyzeJupyterNotebook%" @@ -147,6 +153,10 @@ "command": "notebook.command.addtext", "when": "notebookEditorVisible" }, + { + "command": "notebook.command.addcell", + "when": "false" + }, { "command": "jupyter.task.newNotebook", "when": "false" @@ -172,17 +182,12 @@ { "command": "notebook.command.runactivecell", "when": "activeEditor == workbench.editor.notebookEditor", - "group": "1_notebook" + "group": "1_notebook@1" }, { - "command": "notebook.command.addcode", + "command": "notebook.command.addcell", "when": "activeEditor == workbench.editor.notebookEditor", - "group": "2_notebook" - }, - { - "command": "notebook.command.addtext", - "when": "activeEditor == workbench.editor.notebookEditor", - "group": "2_notebook" + "group": "1_notebook@2" } ], "objectExplorer/item/context": [ @@ -222,17 +227,17 @@ { "command": "notebook.command.runactivecell", "key": "F5", - "when": "notebookEditorVisible" + "when": "activeEditor == workbench.editor.notebookEditor" }, { "command": "notebook.command.addcode", "key": "Ctrl+Shift+C", - "when": "notebookEditorVisible" + "when": "activeEditor == workbench.editor.notebookEditor" }, { "command": "notebook.command.addtext", "key": "Ctrl+Shift+T", - "when": "notebookEditorVisible" + "when": "activeEditor == workbench.editor.notebookEditor" } ], "notebook.languagemagics": [ diff --git a/extensions/notebook/package.nls.json b/extensions/notebook/package.nls.json index 2117337256..9d5ce3827a 100644 --- a/extensions/notebook/package.nls.json +++ b/extensions/notebook/package.nls.json @@ -11,6 +11,7 @@ "notebook.command.runactivecell": "Run Cell", "notebook.command.addcode": "Add Code Cell", "notebook.command.addtext": "Add Text Cell", + "notebook.command.addcell": "Add Cell", "title.analyzeJupyterNotebook": "Analyze in Notebook", "title.newJupyterNotebook": "New Notebook", "title.openJupyterNotebook": "Open Notebook", diff --git a/extensions/notebook/resources/dark/touchbar_add_cell.png b/extensions/notebook/resources/dark/touchbar_add_cell.png new file mode 100644 index 0000000000..4f2e2ad570 Binary files /dev/null and b/extensions/notebook/resources/dark/touchbar_add_cell.png differ diff --git a/extensions/notebook/resources/dark/touchbar_run_cell.png b/extensions/notebook/resources/dark/touchbar_run_cell.png new file mode 100644 index 0000000000..38a87d3db0 Binary files /dev/null and b/extensions/notebook/resources/dark/touchbar_run_cell.png differ diff --git a/extensions/notebook/src/extension.ts b/extensions/notebook/src/extension.ts index 9dc5dc1351..1c925b59f5 100644 --- a/extensions/notebook/src/extension.ts +++ b/extensions/notebook/src/extension.ts @@ -14,14 +14,16 @@ import { JupyterController } from './jupyter/jupyterController'; import { AppContext } from './common/appContext'; import { ApiWrapper } from './common/apiWrapper'; import { IExtensionApi } from './types'; +import { CellType } from './contracts/content'; const localize = nls.loadMessageBundle(); const JUPYTER_NOTEBOOK_PROVIDER = 'jupyter'; -const msgSampleCodeDataFrame = localize('msgSampleCodeDataFrame', 'This sample code loads the file into a data frame and shows the first 10 results.'); -const noNotebookVisible = localize('noNotebookVisible', 'No notebook editor is active'); +const msgSampleCodeDataFrame = localize('msgSampleCodeDataFrame', "This sample code loads the file into a data frame and shows the first 10 results."); +const noNotebookVisible = localize('noNotebookVisible', "No notebook editor is active"); let controller: JupyterController; +type ChooseCellType = { label: string, id: CellType}; export async function activate(extensionContext: vscode.ExtensionContext): Promise { extensionContext.subscriptions.push(vscode.commands.registerCommand('notebook.command.new', (context?: azdata.ConnectedContext) => { @@ -37,6 +39,30 @@ export async function activate(extensionContext: vscode.ExtensionContext): Promi extensionContext.subscriptions.push(vscode.commands.registerCommand('notebook.command.runactivecell', () => { runActiveCell(); })); + extensionContext.subscriptions.push(vscode.commands.registerCommand('notebook.command.addcell', async () => { + let cellType: CellType; + try { + let cellTypes: ChooseCellType[] = [{ + label: localize('codeCellName', "Code"), + id: 'code' + }, + { + label: localize('textCellName', "Text"), + id: 'markdown' + }]; + let selection = await vscode.window.showQuickPick(cellTypes, { + placeHolder: localize('selectCellType', "What type of cell do you want to add?") + }); + if (selection) { + cellType = selection.id; + } + } catch (err) { + return; + } + if (cellType) { + addCell(cellType); + } + })); extensionContext.subscriptions.push(vscode.commands.registerCommand('notebook.command.addcode', () => { addCell('code'); })); @@ -97,7 +123,7 @@ async function openNotebook(): Promise { try { let filter = {}; // TODO support querying valid notebook file types - filter[localize('notebookFiles', 'Notebooks')] = ['ipynb']; + filter[localize('notebookFiles', "Notebooks")] = ['ipynb']; let file = await vscode.window.showOpenDialog({ filters: filter });