Browse Source

fix: 右键菜单 download 显隐

zhouxinmin 1 year ago
parent
commit
b9d3045283
1 changed files with 46 additions and 42 deletions
  1. 46 42
      packages/filebrowser-extension/src/index.ts

+ 46 - 42
packages/filebrowser-extension/src/index.ts

@@ -46,7 +46,7 @@ import {
   closeIcon,
   copyIcon,
   cutIcon,
-  // downloadIcon,
+  downloadIcon,
   editIcon,
   fileIcon,
   folderIcon,
@@ -330,50 +330,50 @@ const factory: JupyterFrontEndPlugin<IFileBrowserFactory> = {
  * Users will still be able to retrieve files from the file download URLs the
  * server provides.
  */
-// const downloadPlugin: JupyterFrontEndPlugin<void> = {
-//   id: '@jupyterlab/filebrowser-extension:download',
-//   requires: [IFileBrowserFactory, ITranslator],
-//   autoStart: true,
-//   activate: (
-//     app: JupyterFrontEnd,
-//     factory: IFileBrowserFactory,
-//     translator: ITranslator
-//   ): void => {
-//     const trans = translator.load('jupyterlab');
-//     const { commands } = app;
-//     const { tracker } = factory;
+const downloadPlugin: JupyterFrontEndPlugin<void> = {
+  id: '@jupyterlab/filebrowser-extension:download',
+  requires: [IFileBrowserFactory, ITranslator],
+  autoStart: true,
+  activate: (
+    app: JupyterFrontEnd,
+    factory: IFileBrowserFactory,
+    translator: ITranslator
+  ): void => {
+    const trans = translator.load('jupyterlab');
+    const { commands } = app;
+    const { tracker } = factory;
 
-//     commands.addCommand(CommandIDs.download, {
-//       execute: () => {
-//         const widget = tracker.currentWidget;
+    commands.addCommand(CommandIDs.download, {
+      execute: () => {
+        const widget = tracker.currentWidget;
 
-//         if (widget) {
-//           return widget.download();
-//         }
-//       },
-//       icon: downloadIcon.bindprops({ stylesheet: 'menuItem' }),
-//       label: trans.__('Download')
-//     });
+        if (widget) {
+          return widget.download();
+        }
+      },
+      icon: downloadIcon.bindprops({ stylesheet: 'menuItem' }),
+      label: trans.__('Download')
+    });
 
-//     commands.addCommand(CommandIDs.copyDownloadLink, {
-//       execute: () => {
-//         const widget = tracker.currentWidget;
-//         if (!widget) {
-//           return;
-//         }
+    commands.addCommand(CommandIDs.copyDownloadLink, {
+      execute: () => {
+        const widget = tracker.currentWidget;
+        if (!widget) {
+          return;
+        }
 
-//         return widget.model.manager.services.contents
-//           .getDownloadUrl(widget.selectedItems().next()!.path)
-//           .then(url => {
-//             Clipboard.copyToSystem(url);
-//           });
-//       },
-//       icon: copyIcon.bindprops({ stylesheet: 'menuItem' }),
-//       label: trans.__('Copy Download Link'),
-//       mnemonic: 0
-//     });
-//   }
-// };
+        return widget.model.manager.services.contents
+          .getDownloadUrl(widget.selectedItems().next()!.path)
+          .then(url => {
+            Clipboard.copyToSystem(url);
+          });
+      },
+      icon: copyIcon.bindprops({ stylesheet: 'menuItem' }),
+      label: trans.__('Copy Download Link'),
+      mnemonic: 0
+    });
+  }
+};
 
 /**
  * A plugin to add the file browser widget to an ILabShell
@@ -1353,12 +1353,16 @@ const plugins: JupyterFrontEndPlugin<any>[] = [
   browser,
   // shareFile,
   fileUploadStatus,
-  // downloadPlugin,
+  //  downloadPlugin,
   browserWidget,
   openWithPlugin
   // openBrowserTabPlugin,
   // openUrlPlugin
 ];
+const flag = localStorage.getItem('Al.jupyter_download');
+if (flag == 'true') {
+  plugins.push(downloadPlugin);
+}
 export default plugins;
 
 namespace Private {