浏览代码

Merge pull request #1290 from alexandercbooth/add-close-and-halt

[WIP] feat(notebook): add close and halt to notebook
Steven Silvester 8 年之前
父节点
当前提交
c23e8f8bc1
共有 1 个文件被更改,包括 13 次插入1 次删除
  1. 13 1
      src/notebook/plugin.ts

+ 13 - 1
src/notebook/plugin.ts

@@ -72,6 +72,7 @@ const cmdIds = {
   restartRunAll: 'notebook:restart-runAll',
   switchKernel: 'notebook:switch-kernel',
   clearAllOutputs: 'notebook:clear-outputs',
+  closeAndHalt: 'notebook:close-and-halt',
   run: 'notebook-cells:run',
   runAndAdvance: 'notebook-cells:run-and-advance',
   runAndInsert: 'notebook-cells:run-and-insert',
@@ -265,6 +266,15 @@ function addCommands(app: JupyterLab, services: IServiceManager, tracker: Notebo
       }
     }
   });
+  commands.addCommand(cmdIds.closeAndHalt, {
+    label: 'Close and Halt',
+    execute: () => {
+      let current = tracker.currentWidget;
+      if (current) {
+        current.context.changeKernel(null).then(() => { current.dispose(); });
+      }
+    }
+  });
   commands.addCommand(cmdIds.restartClear, {
     label: 'Restart Kernel & Clear Outputs',
     execute: () => {
@@ -614,7 +624,8 @@ function populatePalette(palette: ICommandPalette): void {
     cmdIds.toggleAllLines,
     cmdIds.editMode,
     cmdIds.commandMode,
-    cmdIds.switchKernel
+    cmdIds.switchKernel,
+    cmdIds.closeAndHalt
   ].forEach(command => { palette.addItem({ command, category }); });
 
   category = 'Notebook Cell Operations';
@@ -672,6 +683,7 @@ function createMenu(app: JupyterLab): Menu {
   menu.addItem({ command: cmdIds.runAll });
   menu.addItem({ command: cmdIds.restart });
   menu.addItem({ command: cmdIds.switchKernel });
+  menu.addItem({ command: cmdIds.closeAndHalt });
   menu.addItem({ type: 'separator' });
   menu.addItem({ type: 'submenu', menu: settings });