浏览代码

Merge pull request #6834 from danielballan/doc-copy-shareable-link

Add Copy Shareable Link to common extension points.
Jason Grout 5 年之前
父节点
当前提交
f62189ce26
共有 1 个文件被更改,包括 58 次插入0 次删除
  1. 58 0
      docs/source/developer/extension_points.rst

+ 58 - 0
docs/source/developer/extension_points.rst

@@ -356,3 +356,61 @@ Widget tracker tokens are provided for many activities in JupyterLab, including
 notebooks, consoles, text files, mime documents, and terminals.
 If you are adding your own activities to JupyterLab, you might consider providing
 a ``WidgetTracker`` token of your own, so that other extensions can make use of it.
+
+.. _copy_shareable_link:
+
+Copy Shareable Link
+~~~~~~~~~~~~~~~~~~~
+
+The file browser provides a context menu item "Copy Shareable Link". The
+desired behavior will vary by deployment and the users it serves. The file
+browser supports overriding the behavior of this item.
+
+.. code:: typescript
+
+   import {
+     IFileBrowserFactory
+   } from '@jupyterlab/filebrowser';
+
+   import {
+     JupyterFrontEnd, JupyterFrontEndPlugin
+   } from '@jupyterlab/application';
+
+
+   const shareFile: JupyterFrontEndPlugin<void> = {
+     activate: activateShareFile,
+     id: commandID,
+     requires: [IFileBrowserFactory],
+     autoStart: true
+   };
+
+   function activateShareFile(
+     app: JupyterFrontEnd,
+     factory: IFileBrowserFactory
+   ): void {
+     const { commands } = app;
+     const { tracker } = factory;
+
+     commands.addCommand('filebrowser:share-main', {
+       execute: () => {
+         const widget = tracker.currentWidget;
+         if (!widget) {
+           return;
+         }
+         const path = encodeURI(widget.selectedItems().next().path);
+         // Do something with path.
+       },
+       isVisible: () =>
+         tracker.currentWidget &&
+         toArray(tracker.currentWidget.selectedItems()).length === 1,
+       iconClass: 'jp-MaterialIcon jp-LinkIcon',
+       label: 'Copy Shareable Link'
+     });
+   }
+
+Note that before enabling this plugin in the usual way, you must *disable* the
+default plugin provided by the built-in file browser.
+
+.. code:: bash
+
+   jupyter labextension disable @jupyterlab/filebrowser-extension:share-file