From 1fbc8d5629575f950e7dba2b15a0c29b28d1e61f Mon Sep 17 00:00:00 2001 From: markellekelly Date: Thu, 16 Jan 2020 08:37:44 -0800 Subject: [PATCH 1/2] added command for restart and run to selected --- packages/notebook-extension/src/index.ts | 37 ++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/packages/notebook-extension/src/index.ts b/packages/notebook-extension/src/index.ts index bb95f0ff1cce..0f79373fdd56 100644 --- a/packages/notebook-extension/src/index.ts +++ b/packages/notebook-extension/src/index.ts @@ -133,6 +133,8 @@ namespace CommandIDs { export const runAllBelow = 'notebook:run-all-below'; + export const restartAndRunToSelected = 'notebook:restart-and-run-to-selected'; + export const renderAllMarkdown = 'notebook:render-all-markdown'; export const toCode = 'notebook:change-cell-to-code'; @@ -1249,6 +1251,34 @@ function addCommands( }, isEnabled }); + commands.addCommand(CommandIDs.restartAndRunToSelected, { + label: 'Restart Kernel and Run up to Selected Cell…', + execute: args => { + const current = getCurrent(args); + + if (current) { + const { context, content } = current; + return sessionDialogs! + .restart(current.sessionContext) + .then(restarted => { + if (restarted) { + void NotebookActions.runAllAbove( + content, + context.sessionContext + ).then(executed => { + if (executed) { + void NotebookActions.run(content, context.sessionContext); + } + }); + } + }); + } + }, + isEnabled: () => { + // Can't run if there are multiple cells selected + return isEnabledAndSingleSelected(); + } + }); commands.addCommand(CommandIDs.restartRunAll, { label: 'Restart Kernel and Run All Cells…', execute: args => { @@ -1918,6 +1948,7 @@ function populatePalette( CommandIDs.renderAllMarkdown, CommandIDs.runAllAbove, CommandIDs.runAllBelow, + CommandIDs.restartAndRunToSelected, CommandIDs.selectAll, CommandIDs.deselectAll, CommandIDs.clearAllOutputs, @@ -2208,6 +2239,11 @@ function populateMenus( return { command }; }); + // Add a restart and run to group to the run menu. + const restartRunGroup = [CommandIDs.restartAndRunToSelected].map(command => { + return { command }; + }); + // Add commands to the application edit menu. const undoCellActionGroup = [ CommandIDs.undoCellAction, @@ -2251,6 +2287,7 @@ function populateMenus( mainMenu.runMenu.addGroup(runExtras, 10); mainMenu.runMenu.addGroup(runAboveBelowGroup, 11); mainMenu.runMenu.addGroup(renderAllMarkdown, 12); + mainMenu.runMenu.addGroup(restartRunGroup, 13); // Add kernel information to the application help menu. mainMenu.helpMenu.kernelUsers.add({ From 804d0f4546d035534434a4c98ec90d09e0c593f9 Mon Sep 17 00:00:00 2001 From: markellekelly Date: Thu, 16 Jan 2020 09:07:14 -0800 Subject: [PATCH 2/2] moved to kernel menu --- packages/mainmenu-extension/src/index.ts | 3 +++ packages/notebook-extension/src/index.ts | 13 +++---------- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/packages/mainmenu-extension/src/index.ts b/packages/mainmenu-extension/src/index.ts index 98427ef72d2c..83ecd74d20db 100644 --- a/packages/mainmenu-extension/src/index.ts +++ b/packages/mainmenu-extension/src/index.ts @@ -71,6 +71,8 @@ export namespace CommandIDs { export const restartKernelAndClear = 'kernelmenu:restart-and-clear'; + export const restartAndRunToSelected = 'notebook:restart-and-run-to-selected'; + export const changeKernel = 'kernelmenu:change'; export const shutdownKernel = 'kernelmenu:shutdown'; @@ -547,6 +549,7 @@ export function createKernelMenu(app: JupyterFrontEnd, menu: KernelMenu): void { const restartGroup = [ CommandIDs.restartKernel, CommandIDs.restartKernelAndClear, + CommandIDs.restartAndRunToSelected, CommandIDs.restartAndRunAll ].map(command => { return { command }; diff --git a/packages/notebook-extension/src/index.ts b/packages/notebook-extension/src/index.ts index 0f79373fdd56..32aded4a56c7 100644 --- a/packages/notebook-extension/src/index.ts +++ b/packages/notebook-extension/src/index.ts @@ -101,6 +101,8 @@ namespace CommandIDs { export const restartClear = 'notebook:restart-clear-output'; + export const restartAndRunToSelected = 'notebook:restart-and-run-to-selected'; + export const restartRunAll = 'notebook:restart-run-all'; export const reconnectToKernel = 'notebook:reconnect-to-kernel'; @@ -133,8 +135,6 @@ namespace CommandIDs { export const runAllBelow = 'notebook:run-all-below'; - export const restartAndRunToSelected = 'notebook:restart-and-run-to-selected'; - export const renderAllMarkdown = 'notebook:render-all-markdown'; export const toCode = 'notebook:change-cell-to-code'; @@ -1255,7 +1255,6 @@ function addCommands( label: 'Restart Kernel and Run up to Selected Cell…', execute: args => { const current = getCurrent(args); - if (current) { const { context, content } = current; return sessionDialogs! @@ -1266,7 +1265,7 @@ function addCommands( content, context.sessionContext ).then(executed => { - if (executed) { + if (executed || content.activeCellIndex === 0) { void NotebookActions.run(content, context.sessionContext); } }); @@ -2239,11 +2238,6 @@ function populateMenus( return { command }; }); - // Add a restart and run to group to the run menu. - const restartRunGroup = [CommandIDs.restartAndRunToSelected].map(command => { - return { command }; - }); - // Add commands to the application edit menu. const undoCellActionGroup = [ CommandIDs.undoCellAction, @@ -2287,7 +2281,6 @@ function populateMenus( mainMenu.runMenu.addGroup(runExtras, 10); mainMenu.runMenu.addGroup(runAboveBelowGroup, 11); mainMenu.runMenu.addGroup(renderAllMarkdown, 12); - mainMenu.runMenu.addGroup(restartRunGroup, 13); // Add kernel information to the application help menu. mainMenu.helpMenu.kernelUsers.add({