浏览代码

Always add a dock panel child to the shell’s focus tracker. (#3310)

* Add test for removing a widget from the tracker

* Put a dock panel child in the focus tracker exactly when it is in the dock panel.

Fixes #3309

* Make the child hook a private instance property.

Thanks to @blink1073 for the suggestion.

* Move callback definition out of the constructor.
Jason Grout 7 年之前
父节点
当前提交
7187812299
共有 2 个文件被更改,包括 22 次插入21 次删除
  1. 20 21
      packages/application/src/shell.ts
  2. 2 0
      test/src/application/shell.spec.ts

+ 20 - 21
packages/application/src/shell.ts

@@ -72,7 +72,7 @@ class ApplicationShell extends Widget {
     let topPanel = this._topPanel = new Panel();
     let topPanel = this._topPanel = new Panel();
     let hboxPanel = this._hboxPanel = new BoxPanel();
     let hboxPanel = this._hboxPanel = new BoxPanel();
     let dockPanel = this._dockPanel = new DockPanel();
     let dockPanel = this._dockPanel = new DockPanel();
-    MessageLoop.installMessageHook(dockPanel, Private.activityClassHook);
+    MessageLoop.installMessageHook(dockPanel, this._dockChildHook);
 
 
     let hsplitPanel = this._hsplitPanel = new SplitPanel();
     let hsplitPanel = this._hsplitPanel = new SplitPanel();
     let leftHandler = this._leftHandler = new Private.SideBarHandler('left');
     let leftHandler = this._leftHandler = new Private.SideBarHandler('left');
@@ -369,7 +369,6 @@ class ApplicationShell extends Widget {
     }
     }
 
 
     dock.addWidget(widget, { mode: 'tab-after', ref });
     dock.addWidget(widget, { mode: 'tab-after', ref });
-    this._tracker.add(widget);
   }
   }
 
 
   /**
   /**
@@ -609,6 +608,25 @@ class ApplicationShell extends Widget {
     this._layoutModified.emit(void 0);
     this._layoutModified.emit(void 0);
   }
   }
 
 
+  /**
+   * A message hook for child add/remove messages on the main area dock panel.
+   */
+  private _dockChildHook = (handler: IMessageHandler, msg: Message): boolean => {
+    switch (msg.type) {
+      case 'child-added':
+        (msg as Widget.ChildMessage).child.addClass(ACTIVITY_CLASS);
+        this._tracker.add((msg as Widget.ChildMessage).child);
+        break;
+      case 'child-removed':
+        (msg as Widget.ChildMessage).child.removeClass(ACTIVITY_CLASS);
+        this._tracker.remove((msg as Widget.ChildMessage).child);
+        break;
+      default:
+        break;
+    }
+    return true;
+  };
+
   private _activeChanged = new Signal<this, ApplicationShell.IChangedArgs>(this);
   private _activeChanged = new Signal<this, ApplicationShell.IChangedArgs>(this);
   private _cachedLayout: DockLayout.ILayoutConfig | null = null;
   private _cachedLayout: DockLayout.ILayoutConfig | null = null;
   private _currentChanged = new Signal<this, ApplicationShell.IChangedArgs>(this);
   private _currentChanged = new Signal<this, ApplicationShell.IChangedArgs>(this);
@@ -971,24 +989,5 @@ namespace Private {
     private _stackedPanel: StackedPanel;
     private _stackedPanel: StackedPanel;
   }
   }
 
 
-  /**
-   * A message hook that adds and removes the .jp-Activity class to widgets in the dock panel.
-   */
-  export
-  function activityClassHook(handler: IMessageHandler, msg: Message): boolean {
-    switch (msg.type) {
-      case 'child-added':
-        (msg as Widget.ChildMessage).child.addClass(ACTIVITY_CLASS);
-        break;
-      case 'child-removed':
-        (msg as Widget.ChildMessage).child.removeClass(ACTIVITY_CLASS);
-        break;
-      default:
-        break;
-    }
-
-    return true;
-  }
-
 }
 }
 
 

+ 2 - 0
test/src/application/shell.spec.ts

@@ -62,6 +62,8 @@ describe('ApplicationShell', () => {
       expect(shell.currentWidget).to.be(null);
       expect(shell.currentWidget).to.be(null);
       simulate(widget.node, 'focus');
       simulate(widget.node, 'focus');
       expect(shell.currentWidget).to.be(widget);
       expect(shell.currentWidget).to.be(widget);
+      widget.parent = null;
+      expect(shell.currentWidget).to.be(null);
     });
     });
 
 
   });
   });