浏览代码

Merge pull request #5390 from ian-r-rose/use_current_filebrowser

Use the current filebrowser for several commands.
Steven Silvester 6 年之前
父节点
当前提交
22e643c871
共有 1 个文件被更改,包括 20 次插入7 次删除
  1. 20 7
      packages/filebrowser-extension/src/index.ts

+ 20 - 7
packages/filebrowser-extension/src/index.ts

@@ -312,7 +312,8 @@ function addCommands(
 
 
   commands.addCommand(CommandIDs.hideBrowser, {
   commands.addCommand(CommandIDs.hideBrowser, {
     execute: () => {
     execute: () => {
-      if (!browser.isHidden) {
+      const widget = tracker.currentWidget;
+      if (widget && !widget.isHidden) {
         app.shell.collapseLeft();
         app.shell.collapseLeft();
       }
       }
     }
     }
@@ -401,8 +402,8 @@ function addCommands(
         return;
         return;
       }
       }
 
 
-      return browser.model.manager.services.contents
-        .getDownloadUrl(browser.selectedItems().next().path)
+      return widget.model.manager.services.contents
+        .getDownloadUrl(widget.selectedItems().next().path)
         .then(url => {
         .then(url => {
           Clipboard.copyToSystem(url);
           Clipboard.copyToSystem(url);
         });
         });
@@ -440,26 +441,38 @@ function addCommands(
 
 
   commands.addCommand(CommandIDs.share, {
   commands.addCommand(CommandIDs.share, {
     execute: () => {
     execute: () => {
-      const path = encodeURI(browser.selectedItems().next().path);
+      const widget = tracker.currentWidget;
+      if (!widget) {
+        return;
+      }
+      const path = encodeURI(widget.selectedItems().next().path);
       const tree = PageConfig.getTreeUrl({ workspace: true });
       const tree = PageConfig.getTreeUrl({ workspace: true });
 
 
       Clipboard.copyToSystem(URLExt.join(tree, path));
       Clipboard.copyToSystem(URLExt.join(tree, path));
     },
     },
-    isVisible: () => toArray(browser.selectedItems()).length === 1,
+    isVisible: () =>
+      tracker.currentWidget &&
+      toArray(tracker.currentWidget.selectedItems()).length === 1,
     iconClass: 'jp-MaterialIcon jp-LinkIcon',
     iconClass: 'jp-MaterialIcon jp-LinkIcon',
     label: 'Copy Shareable Link'
     label: 'Copy Shareable Link'
   });
   });
 
 
   commands.addCommand(CommandIDs.copyPath, {
   commands.addCommand(CommandIDs.copyPath, {
     execute: () => {
     execute: () => {
-      const item = browser.selectedItems().next();
+      const widget = tracker.currentWidget;
+      if (!widget) {
+        return;
+      }
+      const item = widget.selectedItems().next();
       if (!item) {
       if (!item) {
         return;
         return;
       }
       }
 
 
       Clipboard.copyToSystem(item.path);
       Clipboard.copyToSystem(item.path);
     },
     },
-    isVisible: () => browser.selectedItems().next !== undefined,
+    isVisible: () =>
+      tracker.currentWidget &&
+      tracker.currentWidget.selectedItems().next !== undefined,
     iconClass: 'jp-MaterialIcon jp-FileIcon',
     iconClass: 'jp-MaterialIcon jp-FileIcon',
     label: 'Copy Path'
     label: 'Copy Path'
   });
   });