瀏覽代碼

Navigate to current document's current directory

Grant Nestor 6 年之前
父節點
當前提交
83f17d8d1e
共有 1 個文件被更改,包括 14 次插入2 次删除
  1. 14 2
      packages/filebrowser-extension/src/index.ts

+ 14 - 2
packages/filebrowser-extension/src/index.ts

@@ -94,7 +94,7 @@ namespace CommandIDs {
 const browser: JupyterLabPlugin<void> = {
   activate: activateBrowser,
   id: '@jupyterlab/filebrowser-extension:browser',
-  requires: [IFileBrowserFactory, ILayoutRestorer],
+  requires: [IFileBrowserFactory, ILayoutRestorer, IDocumentManager],
   autoStart: true
 };
 
@@ -223,7 +223,8 @@ function activateFactory(
 function activateBrowser(
   app: JupyterLab,
   factory: IFileBrowserFactory,
-  restorer: ILayoutRestorer
+  restorer: ILayoutRestorer,
+  docManager: IDocumentManager
 ): void {
   const browser = factory.defaultBrowser;
   const { commands, shell } = app;
@@ -261,6 +262,17 @@ function activateBrowser(
     shell.layoutModified.connect(() => {
       maybeCreate();
     });
+
+    // Keep the session object on the status item up-to-date.
+    shell.currentChanged.connect((shell, change) => {
+      const { newValue } = change;
+      const context = docManager.contextForWidget(newValue);
+      // const path = `/${PathExt.dirname(context.path)}`;
+      // browser.model.cd(path);
+      commands.execute('filebrowser:activate', { path: context.path });
+      commands.execute('filebrowser:navigate', { path: context.path });
+    });
+
     maybeCreate();
   });
 }