浏览代码

Allow the cwd of the launcher to be updated

Steven Silvester 7 年之前
父节点
当前提交
14194ff216

+ 1 - 1
jupyterlab/package.json

@@ -1,6 +1,7 @@
 {
   "name": "@jupyterlab/application-top",
   "version": "0.10.2",
+  "private": true,
   "scripts": {
     "build": "node update-core.js && webpack",
     "build:prod": "node update-core.js && webpack --devtool source-map",
@@ -86,7 +87,6 @@
     "url-loader": "^0.5.7",
     "webpack": "^2.2.1"
   },
-  "private": true,
   "jupyterlab": {
     "extensions": {
       "@jupyterlab/application-extension": "",

+ 1 - 0
packages/filebrowser-extension/package.json

@@ -18,6 +18,7 @@
     "@jupyterlab/docmanager": "^0.10.0",
     "@jupyterlab/docregistry": "^0.10.0",
     "@jupyterlab/filebrowser": "^0.10.0",
+    "@jupyterlab/launcher": "^0.10.0",
     "@phosphor/algorithm": "^1.1.1",
     "@phosphor/commands": "^1.3.0",
     "@phosphor/widgets": "^1.3.0"

+ 21 - 9
packages/filebrowser-extension/src/index.ts

@@ -25,6 +25,10 @@ import {
   FileBrowserModel, FileBrowser, IFileBrowserFactory
 } from '@jupyterlab/filebrowser';
 
+import {
+  Launcher
+} from '@jupyterlab/launcher';
+
 import {
   each
 } from '@phosphor/algorithm';
@@ -156,9 +160,7 @@ function activateFactory(app: JupyterLab, docManager: IDocumentManager, state: I
     let launcher = new ToolbarButton({
       className: 'jp-AddIcon',
       onClick: () => {
-        return commands.execute('launcher:create', {
-          cwd: widget.model.path
-        });
+        return createLauncher(commands, widget);
       }
     });
     launcher.addClass('jp-MaterialIcon');
@@ -213,9 +215,7 @@ function activateFileBrowser(app: JupyterLab, factory: IFileBrowserFactory, docM
     if (app.shell.isEmpty('main')) {
       // Make sure the model is restored.
       fbWidget.model.restored.then(() => {
-        app.commands.execute('launcher:create', {
-          cwd: fbWidget.model.path
-        });
+        createLauncher(app.commands, fbWidget);
       });
     }
   });
@@ -390,9 +390,7 @@ function addCommands(app: JupyterLab, tracker: InstanceTracker<FileBrowser>, mai
   commands.addCommand(CommandIDs.createLauncher, {
     label: 'New...',
     execute: () => {
-      return commands.execute('launcher:create', {
-        cwd: mainBrowser.model.path,
-      });
+      return createLauncher(commands, mainBrowser);
     }
   });
 }
@@ -457,3 +455,17 @@ function createContextMenu(path: string, commands: CommandRegistry, registry: Do
 
   return menu;
 }
+
+
+/**
+ * Create a launcher for a given filebrowser widget.
+ */
+function createLauncher(commands: CommandRegistry, widget: FileBrowser): Promise<void> {
+  return commands.execute('launcher:create', {
+    cwd: widget.model.path
+  }).then((launcher: Launcher) => {
+    widget.model.pathChanged.connect(() => {
+      launcher.cwd = widget.model.path;
+    }, launcher);
+  });
+}

+ 1 - 0
packages/launcher-extension/src/index.ts

@@ -81,6 +81,7 @@ function activate(app: JupyterLab, palette: ICommandPalette): ILauncher {
       if (args['activate'] !== false) {
         shell.activateById(widget.id);
       }
+      return widget;
     }
   });
 

+ 9 - 3
packages/launcher/src/index.tsx

@@ -232,7 +232,7 @@ class Launcher extends VDomRenderer<LauncherModel> {
    */
   constructor(options: Launcher.IOptions) {
     super();
-    this.cwd = options.cwd;
+    this._cwd = options.cwd;
     this._callback = options.callback;
     this.addClass(LAUNCHER_CLASS);
   }
@@ -240,7 +240,13 @@ class Launcher extends VDomRenderer<LauncherModel> {
   /**
    * The cwd of the launcher.
    */
-  readonly cwd: string;
+  get cwd(): string {
+    return this._cwd;
+  }
+  set cwd(value: string) {
+    this._cwd = value;
+    this.update();
+  }
 
   /**
    * Whether there is a pending item being launched.
@@ -337,6 +343,7 @@ class Launcher extends VDomRenderer<LauncherModel> {
 
   private _callback: (widget: Widget) => void;
   private _pending = false;
+  private _cwd = '';
 }
 
 
@@ -359,7 +366,6 @@ namespace Launcher {
      * The callback used when an item is launched.
      */
     callback: (widget: Widget) => void;
-
   }
 }