UNPKG

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