UNPKG

5.86 kBTypeScriptView Raw
1import { MenuBar, Menu as MenuWidget, Widget } from '@phosphor/widgets';
2import { CommandRegistry as PhosphorCommandRegistry } from '@phosphor/commands';
3import { CommandRegistry, DisposableCollection, Disposable, MenuModelRegistry, MenuPath, MenuNode, MenuCommandExecutor, CompoundMenuNode, CommandMenuNode } from '../../common';
4import { KeybindingRegistry } from '../keybinding';
5import { FrontendApplicationContribution, FrontendApplication } from '../frontend-application';
6import { ContextKeyService, ContextMatcher } from '../context-key-service';
7import { ContextMenuContext } from './context-menu-context';
8import { ApplicationShell } from '../shell';
9import { CorePreferences } from '../core-preferences';
10import { PreferenceService } from '../preferences/preference-service';
11export declare abstract class MenuBarWidget extends MenuBar {
12 abstract activateMenu(label: string, ...labels: string[]): Promise<MenuWidget>;
13 abstract triggerMenuItem(label: string, ...labels: string[]): Promise<MenuWidget.IItem>;
14}
15export interface BrowserMenuOptions extends MenuWidget.IOptions {
16 commands: MenuCommandRegistry;
17 context?: HTMLElement;
18 contextKeyService?: ContextMatcher;
19 rootMenuPath: MenuPath;
20}
21export declare class BrowserMainMenuFactory implements MenuWidgetFactory {
22 protected readonly contextKeyService: ContextKeyService;
23 protected readonly context: ContextMenuContext;
24 protected readonly commandRegistry: CommandRegistry;
25 protected readonly menuCommandExecutor: MenuCommandExecutor;
26 protected readonly corePreferences: CorePreferences;
27 protected readonly keybindingRegistry: KeybindingRegistry;
28 protected readonly menuProvider: MenuModelRegistry;
29 createMenuBar(): MenuBarWidget;
30 protected showMenuBar(menuBar: DynamicMenuBarWidget, preference: string | undefined): void;
31 protected fillMenuBar(menuBar: MenuBarWidget): void;
32 createContextMenu(path: MenuPath, args?: unknown[], context?: HTMLElement, contextKeyService?: ContextMatcher): MenuWidget;
33 createMenuWidget(menu: CompoundMenuNode, options: BrowserMenuOptions): DynamicMenuWidget;
34 protected createMenuCommandRegistry(menu: CompoundMenuNode, args?: unknown[]): MenuCommandRegistry;
35 protected registerMenu(menuCommandRegistry: MenuCommandRegistry, menu: MenuNode, args: unknown[]): void;
36 protected get services(): MenuServices;
37}
38export declare class DynamicMenuBarWidget extends MenuBarWidget {
39 /**
40 * We want to restore the focus after the menu closes.
41 */
42 protected previousFocusedElement: HTMLElement | undefined;
43 constructor();
44 activateMenu(label: string, ...labels: string[]): Promise<MenuWidget>;
45 triggerMenuItem(label: string, ...labels: string[]): Promise<MenuWidget.IItem>;
46}
47export declare class MenuServices {
48 readonly commandRegistry: CommandRegistry;
49 readonly keybindingRegistry: KeybindingRegistry;
50 readonly contextKeyService: ContextKeyService;
51 readonly context: ContextMenuContext;
52 readonly menuWidgetFactory: MenuWidgetFactory;
53 readonly commandExecutor: MenuCommandExecutor;
54}
55export interface MenuWidgetFactory {
56 createMenuWidget(menu: MenuNode & Required<Pick<MenuNode, 'children'>>, options: BrowserMenuOptions): MenuWidget;
57}
58/**
59 * A menu widget that would recompute its items on update.
60 */
61export declare class DynamicMenuWidget extends MenuWidget {
62 protected menu: CompoundMenuNode;
63 protected options: BrowserMenuOptions;
64 protected services: MenuServices;
65 /**
66 * We want to restore the focus after the menu closes.
67 */
68 protected previousFocusedElement: HTMLElement | undefined;
69 constructor(menu: CompoundMenuNode, options: BrowserMenuOptions, services: MenuServices);
70 aboutToShow({ previousFocusedElement }: {
71 previousFocusedElement: HTMLElement | undefined;
72 }): void;
73 open(x: number, y: number, options?: MenuWidget.IOpenOptions): void;
74 protected updateSubMenus(parent: MenuWidget, menu: CompoundMenuNode, commands: MenuCommandRegistry): void;
75 protected buildSubMenus(parentItems: MenuWidget.IItemOptions[], menu: MenuNode, commands: MenuCommandRegistry): MenuWidget.IItemOptions[];
76 protected undefinedOrMatch(contextKeyService: ContextMatcher, expression?: string, context?: HTMLElement): boolean;
77 protected preserveFocusedElement(previousFocusedElement?: Element | null): boolean;
78 protected restoreFocusedElement(): boolean;
79 protected runWithPreservedFocusContext(what: () => void): void;
80}
81export declare class BrowserMenuBarContribution implements FrontendApplicationContribution {
82 protected readonly factory: BrowserMainMenuFactory;
83 protected readonly shell: ApplicationShell;
84 protected readonly preferenceService: PreferenceService;
85 constructor(factory: BrowserMainMenuFactory);
86 onStart(app: FrontendApplication): void;
87 get menuBar(): MenuBarWidget | undefined;
88 protected appendMenu(shell: ApplicationShell): void;
89 protected createLogo(): Widget;
90}
91/**
92 * Stores Theia-specific action menu nodes instead of PhosphorJS commands with their handlers.
93 */
94export declare class MenuCommandRegistry extends PhosphorCommandRegistry {
95 protected services: MenuServices;
96 protected actions: Map<string, [import("../../common").MenuNodeMetadata & import("../../common").MenuNodeRenderingData & Partial<CompoundMenuNode> & Partial<CommandMenuNode> & Partial<import("../../common").AlternativeHandlerMenuNode> & CommandMenuNode, unknown[]]>;
97 protected toDispose: DisposableCollection;
98 constructor(services: MenuServices);
99 registerActionMenu(menu: MenuNode & CommandMenuNode, args: unknown[]): void;
100 snapshot(menuPath: MenuPath): this;
101 protected registerCommand(menu: MenuNode & CommandMenuNode, args: unknown[], menuPath: MenuPath): Disposable;
102}
103//# sourceMappingURL=browser-menu-plugin.d.ts.map
\No newline at end of file