Skip to content

Commit

Permalink
Added new router rule that allows copying and opening a file (located…
Browse files Browse the repository at this point in the history
… inside of the workspace) adding to the request /lab?copy/path/to/file.ext
  • Loading branch information
santilland committed Feb 12, 2020
1 parent 2cc71f5 commit fe3a9b1
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {
JupyterFrontEnd, JupyterFrontEndPlugin
JupyterFrontEnd, JupyterFrontEndPlugin, IRouter
} from '@jupyterlab/application';
import {ILauncher} from '@jupyterlab/launcher';
import {IFrame} from '@jupyterlab/apputils';
Expand All @@ -11,14 +11,15 @@ import {IDocumentManager} from '@jupyterlab/docmanager';
const extension: JupyterFrontEndPlugin<void> = {
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<void>{
app: JupyterFrontEnd, launcher: ILauncher,
docmanager: IDocumentManager, router: IRouter): Promise<void>{

// create new commands and add them to app.commands
function appendNewCommand(item: any) {
Expand Down Expand Up @@ -53,6 +54,11 @@ export function loadExamples(
});
}

router.register({
command: 'vires:copyRouter',
pattern: /(\?copy|\&copy)([^?]+)/
});

/*appendNewCommand({
name: 'Example Loader',
target: 'widget',
Expand Down Expand Up @@ -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({
Expand Down

0 comments on commit fe3a9b1

Please sign in to comment.