浏览代码

Merge pull request #20 from blink1073/set-active

Set the widget as active when opened
A. Darian 9 年之前
父节点
当前提交
3239e1c7f6
共有 2 个文件被更改,包括 21 次插入4 次删除
  1. 2 1
      package.json
  2. 19 3
      src/fileopener/plugin.ts

+ 2 - 1
package.json

@@ -15,7 +15,8 @@
     "phosphor-codemirror": "^0.0.1",
     "phosphor-command": "^0.5.0",
     "phosphor-di": "^0.9.0",
-    "phosphor-properties": "^2.0.0"
+    "phosphor-properties": "^2.0.0",
+    "phosphor-tabs": "^1.0.0-rc.2"
   },
   "devDependencies": {
     "css-loader": "^0.23.1",

+ 19 - 3
src/fileopener/plugin.ts

@@ -22,6 +22,10 @@ import {
   Property
 } from 'phosphor-properties';
 
+import {
+  TabPanel
+} from 'phosphor-tabs';
+
 import {
   Widget
 } from 'phosphor-widget';
@@ -205,11 +209,23 @@ class FileOpener implements IFileOpener {
   }
 
   /**
-   * Open a file and add it to the application shell.
+   * Open a file and add it to the application shell and give it focus.
    */
   private _open(handler: IFileHandler, path: string): Widget {
-    var widget = handler.open(path);
-    this._appShell.addToMainArea(widget);
+    let widget = handler.open(path);
+    if (!widget.isAttached) {
+      this._appShell.addToMainArea(widget);
+    }
+    let parent = widget.parent;
+    while (parent) {
+      if (parent instanceof TabPanel) {
+        if ((parent as TabPanel).childIndex(widget) !== -1) {
+          (parent as TabPanel).currentWidget = widget;
+          return widget;
+        }
+      }
+      parent = parent.parent;
+    }
     return widget;
   }