@difizen/mana-core
Version:
92 lines • 4.45 kB
TypeScript
import type { MaybePromise } from '@difizen/mana-common';
import { Disposable } from '@difizen/mana-common';
import type { Contribution } from '@difizen/mana-syringe';
import { Syringe } from '@difizen/mana-syringe';
import { ApplicationContribution } from '../application/application';
import { CommandRegistry } from '../command/command-registry';
import type { MenuOptions, MenuPath, ActionMenuNode, GeneralMenuItem } from './menu-protocol';
import { GeneralMenuItemFactory, MenuNode, MenuItem, ActionMenuItemFactory } from './menu-protocol';
export declare const MenuContribution: Syringe.DefinedToken;
export type MenuContribution = {
/**
* Register menus.
* @param menus the menu registry.
*/
registerMenus: (menus: MenuRegistry) => void;
};
/**
* Register and unregister menus, submenus and actions
*/
export declare class MenuRegistry implements ApplicationContribution {
protected readonly root: GeneralMenuItem;
protected readonly contributions: Contribution.Provider<MenuContribution>;
protected readonly generalItemFactory: GeneralMenuItemFactory;
protected readonly actionItemFactory: ActionMenuItemFactory;
protected readonly commands: CommandRegistry;
constructor(contributions: Contribution.Provider<MenuContribution>, generalItemFactory: GeneralMenuItemFactory, actionItemFactory: ActionMenuItemFactory, commands: CommandRegistry);
onStart(): void;
/**
* Adds the given menu action to the menu denoted by the given path.
*
* @returns a disposable which, when called, will remove the menu action again.
*/
registerMenuAction(menuPath: MenuPath, item: ActionMenuNode): Disposable;
/**
* Adds the given menu node to the menu denoted by the given path.
*
* @returns a disposable which, when called, will remove the menu node again.
*/
registerMenuNode(menuPath: MenuPath, item: MenuNode): Disposable;
registerGroupMenu(menuPath: MenuPath, options?: MenuOptions): Disposable;
/**
* Register a new menu at the given path with the given label.
* (If the menu already exists without a label, iconClass or order this method can be used to set them.)
*
* @param menuPath the path for which a new submenu shall be registered.
* @param label the label to be used for the new submenu.
* @param options optionally allows to set an icon class and specify the order of the new menu.
*
* @returns if the menu was successfully created a disposable will be returned which,
* when called, will remove the menu again. If the menu already existed a no-op disposable
* will be returned.
*
* Note that if the menu already existed and was registered with a different label an error
* will be thrown.
*/
registerSubmenu(menuPath: MenuPath, options?: MenuOptions): Disposable;
/**
* Unregister all menu nodes with the same id as the given menu action.
*
* @param item the item whose id will be used.
* @param menuPath if specified only nodes within the path will be unregistered.
*/
unregisterMenuAction(item: ActionMenuNode, menuPath?: MenuPath): void;
/**
* Unregister all menu nodes with the given id.
*
* @param id the id which shall be removed.
* @param menuPath if specified only nodes within the path will be unregistered.
*/
unregisterMenuAction(id: string, menuPath?: MenuPath): void;
/**
* Recurse all menus, removing any menus matching the `id`.
*
* @param id technical identifier of the `MenuNode`.
*/
unregisterMenuNode(id: string): void;
protected getOrCreateGroup(menuPath: MenuPath, options?: MenuOptions): GeneralMenuItem;
protected getOrCreateSub(current: GeneralMenuItem, menuId: string, options?: MenuOptions): GeneralMenuItem;
/**
* Returns the menu at the given path.
*
* @param menuPath the path specifying the menu to return. If not given the empty path will be used.
*
* @returns the root menu when `menuPath` is empty. If `menuPath` is not empty the specified menu is
* returned if it exists, otherwise an error is thrown.
*/
getMenu(menuPath?: MenuPath): GeneralMenuItem;
isVisible(item: MenuItem, ...args: any[]): boolean;
isEnabled(item: MenuItem, ...args: any[]): boolean;
execute(item: MenuItem, ...args: any[]): MaybePromise<void>;
}
//# sourceMappingURL=menu-registry.d.ts.map