Skip to content

Instantly share code, notes, and snippets.

@aaronchall
Last active July 26, 2019 02:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aaronchall/73b43d1e72e1856913491e5bb705158a to your computer and use it in GitHub Desktop.
Save aaronchall/73b43d1e72e1856913491e5bb705158a to your computer and use it in GitHub Desktop.
example of writing extension to change behavior of share file
// src/index.ts
import {
JupyterFrontEnd, JupyterFrontEndPlugin
} from '@jupyterlab/application';
import { Clipboard } from '@jupyterlab/apputils';
import { URLExt } from '@jupyterlab/coreutils';
import { IFileBrowserFactory } from '@jupyterlab/filebrowser';
import { toArray } from '@phosphor/algorithm';
function activateShareFileMYAP(
app: JupyterFrontEnd,
factory: IFileBrowserFactory
): void {
const { commands } = app;
const { tracker } = factory;
//commands.addCommand('my.jupyterlab', { // wrong!!!
commands.addCommand('filebrowser:share-main', {
execute: () => {
const widget = tracker.currentWidget;
if (!widget) {
return;
}
const path = encodeURI(widget.selectedItems().next().path);
Clipboard.copyToSystem(URLExt.join('myap://Notebook', path));
},
isVisible: () =>
tracker.currentWidget &&
toArray(tracker.currentWidget.selectedItems()).length === 1,
iconClass: 'jp-MaterialIcon jpLinkIcon',
label: 'Copy Shareable Link'
});
}
/**
* Initialization data for the my.jupyterlab extension.
*/
const extension: JupyterFrontEndPlugin<void> = {
activate: activateShareFileMYAP,
id: 'my.jupyterlab:factory',
requires: [IFileBrowserFactory],
autoStart: true
};
export default extension;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment