@theia/core
Version:
Theia is a cloud & desktop IDE framework implemented in TypeScript.
135 lines • 7.5 kB
TypeScript
import { MenuBar, Menu as MenuWidget, Widget } from '@lumino/widgets';
import { CommandRegistry as LuminoCommandRegistry } from '@lumino/commands';
import { DisposableCollection, PreferenceService } from '../../common/index.js';
import { KeybindingRegistry } from '../keybinding.js';
import { FrontendApplication } from '../frontend-application.js';
import { FrontendApplicationContribution } from '../frontend-application-contribution.js';
import { ContextKeyService, ContextMatcher } from '../context-key-service.js';
import { ContextMenuContext } from './context-menu-context.js';
import { Message } from '../widgets/index.js';
import { ApplicationShell } from '../shell/index.js';
import { CorePreferences } from '../../common/core-preferences.js';
import { CompoundMenuNode, MenuNode, MenuPath, Submenu } from '../../common/menu/menu-types.js';
import { MenuModelRegistry } from '../../common/menu/menu-model-registry.js';
export declare abstract class MenuBarWidget extends MenuBar {
abstract activateMenu(label: string, ...labels: string[]): Promise<MenuWidget>;
abstract triggerMenuItem(label: string, ...labels: string[]): Promise<MenuWidget.IItem>;
}
export interface BrowserMenuOptions extends MenuWidget.IOptions {
context?: HTMLElement;
}
export declare class BrowserMainMenuFactory implements MenuWidgetFactory {
protected readonly contextKeyService: ContextKeyService;
protected readonly context: ContextMenuContext;
protected readonly corePreferences: CorePreferences;
protected readonly keybindingRegistry: KeybindingRegistry;
protected readonly menuProvider: MenuModelRegistry;
createMenuBar(): MenuBarWidget;
protected getMenuBarVisibility(): string;
protected showMenuBar(menuBar: DynamicMenuBarWidget, preference?: string): void;
protected fillMenuBar(menuBar: MenuBarWidget): void;
createContextMenu(effectiveMenuPath: MenuPath, menuModel: CompoundMenuNode, contextMatcher: ContextMatcher, args?: unknown[], context?: HTMLElement): MenuWidget;
createMenuWidget(parentPath: MenuPath, menu: CompoundMenuNode, contextMatcher: ContextMatcher, options: BrowserMenuOptions, args?: unknown[]): DynamicMenuWidget;
protected get services(): MenuServices;
}
export declare function isMenuElement(element: HTMLElement | null): boolean;
export declare class DynamicMenuBarWidget extends MenuBarWidget {
/**
* We want to restore the focus after the menu closes.
*/
protected previousFocusedElement: HTMLElement | undefined;
constructor();
activateMenu(label: string, ...labels: string[]): Promise<MenuWidget>;
triggerMenuItem(label: string, ...labels: string[]): Promise<MenuWidget.IItem>;
}
export declare class MenuServices {
readonly contextKeyService: ContextKeyService;
readonly context: ContextMenuContext;
readonly menuWidgetFactory: MenuWidgetFactory;
}
export interface MenuWidgetFactory {
createMenuWidget(effectiveMenuPath: MenuPath, menu: Submenu, contextMatcher: ContextMatcher, options: BrowserMenuOptions, args?: unknown[]): MenuWidget;
}
/**
* A menu widget that would recompute its items on update.
*/
export declare class DynamicMenuWidget extends MenuWidget {
protected readonly effectiveMenuPath: MenuPath;
protected menu: CompoundMenuNode;
protected options: BrowserMenuOptions;
protected contextMatcher: ContextMatcher;
protected services: MenuServices;
protected args?: unknown[] | undefined;
private static nextCommmandId;
/**
* We want to restore the focus after the menu closes.
*/
protected previousFocusedElement: HTMLElement | undefined;
constructor(effectiveMenuPath: MenuPath, menu: CompoundMenuNode, options: BrowserMenuOptions, contextMatcher: ContextMatcher, services: MenuServices, args?: unknown[] | undefined);
protected onAfterAttach(msg: Message): void;
protected onBeforeDetach(msg: Message): void;
handleEvent(event: Event): void;
handlePointerDown(event: PointerEvent): void;
private hitTestMenus;
aboutToShow({ previousFocusedElement }: {
previousFocusedElement: HTMLElement | undefined;
}): void;
open(x: number, y: number, options?: MenuWidget.IOpenOptions): void;
protected updateSubMenus(parentPath: MenuPath, parent: MenuWidget, menu: CompoundMenuNode, commands: LuminoCommandRegistry, contextMatcher: ContextMatcher, context?: HTMLElement | undefined): void;
protected createItems(parentPath: MenuPath, nodes: MenuNode[], phCommandRegistry: LuminoCommandRegistry, contextMatcher: ContextMatcher, context?: HTMLElement): MenuWidget.IItemOptions[];
protected preserveFocusedElement(previousFocusedElement?: Element | null): boolean;
protected restoreFocusedElement(): boolean;
protected runWithPreservedFocusContext(what: () => void): void;
}
export declare class BrowserMenuBarContribution implements FrontendApplicationContribution {
protected readonly factory: BrowserMainMenuFactory;
protected readonly shell: ApplicationShell;
protected readonly preferenceService: PreferenceService;
protected toggleModeListeners: DisposableCollection;
protected menuWidget?: MenuBarWidget;
protected logoWidget?: Widget;
constructor(factory: BrowserMainMenuFactory);
onStart(app: FrontendApplication): void;
get menuBar(): MenuBarWidget | undefined;
protected appendMenu(shell: ApplicationShell): void;
/**
* Manages Lumino menu bar visibility and Alt-key toggling in Electron.
*
* With native title bar, the native Electron menu bar handles toggle via
* `autoHideMenuBar`, so the Lumino menu bar is simply hidden.
*
* With custom title bar, the Lumino menu bar is the only menu bar visible
* to the user. For 'toggle' mode, an Alt-key listener is installed to
* show/hide the menu bar widget.
*/
protected updateElectronMenuToggleMode(menu: MenuBarWidget, logo: Widget): void;
/**
* Establishes the resting visibility of the menu bar widgets in Electron, i.e. the state
* a clean Alt press toggles away from in 'toggle' mode.
*/
protected applyElectronMenuBarVisibility(menu: MenuBarWidget, logo: Widget, pref: string): void;
/**
* The widgets a clean Alt press shows and hides in 'toggle' mode in Electron.
*/
protected getElectronToggleTargets(menu: MenuBarWidget, logo: Widget): Widget[];
/**
* Manages Alt-key toggle behavior for 'toggle' mode in the browser.
* The top panel's initial visibility is handled by {@link ApplicationShell.setTopPanelVisibility};
* this method only installs or removes the Alt-key listener.
*/
protected updateBrowserMenuToggleMode(menu: MenuBarWidget): void;
/**
* Installs Alt-key listeners to toggle menu bar visibility.
* A clean Alt press (press and release without other keys) shows the
* given toggle targets and focuses the first menu. Pressing Alt again
* or clicking outside hides them.
*
* @param menu the menu bar widget to focus when shown
* @param toggleTargets supplies the widgets to show/hide on Alt toggle. It is consulted on
* each gesture, because the targets can depend on state that changes while the listener is
* installed, e.g. whether the window is in full screen.
*/
protected installAltKeyToggle(menu: MenuBarWidget, toggleTargets: () => Widget[]): DisposableCollection;
protected createLogo(): Widget;
}
//# sourceMappingURL=browser-menu-plugin.d.ts.map