|
1 | | -import { IRenderMimeRegistry } from '@jupyterlab/rendermime'; |
2 | | -import { |
3 | | - JupyterFrontEnd, |
4 | | - JupyterFrontEndPlugin |
5 | | -} from '@jupyterlab/application'; |
6 | | -import { WidgetTracker } from '@jupyterlab/apputils'; |
7 | | - |
8 | 1 | import { |
9 | 2 | ICollaborativeDrive, |
10 | 3 | SharedDocumentFactory |
11 | 4 | } from '@jupyter/docprovider'; |
| 5 | +import { |
| 6 | + JupyterFrontEnd, |
| 7 | + JupyterFrontEndPlugin |
| 8 | +} from '@jupyterlab/application'; |
| 9 | +import { ICommandPalette, WidgetTracker } from '@jupyterlab/apputils'; |
| 10 | +import { IFileBrowserFactory } from '@jupyterlab/filebrowser'; |
| 11 | +import { ILauncher } from '@jupyterlab/launcher'; |
| 12 | +import { INotebookTracker } from '@jupyterlab/notebook'; |
| 13 | +import { IRenderMimeRegistry } from '@jupyterlab/rendermime'; |
| 14 | +import { IJupyterYWidgetManager } from 'yjs-widgets'; |
12 | 15 |
|
| 16 | +import { CommandIDs } from '../commands'; |
13 | 17 | import { IGlueSessionTracker } from '../token'; |
| 18 | +import { glueIcon } from '../tools'; |
| 19 | +import defaultContent from './default.json'; |
14 | 20 | import { GlueSessionModelFactory } from './modelFactory'; |
| 21 | +import { GlueSessionSharedModel } from './sharedModel'; |
15 | 22 | import { GlueSessionTracker } from './tracker'; |
16 | 23 | import { GlueCanvasWidgetFactory } from './widgetFactory'; |
17 | | -import { GlueSessionSharedModel } from './sharedModel'; |
18 | | -import { INotebookTracker } from '@jupyterlab/notebook'; |
19 | | -import { IJupyterYWidgetManager } from 'yjs-widgets'; |
20 | 24 |
|
21 | 25 | const NAME_SPACE = 'gluepyter'; |
22 | 26 |
|
@@ -97,3 +101,65 @@ export const gluePlugin: JupyterFrontEndPlugin<void> = { |
97 | 101 | ); |
98 | 102 | } |
99 | 103 | }; |
| 104 | + |
| 105 | +/** |
| 106 | + * Add launcher button to create a new glue session. |
| 107 | + */ |
| 108 | +export const newFilePlugin: JupyterFrontEndPlugin<void> = { |
| 109 | + id: 'gluepyter:create-new-plugin', |
| 110 | + autoStart: true, |
| 111 | + requires: [IFileBrowserFactory], |
| 112 | + optional: [ILauncher, ICommandPalette], |
| 113 | + activate: ( |
| 114 | + app: JupyterFrontEnd, |
| 115 | + browserFactory: IFileBrowserFactory, |
| 116 | + launcher?: ILauncher, |
| 117 | + commandPalette?: ICommandPalette |
| 118 | + ) => { |
| 119 | + const { commands } = app; |
| 120 | + commands.addCommand(CommandIDs.createNew, { |
| 121 | + label: args => 'New Glue Session', |
| 122 | + caption: 'Create a new Glue Session', |
| 123 | + icon: args => (args['isPalette'] ? undefined : glueIcon), |
| 124 | + execute: async args => { |
| 125 | + const cwd = (args['cwd'] || |
| 126 | + browserFactory.tracker.currentWidget?.model.path) as string; |
| 127 | + |
| 128 | + let model = await app.serviceManager.contents.newUntitled({ |
| 129 | + path: cwd, |
| 130 | + type: 'file', |
| 131 | + ext: '.glu' |
| 132 | + }); |
| 133 | + model = await app.serviceManager.contents.save(model.path, { |
| 134 | + ...model, |
| 135 | + format: 'text', |
| 136 | + size: undefined, |
| 137 | + content: JSON.stringify(defaultContent) |
| 138 | + }); |
| 139 | + |
| 140 | + // Open the newly created file with the 'Editor' |
| 141 | + return app.commands.execute('docmanager:open', { |
| 142 | + path: model.path |
| 143 | + }); |
| 144 | + } |
| 145 | + }); |
| 146 | + |
| 147 | + // Add the command to the launcher |
| 148 | + if (launcher) { |
| 149 | + launcher.add({ |
| 150 | + command: CommandIDs.createNew, |
| 151 | + category: 'Gluepyter', |
| 152 | + rank: 1 |
| 153 | + }); |
| 154 | + } |
| 155 | + |
| 156 | + // Add the command to the palette |
| 157 | + if (commandPalette) { |
| 158 | + commandPalette.addItem({ |
| 159 | + command: CommandIDs.createNew, |
| 160 | + args: { isPalette: true }, |
| 161 | + category: 'Gluepyter' |
| 162 | + }); |
| 163 | + } |
| 164 | + } |
| 165 | +}; |
0 commit comments