UNPKG

4.72 kBTypeScriptView Raw
1import { IDisposable } from '@lumino/disposable';
2import { Menu } from '@lumino/widgets';
3/**
4 * Interface for disposable item menu
5 */
6export interface IDisposableMenuItem extends IDisposable, Menu.IItem {
7}
8/**
9 * A common interface for extensible JupyterLab application menus.
10 *
11 * Plugins are still free to define their own menus in any way
12 * they like. However, JupyterLab defines a few top-level
13 * application menus that may be extended by plugins as well,
14 * such as "Edit" and "View"
15 */
16export interface IRankedMenu extends IDisposable {
17 /**
18 * Add a group of menu items specific to a particular
19 * plugin.
20 *
21 * The rank can be set for all items in the group using the
22 * function argument or per item.
23 *
24 * @param items - the list of menu items to add.
25 * @param rank - the default rank in the menu in which to insert the group.
26 * @returns Disposable of the group
27 */
28 addGroup(items: Menu.IItemOptions[], rank?: number): IDisposable;
29 /**
30 * Add a menu item to the end of the menu.
31 *
32 * @param options - The options for creating the menu item.
33 *
34 * @returns The menu item added to the menu.
35 *
36 * @deprecated It will return a `IDisposable` object in v4
37 */
38 addItem(options: IRankedMenu.IItemOptions): Menu.IItem;
39 /**
40 * A read-only array of the menu items in the menu.
41 */
42 readonly items: ReadonlyArray<Menu.IItem>;
43 /**
44 * The underlying Lumino menu.
45 *
46 * @deprecated will be removed in v4
47 */
48 readonly menu: Menu;
49 /**
50 * Menu rank
51 */
52 readonly rank?: number;
53}
54/**
55 * Namespace for JupyterLabMenu interfaces
56 */
57export declare namespace IRankedMenu {
58 /**
59 * Default menu item rank
60 */
61 const DEFAULT_RANK = 100;
62 /**
63 * An options object for creating a menu item.
64 */
65 interface IItemOptions extends Menu.IItemOptions {
66 /**
67 * Menu item rank
68 */
69 rank?: number;
70 }
71 /**
72 * An options object for creating a JupyterLab menu.
73 */
74 interface IOptions extends Menu.IOptions {
75 /**
76 * Whether to include separators between the
77 * groups that are added to the menu.
78 *
79 * Default: true
80 */
81 includeSeparators?: boolean;
82 /**
83 * Menu rank
84 */
85 rank?: number;
86 }
87}
88/**
89 * An extensible menu for JupyterLab application menus.
90 */
91export declare class RankedMenu extends Menu implements IRankedMenu {
92 /**
93 * Construct a new menu.
94 *
95 * @param options - Options for the lumino menu.
96 */
97 constructor(options: IRankedMenu.IOptions);
98 /**
99 * The underlying Lumino menu.
100 *
101 * @deprecated since v3.1
102 * RankMenu inherits from Menu since v3.1
103 */
104 get menu(): Menu;
105 /**
106 * Menu rank.
107 */
108 get rank(): number | undefined;
109 /**
110 * Add a group of menu items specific to a particular
111 * plugin.
112 *
113 * The rank can be set for all items in the group using the
114 * function argument or per item.
115 *
116 * @param items - the list of menu items to add.
117 * @param rank - the default rank in the menu in which to insert the group.
118 * @returns Disposable of the group
119 */
120 addGroup(items: IRankedMenu.IItemOptions[], rank?: number): IDisposable;
121 /**
122 * Add a menu item to the end of the menu.
123 *
124 * @param options - The options for creating the menu item.
125 *
126 * @returns The menu item added to the menu.
127 */
128 addItem(options: IRankedMenu.IItemOptions): IDisposableMenuItem;
129 /**
130 * Remove all menu items from the menu.
131 */
132 clearItems(): void;
133 /**
134 * Dispose of the resources held by the menu.
135 */
136 dispose(): void;
137 /**
138 * Get the rank of the item at index.
139 *
140 * @param index Item index.
141 * @returns Rank of the item.
142 */
143 getRankAt(index: number): number;
144 /**
145 * Insert a menu item into the menu at the specified index.
146 *
147 * @param index - The index at which to insert the item.
148 *
149 * @param options - The options for creating the menu item.
150 *
151 * @returns The menu item added to the menu.
152 *
153 * #### Notes
154 * The index will be clamped to the bounds of the items.
155 */
156 insertItem(index: number, options: IRankedMenu.IItemOptions): IDisposableMenuItem;
157 /**
158 * Remove the item at a given index from the menu.
159 *
160 * @param index - The index of the item to remove.
161 *
162 * #### Notes
163 * This is a no-op if the index is out of range.
164 */
165 removeItemAt(index: number): void;
166 private _includeSeparators;
167 private _rank;
168 private _ranks;
169}