Skip to content

Commit

Permalink
added command for restart and run to selected
Browse files Browse the repository at this point in the history
  • Loading branch information
markellekelly committed Jan 16, 2020
1 parent ac3ab8c commit 1fbc8d5
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions packages/notebook-extension/src/index.ts
Expand Up @@ -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';
Expand Down Expand Up @@ -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 => {
Expand Down Expand Up @@ -1918,6 +1948,7 @@ function populatePalette(
CommandIDs.renderAllMarkdown,
CommandIDs.runAllAbove,
CommandIDs.runAllBelow,
CommandIDs.restartAndRunToSelected,
CommandIDs.selectAll,
CommandIDs.deselectAll,
CommandIDs.clearAllOutputs,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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({
Expand Down

0 comments on commit 1fbc8d5

Please sign in to comment.