5
5
* @module collaboration-extension
6
6
*/
7
7
8
+ import {
9
+ DocumentRegistry
10
+ } from '@jupyterlab/docregistry' ;
11
+
12
+ import {
13
+ NotebookPanel , INotebookModel
14
+ } from '@jupyterlab/notebook' ;
15
+
16
+ import {
17
+ IDisposable , DisposableDelegate
18
+ } from '@lumino/disposable' ;
19
+
20
+ import { CommandRegistry } from '@lumino/commands' ;
21
+
8
22
import {
9
23
JupyterFrontEnd ,
10
24
JupyterFrontEndPlugin
@@ -15,7 +29,11 @@ import {
15
29
IEditorExtensionRegistry
16
30
} from '@jupyterlab/codemirror' ;
17
31
import { WebSocketAwarenessProvider } from '@jupyter/docprovider' ;
18
- import { SidePanel , usersIcon } from '@jupyterlab/ui-components' ;
32
+ import {
33
+ SidePanel ,
34
+ usersIcon ,
35
+ caretDownIcon
36
+ } from '@jupyterlab/ui-components' ;
19
37
import { URLExt } from '@jupyterlab/coreutils' ;
20
38
import { ServerConnection } from '@jupyterlab/services' ;
21
39
import { IStateDB , StateDB } from '@jupyterlab/statedb' ;
@@ -189,3 +207,61 @@ export const userEditorCursors: JupyterFrontEndPlugin<void> = {
189
207
} ) ;
190
208
}
191
209
} ;
210
+
211
+ /**
212
+ * A plugin to add editing mode to the notebook page
213
+ */
214
+ export const editingMode : JupyterFrontEndPlugin < void > = {
215
+ id : '@jupyter/collaboration-extension:editingMode' ,
216
+ description : 'A plugin to add editing mode to the notebook page.' ,
217
+ autoStart : true ,
218
+ requires : [ ITranslator ] ,
219
+ activate : (
220
+ app : JupyterFrontEnd ,
221
+ ) => {
222
+ app . docRegistry . addWidgetExtension ( 'Notebook' , new EditingModeExtension ( ) ) ;
223
+ } ,
224
+ } ;
225
+
226
+ export class EditingModeExtension implements DocumentRegistry . IWidgetExtension < NotebookPanel , INotebookModel > {
227
+ createNew ( panel : NotebookPanel , context : DocumentRegistry . IContext < INotebookModel > ) : IDisposable {
228
+ const menubar = new MenuBar ( ) ;
229
+ const commands = new CommandRegistry ( ) ;
230
+ const menu = new Menu ( { commands } ) ;
231
+ menu . title . label = 'Editing' ;
232
+ menu . title . icon = caretDownIcon ;
233
+ addMenuItem ( commands , menu , 'editing' , 'Editing' , context ) ;
234
+ addMenuItem ( commands , menu , 'suggesting' , 'Suggesting' , context ) ;
235
+ menubar . addMenu ( menu ) ;
236
+
237
+ panel . toolbar . insertItem ( 990 , 'editingMode' , menubar ) ;
238
+ return new DisposableDelegate ( ( ) => {
239
+ menubar . dispose ( ) ;
240
+ } ) ;
241
+ }
242
+ }
243
+
244
+ /**
245
+ * Helper Function to add menu items.
246
+ */
247
+ function addMenuItem (
248
+ commands : CommandRegistry ,
249
+ menu : Menu ,
250
+ command : string ,
251
+ label : string ,
252
+ context : DocumentRegistry . IContext < INotebookModel > ,
253
+ ) : void {
254
+ commands . addCommand ( command , {
255
+ label : label ,
256
+ execute : ( ) => {
257
+ menu . title . label = label ;
258
+ if ( command == 'suggesting' ) {
259
+ context . model . sharedModel . getProvider ( 'root' ) . fork ( ) ;
260
+ }
261
+ }
262
+ } ) ;
263
+ menu . addItem ( {
264
+ type : 'command' ,
265
+ command : command
266
+ } ) ;
267
+ }
0 commit comments