@@ -51,11 +51,14 @@ export class Application<T extends Widget | HTMLElement = Widget> {
51
51
this . pluginRegistry . application = this ;
52
52
53
53
// Initialize the application state.
54
- this . commands = new CommandRegistry ( ) ;
55
- this . contextMenu = new ContextMenu ( {
54
+ this . commands = options . commands ?? new CommandRegistry ( ) ;
55
+ const contextMenuOptions = {
56
56
commands : this . commands ,
57
57
renderer : options . contextMenuRenderer
58
- } ) ;
58
+ } ;
59
+ this . contextMenu = options . contextMenuFactory
60
+ ? options . contextMenuFactory ( contextMenuOptions )
61
+ : new ContextMenu ( contextMenuOptions ) ;
59
62
this . shell = options . shell ;
60
63
this . _hasShellWidget = this . shell instanceof Widget ;
61
64
}
@@ -197,7 +200,9 @@ export class Application<T extends Widget | HTMLElement = Widget> {
197
200
* If the plugin provides a service which has already been provided
198
201
* by another plugin, the new service will override the old service.
199
202
*/
200
- registerPlugin ( plugin : IPlugin < Application < Widget | HTMLElement > , any > ) : void {
203
+ registerPlugin (
204
+ plugin : IPlugin < Application < Widget | HTMLElement > , any >
205
+ ) : void {
201
206
this . pluginRegistry . registerPlugin ( plugin ) ;
202
207
}
203
208
@@ -209,7 +214,9 @@ export class Application<T extends Widget | HTMLElement = Widget> {
209
214
* #### Notes
210
215
* This calls `registerPlugin()` for each of the given plugins.
211
216
*/
212
- registerPlugins ( plugins : IPlugin < Application < Widget | HTMLElement > , any > [ ] ) : void {
217
+ registerPlugins (
218
+ plugins : IPlugin < Application < Widget | HTMLElement > , any > [ ]
219
+ ) : void {
213
220
this . pluginRegistry . registerPlugins ( plugins ) ;
214
221
}
215
222
@@ -340,14 +347,15 @@ export class Application<T extends Widget | HTMLElement = Widget> {
340
347
* A subclass may reimplement this method as needed.
341
348
*/
342
349
protected attachShell ( id : string ) : void {
343
- if ( this . _hasShellWidget ) {
344
- Widget . attach (
345
- this . shell as Widget ,
346
- ( id && document . getElementById ( id ) ) || document . body
347
- ) ; } else {
350
+ if ( this . _hasShellWidget ) {
351
+ Widget . attach (
352
+ this . shell as Widget ,
353
+ ( id && document . getElementById ( id ) ) || document . body
354
+ ) ;
355
+ } else {
348
356
const host = ( id && document . getElementById ( id ) ) || document . body ;
349
- if ( ! host . contains ( this . shell as HTMLElement ) ) {
350
- host . appendChild ( this . shell as HTMLElement )
357
+ if ( ! host . contains ( this . shell as HTMLElement ) ) {
358
+ host . appendChild ( this . shell as HTMLElement ) ;
351
359
}
352
360
}
353
361
}
@@ -426,7 +434,9 @@ export class Application<T extends Widget | HTMLElement = Widget> {
426
434
* A subclass may reimplement this method as needed.
427
435
*/
428
436
protected evtResize ( event : Event ) : void {
429
- if ( this . _hasShellWidget ) { ( this . shell as Widget ) . update ( ) }
437
+ if ( this . _hasShellWidget ) {
438
+ ( this . shell as Widget ) . update ( ) ;
439
+ }
430
440
}
431
441
432
442
/**
@@ -440,13 +450,14 @@ export class Application<T extends Widget | HTMLElement = Widget> {
440
450
}
441
451
442
452
/**
443
- * The namespace for the ` Application` class statics.
453
+ * The namespace for the { @link Application} class statics.
444
454
*/
445
455
export namespace Application {
446
456
/**
447
457
* An options object for creating an application.
448
458
*/
449
- export interface IOptions < T extends Widget | HTMLElement > extends PluginRegistry . IOptions {
459
+ export interface IOptions < T extends Widget | HTMLElement >
460
+ extends PluginRegistry . IOptions {
450
461
/**
451
462
* The shell element to use for the application.
452
463
*
@@ -455,6 +466,16 @@ export namespace Application {
455
466
*/
456
467
shell : T ;
457
468
469
+ /**
470
+ * A custom commands registry.
471
+ */
472
+ commands ?: CommandRegistry ;
473
+
474
+ /**
475
+ * A custom context menu factory.
476
+ */
477
+ contextMenuFactory ?: ( options : ContextMenu . IOptions ) => ContextMenu ;
478
+
458
479
/**
459
480
* A custom renderer for the context menu.
460
481
*/
0 commit comments