浏览代码

Propagate dispose from CellModel to OutputAreaModel to OutputAreaWidget.

danielballan 8 年之前
父节点
当前提交
041e488396
共有 3 个文件被更改,包括 33 次插入0 次删除
  1. 1 0
      src/notebook/cells/model.ts
  2. 11 0
      src/notebook/output-area/model.ts
  3. 21 0
      src/notebook/output-area/widget.ts

+ 1 - 0
src/notebook/cells/model.ts

@@ -410,6 +410,7 @@ class CodeCellModel extends CellModel implements ICodeCellModel {
       return;
     }
     this._outputs.clear(false);
+    this._outputs.dispose();
     this._outputs = null;
     super.dispose();
   }

+ 11 - 0
src/notebook/output-area/model.ts

@@ -42,6 +42,14 @@ class OutputAreaModel implements IDisposable {
     return Private.changedSignal.bind(this);
   }
 
+  /**
+   * A signal emitted when the model is disposed.
+   */
+  get disposed(): ISignal<OutputAreaModel, void> {
+    console.log('get model disposed signal')
+    return Private.disposedSignal.bind(this);
+  }
+
   /**
    * Get the length of the items in the model.
    *
@@ -69,6 +77,7 @@ class OutputAreaModel implements IDisposable {
     if (this.isDisposed) {
       return;
     }
+    this.disposed.emit(void 0);
     this._list.clear();
     this._list = null;
     clearSignalData(this);
@@ -199,4 +208,6 @@ namespace Private {
    */
   export
   const changedSignal = new Signal<OutputAreaModel, IListChangedArgs<nbformat.IOutput>>();
+  export
+  const disposedSignal = new Signal<OutputAreaModel, void>();
 }

+ 21 - 0
src/notebook/output-area/widget.ts

@@ -158,6 +158,13 @@ class OutputAreaWidget extends Widget {
      return Private.modelChangedSignal.bind(this);
   }
 
+  /**
+   * A signal emitted when the widget's model is disposed.
+   */
+  get modelDisposed(): ISignal<OutputAreaWidget, void> {
+     return Private.modelDisposedSignal.bind(this);
+  }
+
   /**
    * The model for the widget.
    */
@@ -305,8 +312,10 @@ class OutputAreaWidget extends Widget {
     let layout = this.layout as PanelLayout;
     if (oldValue) {
       oldValue.changed.disconnect(this._onModelStateChanged, this);
+      oldValue.disposed.disconnect(this._onModelDisposed, this);
     }
     newValue.changed.connect(this._onModelStateChanged, this);
+    newValue.disposed.connect(this._onModelDisposed, this);
     let start = newValue ? newValue.length : 0;
     // Clear unnecessary child widgets.
     for (let i = start; i < layout.childCount(); i++) {
@@ -325,6 +334,16 @@ class OutputAreaWidget extends Widget {
     }
   }
 
+  /**
+   * Handle a model disposal.
+   */
+  protected onModelDisposed(oldValue: OutputAreaModel, newValue: OutputAreaModel): void { }
+
+  private _onModelDisposed(): void {
+    this.modelDisposed.emit(void 0);
+    this.dispose();
+  }
+
   /**
    * Add a child to the layout.
    */
@@ -879,4 +898,6 @@ namespace Private {
    */
   export
   const modelChangedSignal = new Signal<OutputAreaWidget, void>();
+  export
+  const modelDisposedSignal = new Signal<OutputAreaWidget, void>();
 }