UNPKG

4.38 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 disposable menu item added to the menu.
35 */
36 addItem(options: IRankedMenu.IItemOptions): IDisposable;
37 /**
38 * A read-only array of the menu items in the menu.
39 */
40 readonly items: ReadonlyArray<Menu.IItem>;
41 /**
42 * Menu rank
43 */
44 readonly rank?: number;
45}
46/**
47 * Namespace for JupyterLabMenu interfaces
48 */
49export declare namespace IRankedMenu {
50 /**
51 * Default menu item rank
52 */
53 const DEFAULT_RANK = 100;
54 /**
55 * An options object for creating a menu item.
56 */
57 interface IItemOptions extends Menu.IItemOptions {
58 /**
59 * Menu item rank
60 */
61 rank?: number;
62 }
63 /**
64 * An options object for creating a JupyterLab menu.
65 */
66 interface IOptions extends Menu.IOptions {
67 /**
68 * Whether to include separators between the
69 * groups that are added to the menu.
70 *
71 * Default: true
72 */
73 includeSeparators?: boolean;
74 /**
75 * Menu rank
76 */
77 rank?: number;
78 }
79}
80/**
81 * An extensible menu for JupyterLab application menus.
82 */
83export declare class RankedMenu extends Menu implements IRankedMenu {
84 /**
85 * Construct a new menu.
86 *
87 * @param options - Options for the lumino menu.
88 */
89 constructor(options: IRankedMenu.IOptions);
90 /**
91 * Menu rank.
92 */
93 get rank(): number | undefined;
94 /**
95 * Add a group of menu items specific to a particular
96 * plugin.
97 *
98 * The rank can be set for all items in the group using the
99 * function argument or per item.
100 *
101 * @param items - the list of menu items to add.
102 * @param rank - the default rank in the menu in which to insert the group.
103 * @returns Disposable of the group
104 */
105 addGroup(items: IRankedMenu.IItemOptions[], rank?: number): IDisposable;
106 /**
107 * Add a menu item to the end of the menu.
108 *
109 * @param options - The options for creating the menu item.
110 *
111 * @returns The menu item added to the menu.
112 */
113 addItem(options: IRankedMenu.IItemOptions): IDisposableMenuItem;
114 /**
115 * Remove all menu items from the menu.
116 */
117 clearItems(): void;
118 /**
119 * Dispose of the resources held by the menu.
120 */
121 dispose(): void;
122 /**
123 * Get the rank of the item at index.
124 *
125 * @param index Item index.
126 * @returns Rank of the item.
127 */
128 getRankAt(index: number): number;
129 /**
130 * Insert a menu item into the menu at the specified index.
131 *
132 * @param index - The index at which to insert the item.
133 *
134 * @param options - The options for creating the menu item.
135 *
136 * @returns The menu item added to the menu.
137 *
138 * #### Notes
139 * The index will be clamped to the bounds of the items.
140 */
141 insertItem(index: number, options: IRankedMenu.IItemOptions): IDisposableMenuItem;
142 /**
143 * Remove the item at a given index from the menu.
144 *
145 * @param index - The index of the item to remove.
146 *
147 * #### Notes
148 * This is a no-op if the index is out of range.
149 */
150 removeItemAt(index: number): void;
151 private _includeSeparators;
152 private _rank;
153 private _ranks;
154}