소스 검색

Add run all above/below commands for the notebook.

Ian Rose 7 년 전
부모
커밋
a2a872df70
2개의 변경된 파일69개의 추가작업 그리고 1개의 파일을 삭제
  1. 11 1
      packages/notebook-extension/src/index.ts
  2. 58 0
      packages/notebook/src/actions.ts

+ 11 - 1
packages/notebook-extension/src/index.ts

@@ -1302,7 +1302,7 @@ function populateMenus(app: JupyterLab, mainMenu: IMainMenu, tracker: INotebookT
   // Add a clearer to the edit menu
   mainMenu.editMenu.clearers.set('Notebook', {
     tracker,
-    noun: 'All Cells',
+    noun: 'All Cell Outputs',
     clear: (current: NotebookPanel) => {
       return NotebookActions.clearAllOutputs(current.notebook);
     }
@@ -1405,6 +1405,16 @@ function populateMenus(app: JupyterLab, mainMenu: IMainMenu, tracker: INotebookT
       const { context, notebook } = current;
       return NotebookActions.runAll(notebook, context.session)
       .then(() => void 0);
+    },
+    runAbove: current => {
+      const { context, notebook } = current;
+      return NotebookActions.runAllAbove(notebook, context.session)
+      .then(() => void 0);
+    },
+    runBelow: current => {
+      const { context, notebook } = current;
+      return NotebookActions.runAllBelow(notebook, context.session)
+      .then(() => void 0);
     }
   } as IRunMenu.ICodeRunner<NotebookPanel>);
 

+ 58 - 0
packages/notebook/src/actions.ts

@@ -466,6 +466,64 @@ namespace NotebookActions {
     return promise;
   }
 
+  /**
+   * Run all of the cells before the currently active cell (exclusive).
+   *
+   * @param widget - The target notebook widget.
+   *
+   * @param session - The optional client session object.
+   *
+   * #### Notes
+   * The existing selection will be cleared.
+   * An execution error will prevent the remaining code cells from executing.
+   * All markdown cells will be rendered.
+   * The currently active cell will remain selected.
+   */
+  export
+  function runAllAbove(widget: Notebook, session?: IClientSession): Promise<boolean> {
+    if (!widget.model || !widget.activeCell || widget.activeCellIndex === 0) {
+      return Promise.resolve(false);
+    }
+    let state = Private.getState(widget);
+    widget.activeCellIndex--;
+    widget.deselectAll();
+    for (let i = 0; i < widget.activeCellIndex; ++i) {
+      widget.select(widget.widgets[i]);
+    }
+    let promise = Private.runSelected(widget, session);
+    widget.activeCellIndex++;
+    Private.handleRunState(widget, state, true);
+    return promise;
+  }
+
+  /**
+   * Run all of the cells after the currently active cell (inclusive).
+   *
+   * @param widget - The target notebook widget.
+   *
+   * @param session - The optional client session object.
+   *
+   * #### Notes
+   * The existing selection will be cleared.
+   * An execution error will prevent the remaining code cells from executing.
+   * All markdown cells will be rendered.
+   * The last cell in the notebook will be activated and scrolled into view.
+   */
+  export
+  function runAllBelow(widget: Notebook, session?: IClientSession): Promise<boolean> {
+    if (!widget.model || !widget.activeCell) {
+      return Promise.resolve(false);
+    }
+    let state = Private.getState(widget);
+    widget.deselectAll();
+    for (let i = widget.activeCellIndex; i < widget.widgets.length; ++i) {
+      widget.select(widget.widgets[i]);
+    }
+    let promise = Private.runSelected(widget, session);
+    Private.handleRunState(widget, state, true);
+    return promise;
+  }
+
   /**
    * Select the above the active cell.
    *