Browse Source

Merge pull request #2230 from blink1073/fix-remove-widget

Remove uses of removeWidget
Afshin Darian 8 years ago
parent
commit
772215f81e

+ 4 - 10
packages/apputils/src/toolbar.ts

@@ -114,6 +114,9 @@ class Toolbar<T extends Widget> extends Widget {
    *
    * @returns Whether the item was added to toolbar.  Returns false if
    *   an item of the same name is already in the toolbar.
+   *
+   * #### Notes
+   * The item can be removed from the toolbar by setting its parent to `null`.
    */
   addItem(name: string, widget: T): boolean {
     let layout = this.layout as PanelLayout;
@@ -134,6 +137,7 @@ class Toolbar<T extends Widget> extends Widget {
    *
    * #### Notes
    * The index will be clamped to the bounds of the items.
+   * The item can be removed from the toolbar by setting its parent to `null`.
    */
   insertItem(index: number, name: string, widget: T): boolean {
     let existing = find(this.names(), value => value === name);
@@ -147,16 +151,6 @@ class Toolbar<T extends Widget> extends Widget {
     return true;
   }
 
-  /**
-   * Remove an item in the toolbar by value.
-   *
-   *  @param name - The name of the widget to remove from the toolbar.
-   */
-  removeItem(widget: T): void {
-    let layout = this.layout as PanelLayout;
-    layout.removeWidget(widget);
-  }
-
   /**
    * Handle the DOM events for the widget.
    *

+ 3 - 3
packages/cells/src/inputarea.ts

@@ -115,9 +115,9 @@ class InputArea extends Widget {
   renderInput(widget: Widget): void {
     let layout = this.layout as PanelLayout;
     if (this._rendered) {
-      layout.removeWidget(this._rendered);
+      this._rendered.parent = null;
     } else {
-      layout.removeWidget(this._editor);
+      this._editor.parent = null;
     }
     this._rendered = widget;
     layout.addWidget(widget);
@@ -129,7 +129,7 @@ class InputArea extends Widget {
   showEditor(): void {
     let layout = this.layout as PanelLayout;
     if (this._rendered) {
-      layout.removeWidget(this._rendered);
+      this._rendered.parent = null;
       layout.addWidget(this._editor);
     }
   }

+ 2 - 1
packages/console/src/widget.ts

@@ -410,7 +410,8 @@ class CodeConsole extends Widget {
       promptCell.readOnly = true;
       promptCell.removeClass(PROMPT_CLASS);
       Signal.clearData(promptCell.editor);
-      (input.layout as PanelLayout).removeWidgetAt(0);
+      let child = input.widgets[0];
+      child.parent = null;
       this.addCell(promptCell);
     }
 

+ 0 - 16
test/src/apputils/toolbar.spec.ts

@@ -134,22 +134,6 @@ describe('@jupyterlab/apputils', () => {
 
     });
 
-    describe('#removeItem()', () => {
-
-      it('should remove the item from the toolbar', () => {
-        widget.addItem('a', new Widget());
-        let b = new Widget();
-        widget.addItem('b', b);
-        expect(widget.removeItem(b)).to.be(void 0);
-      });
-
-      it('should be a no-op the widget is not in the toolbar', () => {
-        widget.addItem('a', new Widget());
-        expect(widget.removeItem(new Widget())).to.be(void 0);
-      });
-
-    });
-
     describe('.createInterruptButton()', () => {
 
       it('should have the `\'jp-StopIcon\'` class', () => {