浏览代码

dialog cleanup

Steven Silvester 7 年之前
父节点
当前提交
ba5aff1439

+ 12 - 5
packages/apputils/src/clientsession.ts

@@ -380,6 +380,9 @@ class ClientSession implements IClientSession {
       this._session.dispose();
       this._session = null;
     }
+    if (this._dialog) {
+      this._dialog.dispose();
+    }
     Signal.clearData(this);
   }
 
@@ -592,11 +595,13 @@ class ClientSession implements IClientSession {
     if (this.isDisposed) {
       return Promise.resolve(void 0);
     }
-    return showDialog({
+    let dialog = this._dialog = new Dialog({
       title: 'Select Kernel',
       body: new Private.KernelSelector(this),
       buttons: [Dialog.cancelButton(), Dialog.okButton({ label: 'SELECT' })]
-    }).then(result => {
+    });
+
+    return dialog.launch().then(result => {
       if (this.isDisposed || !result.button.accept) {
         return;
       }
@@ -607,7 +612,7 @@ class ClientSession implements IClientSession {
       if (model) {
         return this._changeKernel(model).then(() => void 0);
       }
-    }).then(() => void 0);
+    }).then(() => { this._dialog = null; });
   }
 
   /**
@@ -677,12 +682,13 @@ class ClientSession implements IClientSession {
       } catch (err) {
         // no-op
       }
-      return showDialog({
+      let dialog = this._dialog = new Dialog({
         title: 'Error Starting Kernel',
         body: h.pre(message),
         buttons: [Dialog.okButton()]
       });
-    }).then(() => undefined);
+      return dialog.launch();
+    }).then(() => { this._dialog = null; });
   }
 
   /**
@@ -758,6 +764,7 @@ class ClientSession implements IClientSession {
   private _iopubMessage = new Signal<this, KernelMessage.IMessage>(this);
   private _unhandledMessage = new Signal<this, KernelMessage.IMessage>(this);
   private _propertyChanged = new Signal<this, 'path' | 'name' | 'type'>(this);
+  private _dialog: Dialog<any> | null = null;
 }
 
 

+ 1 - 1
packages/apputils/src/dialog.ts

@@ -466,7 +466,7 @@ namespace Dialog {
    * A widget used as a dialog body.
    */
   export
-  interface IBodyWidget<T> extends Widget {
+  interface IBodyWidget<T = string> extends Widget {
     /**
      * Get the serialized value of the widget.
      */

+ 1 - 0
packages/console/src/panel.ts

@@ -123,6 +123,7 @@ class ConsolePanel extends Panel {
    * Dispose of the resources held by the widget.
    */
   dispose(): void {
+    this.session.dispose();
     this.console.dispose();
     super.dispose();
   }

+ 0 - 1
test/src/console/panel.spec.ts

@@ -137,7 +137,6 @@ describe('console/panel', () => {
         MessageLoop.sendMessage(panel, Widget.Msg.CloseRequest);
         expect(panel.methods).to.contain('onCloseRequest');
         expect(panel.isDisposed).to.be(true);
-        return dismissDialog();
       });
 
     });