|
@@ -103,6 +103,24 @@ const factory: JupyterLabPlugin<IFileBrowserFactory> = {
|
|
|
requires: [IDocumentManager, IStateDB]
|
|
|
};
|
|
|
|
|
|
+/**
|
|
|
+ * The default file browser share-file plugin
|
|
|
+ *
|
|
|
+ * This extension adds a "Copy Shareable Link" command that generates a copy-
|
|
|
+ * pastable URL. This url can be used to open a particular file in JupyterLab,
|
|
|
+ * handy for emailing links or bookmarking for reference.
|
|
|
+ *
|
|
|
+ * If you need to change how this link is generated (for instance, to copy a
|
|
|
+ * /user-redirect URL for JupyterHub), disable this plugin and replace it
|
|
|
+ * with another implementation.
|
|
|
+ */
|
|
|
+const shareFile: JupyterLabPlugin<void> = {
|
|
|
+ activate: activateShareFile,
|
|
|
+ id: '@jupyterlab/filebrowser-extension:share-file',
|
|
|
+ requires: [IFileBrowserFactory],
|
|
|
+ autoStart: true
|
|
|
+};
|
|
|
+
|
|
|
/**
|
|
|
* The file browser namespace token.
|
|
|
*/
|
|
@@ -111,7 +129,7 @@ const namespace = 'filebrowser';
|
|
|
/**
|
|
|
* Export the plugins as default.
|
|
|
*/
|
|
|
-const plugins: JupyterLabPlugin<any>[] = [factory, browser];
|
|
|
+const plugins: JupyterLabPlugin<any>[] = [factory, browser, shareFile];
|
|
|
export default plugins;
|
|
|
|
|
|
/**
|
|
@@ -208,6 +226,32 @@ function activateBrowser(
|
|
|
});
|
|
|
}
|
|
|
|
|
|
+function activateShareFile(
|
|
|
+ app: JupyterLab,
|
|
|
+ factory: IFileBrowserFactory
|
|
|
+): void {
|
|
|
+ const { commands } = app;
|
|
|
+ const { tracker } = factory;
|
|
|
+
|
|
|
+ commands.addCommand(CommandIDs.share, {
|
|
|
+ execute: () => {
|
|
|
+ const widget = tracker.currentWidget;
|
|
|
+ if (!widget) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ const path = encodeURI(widget.selectedItems().next().path);
|
|
|
+ const tree = PageConfig.getTreeUrl({ workspace: true });
|
|
|
+
|
|
|
+ Clipboard.copyToSystem(URLExt.join(tree, path));
|
|
|
+ },
|
|
|
+ isVisible: () =>
|
|
|
+ tracker.currentWidget &&
|
|
|
+ toArray(tracker.currentWidget.selectedItems()).length === 1,
|
|
|
+ iconClass: 'jp-MaterialIcon jp-LinkIcon',
|
|
|
+ label: 'Copy Shareable Link'
|
|
|
+ });
|
|
|
+}
|
|
|
+
|
|
|
/**
|
|
|
* Add the main file browser commands to the application's command registry.
|
|
|
*/
|
|
@@ -450,24 +494,6 @@ function addCommands(
|
|
|
mnemonic: 0
|
|
|
});
|
|
|
|
|
|
- commands.addCommand(CommandIDs.share, {
|
|
|
- execute: () => {
|
|
|
- const widget = tracker.currentWidget;
|
|
|
- if (!widget) {
|
|
|
- return;
|
|
|
- }
|
|
|
- const path = encodeURI(widget.selectedItems().next().path);
|
|
|
- const tree = PageConfig.getTreeUrl({ workspace: true });
|
|
|
-
|
|
|
- Clipboard.copyToSystem(URLExt.join(tree, path));
|
|
|
- },
|
|
|
- isVisible: () =>
|
|
|
- tracker.currentWidget &&
|
|
|
- toArray(tracker.currentWidget.selectedItems()).length === 1,
|
|
|
- iconClass: 'jp-MaterialIcon jp-LinkIcon',
|
|
|
- label: 'Copy Shareable Link'
|
|
|
- });
|
|
|
-
|
|
|
commands.addCommand(CommandIDs.copyPath, {
|
|
|
execute: () => {
|
|
|
const widget = tracker.currentWidget;
|