Selaa lähdekoodia

Close All Widgets functionality added

charnpreetsingh185 8 vuotta sitten
vanhempi
commit
f9350f4740
2 muutettua tiedostoa jossa 29 lisäystä ja 1 poistoa
  1. 13 0
      src/application/shell.ts
  2. 16 1
      src/main/plugin.ts

+ 13 - 0
src/application/shell.ts

@@ -20,6 +20,10 @@ import {
   FocusTracker
 } from 'phosphor/lib/ui/focustracker';
 
+import {
+  each
+} from 'phosphor/lib/algorithm/iteration';
+
 import {
   Panel
 } from 'phosphor/lib/ui/panel';
@@ -242,6 +246,15 @@ class ApplicationShell extends Widget {
     this._rightHandler.collapse();
   }
 
+  /**
+   * Close all tracked widgets.
+   */
+  closeAll(): void {
+    each(this._tracker.widgets, widget => {
+      widget.close();
+    });
+  }
+
   private _topPanel: Panel;
   private _hboxPanel: BoxPanel;
   private _dockPanel: DockPanel;

+ 16 - 1
src/main/plugin.ts

@@ -5,6 +5,10 @@ import {
   JupyterLab, JupyterLabPlugin
 } from '../application';
 
+import {
+  ICommandPalette
+} from '../commandpalette';
+
 
 /**
  * The main extension.
@@ -12,7 +16,18 @@ import {
 export
 const mainExtension: JupyterLabPlugin<void> = {
   id: 'jupyter.extensions.main',
-  activate: (app: JupyterLab) => {
+  requires: [ICommandPalette],
+  activate: (app: JupyterLab, palette: ICommandPalette) => {
+    let commandId = 'main-jupyterlab:closeAll';
+    app.commands.addCommand(commandId, {
+      label: 'Close All Widgets',
+      execute: () => {
+        app.shell.closeAll();
+      }
+    });
+
+    palette.addItem({ command: commandId, category: 'Dock Panel' });
+
     const message = 'Are you sure you want to exit JupyterLab?\n' +
                     'Any unsaved changes will be lost.';