浏览代码

Activate console panel on mousedown.

Afshin Darian 8 年之前
父节点
当前提交
ba780c3dda
共有 1 个文件被更改,包括 39 次插入0 次删除
  1. 39 0
      src/console/panel.ts

+ 39 - 0
src/console/panel.ts

@@ -78,6 +78,41 @@ class ConsolePanel extends Panel {
     super.dispose();
   }
 
+  /**
+   * Handle the DOM events for the widget.
+   *
+   * @param event - The DOM event sent to the widget.
+   *
+   * #### Notes
+   * This method implements the DOM `EventListener` interface and is
+   * called in response to events on the console panel's node. It should
+   * not be called directly by user code.
+   */
+  handleEvent(event: Event): void {
+    switch (event.type) {
+    case 'mousedown':
+      this._evtMouseDown(event as MouseEvent);
+      break;
+    default:
+      break;
+    }
+  }
+
+  /**
+   * Handle `after_attach` messages for the widget.
+   */
+  protected onAfterAttach(msg: Message): void {
+    super.onAfterAttach(msg);
+    this.node.addEventListener('mousedown', this);
+  }
+
+  /**
+   * Handle `before_detach` messages for the widget.
+   */
+  protected onBeforeDetach(msg: Message): void {
+    this.node.removeEventListener('mousedown', this);
+  }
+
   /**
    * Handle `'activate-request'` messages.
    */
@@ -111,6 +146,10 @@ class ConsolePanel extends Panel {
     });
   }
 
+  private _evtMouseDown(event: MouseEvent): void {
+    this.activate();
+  }
+
   private _content: ConsoleContent = null;
 }