Forráskód Böngészése

Bug fix: create `filebrowser:open` command to use for file browser context menu.

Afshin Darian 8 éve
szülő
commit
0e5bb60e16

+ 3 - 4
packages/docmanager/src/manager.ts

@@ -335,12 +335,11 @@ class DocumentManager implements IDisposable {
    */
   openOrReveal(path: string, widgetName='default', kernel?: Kernel.IModel): Widget {
     let widget = this.findWidget(path, widgetName);
-    if (!widget) {
-      widget = this.open(path, widgetName, kernel);
-    } else {
+    if (widget) {
       this._opener.open(widget);
+      return widget;
     }
-    return widget;
+    return this.open(path, widgetName, kernel);
   }
 
   /**

+ 18 - 8
packages/filebrowser-extension/src/index.ts

@@ -52,6 +52,9 @@ namespace CommandIDs {
   export
   const hideBrowser = 'filebrowser-main:hide'; // For main browser only.
 
+  export
+  const open = 'filebrowser:open';
+
   export
   const paste = 'filebrowser:paste';
 
@@ -275,6 +278,20 @@ function addCommands(app: JupyterLab, tracker: InstanceTracker<FileBrowser>, mai
     }
   });
 
+  commands.addCommand(CommandIDs.open, {
+    execute: () => {
+      const widget = tracker.currentWidget;
+      if (!widget) {
+        return;
+      }
+
+      return widget.open();
+    },
+    icon: 'jp-MaterialIcon jp-OpenFolderIcon',
+    label: 'Open',
+    mnemonic: 0,
+  });
+
   commands.addCommand(CommandIDs.paste, {
     execute: () => {
       const widget = tracker.currentWidget;
@@ -343,14 +360,7 @@ function createContextMenu(fbWidget: FileBrowser, openWith: Menu):  Menu {
   const { commands } = fbWidget;
   const menu = new Menu({ commands });
 
-  menu.addItem({
-    command: 'file-operations:open',
-    args: {
-      icon: 'jp-MaterialIcon jp-OpenFolderIcon',
-      label: 'Open',
-      mnemonic: 0
-    }
-  });
+  menu.addItem({ command: CommandIDs.open });
 
   if (openWith) {
     menu.addItem({ type: 'submenu', submenu: openWith });