From 3349151d4c69d0982484f82cf17b7d7a15a4826c Mon Sep 17 00:00:00 2001 From: Kevin Cunnane Date: Thu, 11 Apr 2019 16:43:27 -0700 Subject: [PATCH] Touchbar icon support in notebooks (#4998) * Touchbar icon support in notebooks - updated shortcut keys to only work if notebook is active - Added icons - Now have 1 "add cell" icon that prompts for code/text. This is useful as there wasn't an icon to differentiate --- extensions/notebook/package.json | 29 +++++++++------- extensions/notebook/package.nls.json | 1 + .../resources/dark/touchbar_add_cell.png | Bin 0 -> 766 bytes .../resources/dark/touchbar_run_cell.png | Bin 0 -> 826 bytes extensions/notebook/src/extension.ts | 32 ++++++++++++++++-- 5 files changed, 47 insertions(+), 15 deletions(-) create mode 100644 extensions/notebook/resources/dark/touchbar_add_cell.png create mode 100644 extensions/notebook/resources/dark/touchbar_run_cell.png 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 0000000000000000000000000000000000000000..4f2e2ad5704b81d23499102c70eb3e50c9838c4f GIT binary patch literal 766 zcmVfu_jo=OH5xhaOL2rcI2JQyA z4V(>}4V(#h5I`4%8p$?AIR&H#2yhaa;xi>me9jj{gxv5oJH~}{Mku6nK_Q(B3h7)> zNauoYPvB{s&zGYeNKLu|fRYd)pX%plkgl9*-6kZwG@~`mrDt!ucYdeq4?0C{g*}EMwbPFKF0^ki=!CwDN%H~s zI35c=)=vPaCH5qw4Ld_$4=xz&Y3>jE+)9i{NiR4{28{$?N^Zrr39+OPFAJYVx?$I& zWY9>=RJZ_3rn?}irAR&FD_2g4K7Hmm!lW+%!N~V(O%?D`${ZgT3$@C@} zBbKyipNvHGIYC029}ap=HXFgu{fChr*|d5&INFA7ard3o-Cszztdr+@3uY=uKLnya zA8Qax!x2S2S2FqoM1}IxMMK9&Llu%+lHOQ}IUJ$8 wl|Q-Xf`6pHRA_K|!I>C8^x*K?eY;YOD-5?t@ouD4U z*&yA(*}$Ga2cZGR{^Z+m>)5xB(63N~eb2f6=wsi{KQXDO< zWjg?P3;gc}09O=>8s#O><`)1Q0bo+oP&wfJx=@$G0N376uKrR93noV7kmim z&U5Khgq=`VKS}$E30Zp#Jv&S+>ZA$9UsO1z3vFK|W5(p(N0ME28xRJJ)gAfW-FbEy z5w13o^~Gr?c1t2Oj0c6AjWp-2K34Lr-0- z345k;k#+ZZ|p*ki_6dcr~iptVJ_&cq1`1AdoHvciFWAP4%RLVrtgAmdzP`qEIQ@+uiAh*QE- zY)xHDsZi}Zc87Ly@(4#??`T@1_G;iG-h4>=YrOu{?z1#W!@@Ppz`TlSy?w&Trh { 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 });