From fe3a9b14721f58330fbc2103011fa8cd9c23b6e4 Mon Sep 17 00:00:00 2001 From: santilland Date: Wed, 12 Feb 2020 16:08:24 +0100 Subject: [PATCH] Added new router rule that allows copying and opening a file (located inside of the workspace) adding to the request /lab?copy/path/to/file.ext --- src/index.ts | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/src/index.ts b/src/index.ts index 590285c..2aa726d 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,5 +1,5 @@ import { - JupyterFrontEnd, JupyterFrontEndPlugin + JupyterFrontEnd, JupyterFrontEndPlugin, IRouter } from '@jupyterlab/application'; import {ILauncher} from '@jupyterlab/launcher'; import {IFrame} from '@jupyterlab/apputils'; @@ -11,14 +11,15 @@ import {IDocumentManager} from '@jupyterlab/docmanager'; const extension: JupyterFrontEndPlugin = { id: 'exampleLoader', autoStart: true, - requires: [ILauncher, IDocumentManager], + requires: [ILauncher, IDocumentManager, IRouter], activate: loadExamples }; export default extension; export function loadExamples( - app: JupyterFrontEnd, launcher: ILauncher, docmanager: IDocumentManager): Promise{ + app: JupyterFrontEnd, launcher: ILauncher, + docmanager: IDocumentManager, router: IRouter): Promise{ // create new commands and add them to app.commands function appendNewCommand(item: any) { @@ -53,6 +54,11 @@ export function loadExamples( }); } + router.register({ + command: 'vires:copyRouter', + pattern: /(\?copy|\©)([^?]+)/ + }); + /*appendNewCommand({ name: 'Example Loader', target: 'widget', @@ -80,6 +86,18 @@ export function loadExamples( } }); + app.commands.addCommand('vires:copyRouter', { + label: 'Router command for copy functionality', + iconClass: 'templateIcon', + execute: (args) => { + const path = (args.search as string).replace('?copy', ''); + docmanager.copy(path, '') + .then((result)=>{ + docmanager.open(result.path); + }); + } + }); + console.log(docmanager); launcher.add({