Explorar el Código

Updates for new api

Steven Silvester hace 8 años
padre
commit
510b6ee1b7

+ 25 - 0
src/notebook/notebook/actions.ts

@@ -9,6 +9,10 @@ import {
   MimeData as IClipboard
 } from 'phosphor-dragdrop';
 
+import {
+  showDialog
+} from '../../dialog';
+
 import {
   ICellModel, CodeCellModel,
   CodeCellWidget, BaseCellWidget, MarkdownCellWidget
@@ -582,6 +586,27 @@ namespace NotebookActions {
       }
     }
   }
+
+  /**
+   * Restart a kernel.
+   */
+  export
+  function restart(kernel: IKernel, host?: HTMLElement): Promise<boolean> {
+    if (!kernel) {
+      return Promise.resolve(false);
+    }
+    return showDialog({
+      title: 'Restart Kernel?',
+      body: 'Do you want to restart the current kernel? All variables will be lost.',
+      host
+    }).then(result => {
+      if (result.text === 'OK') {
+        return kernel.restart().then(() => { return true; });
+      } else {
+        return false;
+      }
+    });
+  }
 }
 
 

+ 1 - 1
src/notebook/notebook/default-toolbar.ts

@@ -201,7 +201,7 @@ namespace ToolbarItems {
     return new ToolbarButton({
       className: TOOLBAR_RESTART,
       onClick: () => {
-        panel.restart();
+        NotebookActions.restart(panel.kernel, panel.node);
       },
       tooltip: 'Restart the kernel'
     });

+ 5 - 3
src/notebook/plugin.ts

@@ -261,7 +261,7 @@ function activateNotebookHandler(app: Application, registry: DocumentRegistry, s
     handler: () => {
       if (tracker.activeNotebook) {
         let nbWidget = tracker.activeNotebook;
-        nbWidget.restart();
+        NotebookActions.restart(nbWidget.kernel, nbWidget.node);
       }
     }
   },
@@ -270,7 +270,8 @@ function activateNotebookHandler(app: Application, registry: DocumentRegistry, s
     handler: () => {
       if (tracker.activeNotebook) {
         let nbWidget = tracker.activeNotebook;
-        nbWidget.restart().then(result => {
+        let promise = NotebookActions.restart(nbWidget.kernel, nbWidget.node);
+        promise.then(result => {
           if (result) {
             NotebookActions.clearAllOutputs(nbWidget.content);
           }
@@ -283,7 +284,8 @@ function activateNotebookHandler(app: Application, registry: DocumentRegistry, s
     handler: () => {
       if (tracker.activeNotebook) {
         let nbWidget = tracker.activeNotebook;
-        nbWidget.restart().then(result => {
+        let promise = NotebookActions.restart(nbWidget.kernel, nbWidget.node);
+        promise.then(result => {
           NotebookActions.runAll(nbWidget.content, nbWidget.context.kernel);
         });
       }