UNPKG

1.89 kBPlain TextView Raw
1// Copyright (c) Jupyter Development Team.
2// Distributed under the terms of the Modified BSD License.
3
4import { IRankedMenu, RankedMenu } from '@jupyterlab/ui-components';
5import { find } from '@lumino/algorithm';
6import { SemanticCommand } from '@jupyterlab/apputils';
7
8/**
9 * An interface for a File menu.
10 */
11export interface IFileMenu extends IRankedMenu {
12 /**
13 * Option to add a `Quit` entry in the File menu
14 */
15 quitEntry: boolean;
16
17 /**
18 * A submenu for creating new files/launching new activities.
19 */
20 readonly newMenu: IRankedMenu;
21
22 /**
23 * The close and cleanup semantic command.
24 */
25 readonly closeAndCleaners: SemanticCommand;
26
27 /**
28 * The console creator semantic command.
29 */
30 readonly consoleCreators: SemanticCommand;
31}
32
33/**
34 * An extensible FileMenu for the application.
35 */
36export class FileMenu extends RankedMenu implements IFileMenu {
37 constructor(options: IRankedMenu.IOptions) {
38 super(options);
39 this.quitEntry = false;
40
41 this.closeAndCleaners = new SemanticCommand();
42 this.consoleCreators = new SemanticCommand();
43 }
44
45 /**
46 * The New submenu.
47 */
48 get newMenu(): RankedMenu {
49 if (!this._newMenu) {
50 this._newMenu =
51 (find(this.items, menu => menu.submenu?.id === 'jp-mainmenu-file-new')
52 ?.submenu as RankedMenu) ??
53 new RankedMenu({
54 commands: this.commands
55 });
56 }
57 return this._newMenu;
58 }
59
60 /**
61 * The close and cleanup semantic command.
62 */
63 readonly closeAndCleaners: SemanticCommand;
64
65 /**
66 * The console creator semantic command.
67 */
68 readonly consoleCreators: SemanticCommand;
69
70 /**
71 * Dispose of the resources held by the file menu.
72 */
73 dispose(): void {
74 this._newMenu?.dispose();
75 super.dispose();
76 }
77
78 /**
79 * Option to add a `Quit` entry in File menu
80 */
81 public quitEntry: boolean;
82
83 private _newMenu: RankedMenu;
84}