Skip to content

Commit fe3a9b1

Browse files
committed
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
1 parent 2cc71f5 commit fe3a9b1

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

src/index.ts

+21-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {
2-
JupyterFrontEnd, JupyterFrontEndPlugin
2+
JupyterFrontEnd, JupyterFrontEndPlugin, IRouter
33
} from '@jupyterlab/application';
44
import {ILauncher} from '@jupyterlab/launcher';
55
import {IFrame} from '@jupyterlab/apputils';
@@ -11,14 +11,15 @@ import {IDocumentManager} from '@jupyterlab/docmanager';
1111
const extension: JupyterFrontEndPlugin<void> = {
1212
id: 'exampleLoader',
1313
autoStart: true,
14-
requires: [ILauncher, IDocumentManager],
14+
requires: [ILauncher, IDocumentManager, IRouter],
1515
activate: loadExamples
1616
};
1717

1818
export default extension;
1919

2020
export function loadExamples(
21-
app: JupyterFrontEnd, launcher: ILauncher, docmanager: IDocumentManager): Promise<void>{
21+
app: JupyterFrontEnd, launcher: ILauncher,
22+
docmanager: IDocumentManager, router: IRouter): Promise<void>{
2223

2324
// create new commands and add them to app.commands
2425
function appendNewCommand(item: any) {
@@ -53,6 +54,11 @@ export function loadExamples(
5354
});
5455
}
5556

57+
router.register({
58+
command: 'vires:copyRouter',
59+
pattern: /(\?copy|\&copy)([^?]+)/
60+
});
61+
5662
/*appendNewCommand({
5763
name: 'Example Loader',
5864
target: 'widget',
@@ -80,6 +86,18 @@ export function loadExamples(
8086
}
8187
});
8288

89+
app.commands.addCommand('vires:copyRouter', {
90+
label: 'Router command for copy functionality',
91+
iconClass: 'templateIcon',
92+
execute: (args) => {
93+
const path = (args.search as string).replace('?copy', '');
94+
docmanager.copy(path, '')
95+
.then((result)=>{
96+
docmanager.open(result.path);
97+
});
98+
}
99+
});
100+
83101
console.log(docmanager);
84102

85103
launcher.add({

0 commit comments

Comments
 (0)