Options
All
  • Public
  • Public/Protected
  • All
Menu

Class DynamicMenuWidget

A menu widget that would recompute its items on update.

Hierarchy

  • Menu
    • DynamicMenuWidget

Implements

  • IMessageHandler
  • IObservableDisposable

Index

Type aliases

Static ItemType

ItemType: "command" | "submenu" | "separator"

A type alias for a menu item type.

Constructors

constructor

Properties

Readonly aboutToClose

aboutToClose: ISignal<this, void>

A signal emitted just before the menu is closed.

Notes

This signal is emitted when the menu receives a 'close-request' message, just before it removes itself from the DOM.

This signal is not emitted if the menu is already detached from the DOM when it receives the 'close-request' message.

activeIndex

activeIndex: number

Set the index of the currently active menu item.

Notes

If the item cannot be activated, the index will be set to -1.

activeItem

activeItem: IItem | null

Set the currently active menu item.

Notes

If the item cannot be activated, the item will be set to null.

Readonly childMenu

childMenu: Menu | null

The child menu of the menu.

Notes

This is null unless the menu has an open submenu.

Readonly commands

commands: CommandRegistry

The command registry used by the menu.

Readonly contentNode

contentNode: HTMLUListElement

The menu content node.

Notes

This is the node which holds the menu item nodes.

Modifying this node directly can lead to undefined behavior.

Readonly dataset

dataset: DOMStringMap

The dataset for the widget's DOM node.

Readonly disposed

disposed: ISignal<this, void>

A signal emitted when the widget is disposed.

id

id: string

Set the id of the widget's DOM node.

Readonly isAttached

isAttached: boolean

Test whether the widget's node is attached to the DOM.

Readonly isDisposed

isDisposed: boolean

Test whether the widget has been disposed.

Readonly isHidden

isHidden: boolean

Test whether the widget is explicitly hidden.

Readonly isVisible

isVisible: boolean

Test whether the widget is visible.

Notes

A widget is visible when it is attached to the DOM, is not explicitly hidden, and has no explicitly hidden ancestors.

Readonly items

items: ReadonlyArray<IItem>

A read-only array of the menu items in the menu.

layout

layout: Layout | null

Set the layout for the widget.

Notes

The layout is single-use only. It cannot be changed after the first assignment.

The layout is disposed automatically when the widget is disposed.

Readonly leafMenu

leafMenu: Menu

The leaf menu of the menu hierarchy.

Protected menu

Readonly menuRequested

menuRequested: ISignal<this, "next" | "previous">

A signal emitted when a new menu is requested by the user.

Notes

This signal is emitted whenever the user presses the right or left arrow keys, and a submenu cannot be opened or closed in response.

This signal is useful when implementing menu bars in order to open the next or previous menu in response to a user key press.

This signal is only emitted for the root menu in a hierarchy.

Readonly node

node: HTMLElement

Get the DOM node owned by the widget.

Protected options

options: MenuWidget.IOptions & { commands: MenuCommandRegistry }

parent

parent: Widget | null

Set the parent of the widget.

Notes

Children are typically added to a widget by using a layout, which means user code will not normally set the parent widget directly.

The widget will be automatically removed from its old parent.

This is a no-op if there is no effective parent change.

Readonly parentMenu

parentMenu: Menu | null

The parent menu of the menu.

Notes

This is null unless the menu is an open submenu.

Protected previousFocusedElement

previousFocusedElement: HTMLElement | undefined

We want to restore the focus after the menu closes.

Readonly renderer

renderer: IRenderer

The renderer used by the menu.

Readonly rootMenu

rootMenu: Menu

The root menu of the menu hierarchy.

Protected services

services: MenuServices

Readonly title

title: Title<Widget>

The title object for the widget.

Notes

The title object is used by some container widgets when displaying the widget alongside some title, such as a tab panel or side bar.

Since not all widgets will use the title, it is created on demand.

The owner property of the title is set to this widget.

Static defaultRenderer

defaultRenderer: Renderer

The default Renderer instance.

Methods

aboutToShow

  • aboutToShow(__namedParameters: { previousFocusedElement: undefined | HTMLElement }): void

activate

  • activate(): void
  • Post an 'activate-request' message to the widget.

    Notes

    This is a simple convenience method for posting the message.

    Returns void

activateNextItem

  • activateNextItem(): void
  • Activate the next selectable item in the menu.

    Notes

    If no item is selectable, the index will be set to -1.

    Returns void

activatePreviousItem

  • activatePreviousItem(): void
  • Activate the previous selectable item in the menu.

    Notes

    If no item is selectable, the index will be set to -1.

    Returns void

addClass

  • addClass(name: string): void
  • Add a class name to the widget's DOM node.

    Parameters

    • name: string

      The class name to add to the node.

      Notes

      If the class name is already added to the node, this is a no-op.

      The class name must not contain whitespace.

    Returns void

addItem

  • Add a menu item to the end of the menu.

    Parameters

    • options: IItemOptions

      The options for creating the menu item.

    Returns IItem

    The menu item added to the menu.

Private buildSubMenus

children

  • children(): IIterator<Widget>
  • Create an iterator over the widget's children.

    Returns IIterator<Widget>

    A new iterator over the children of the widget.

    Notes

    The widget must have a populated layout in order to have children.

    If a layout is not installed, the returned iterator will be empty.

clearFlag

  • clearFlag(flag: Flag): void
  • Clear the given widget flag.

    Notes

    This will not typically be called directly by user code.

    Parameters

    Returns void

clearItems

  • clearItems(): void
  • Remove all menu items from the menu.

    Returns void

close

  • close(): void
  • Send a 'close-request' message to the widget.

    Notes

    This is a simple convenience method for sending the message.

    Returns void

contains

  • contains(widget: Widget): boolean
  • Test whether a widget is a descendant of this widget.

    Parameters

    • widget: Widget

      The descendant widget of interest.

    Returns boolean

    true if the widget is a descendant, false otherwise.

dispose

  • dispose(): void

fit

  • fit(): void
  • Post a 'fit-request' message to the widget.

    Notes

    This is a simple convenience method for posting the message.

    Returns void

Protected handleDefault

  • handleDefault(menuNode: MenuNode): MenuWidget.IItemOptions[]

handleEvent

  • handleEvent(event: Event): void
  • Handle the DOM events for the menu.

    Parameters

    • event: Event

      The DOM event sent to the menu.

      Notes

      This method implements the DOM EventListener interface and is called in response to events on the menu's DOM nodes. It should not be called directly by user code.

    Returns void

hasClass

  • hasClass(name: string): boolean
  • Test whether the widget's DOM node has the given class name.

    Parameters

    • name: string

      The class name of interest.

    Returns boolean

    true if the node has the class, false otherwise.

hide

  • hide(): void
  • Hide the widget and make it hidden to its parent widget.

    Notes

    This causes the isHidden property to be true.

    If the widget is explicitly hidden, this is a no-op.

    Returns void

insertItem

  • Insert a menu item into the menu at the specified index.

    Parameters

    • index: number

      The index at which to insert the item.

    • options: IItemOptions

      The options for creating the menu item.

    Returns IItem

    The menu item added to the menu.

    Notes

    The index will be clamped to the bounds of the items.

Protected notifyLayout

  • notifyLayout(msg: Message): void
  • Invoke the message processing routine of the widget's layout.

    Parameters

    • msg: Message

      The message to dispatch to the layout.

      Notes

      This is a no-op if the widget does not have a layout.

      This will not typically be called directly by user code.

    Returns void

Protected onActivateRequest

  • onActivateRequest(msg: Message): void

Protected onAfterAttach

  • onAfterAttach(msg: Message): void
  • A message handler invoked on an 'after-attach' message.

    Notes

    The default implementation of this handler is a no-op.

    Parameters

    • msg: Message

    Returns void

Protected onAfterDetach

  • onAfterDetach(msg: Message): void

Protected onAfterHide

  • onAfterHide(msg: Message): void
  • A message handler invoked on an 'after-hide' message.

    Notes

    The default implementation of this handler is a no-op.

    Parameters

    • msg: Message

    Returns void

Protected onAfterShow

  • onAfterShow(msg: Message): void
  • A message handler invoked on an 'after-show' message.

    Notes

    The default implementation of this handler is a no-op.

    Parameters

    • msg: Message

    Returns void

Protected onBeforeAttach

  • onBeforeAttach(msg: Message): void

Protected onBeforeDetach

  • onBeforeDetach(msg: Message): void
  • A message handler invoked on a 'before-detach' message.

    Notes

    The default implementation of this handler is a no-op.

    Parameters

    • msg: Message

    Returns void

Protected onBeforeHide

  • onBeforeHide(msg: Message): void
  • A message handler invoked on a 'before-hide' message.

    Notes

    The default implementation of this handler is a no-op.

    Parameters

    • msg: Message

    Returns void

Protected onBeforeShow

  • onBeforeShow(msg: Message): void
  • A message handler invoked on a 'before-show' message.

    Notes

    The default implementation of this handler is a no-op.

    Parameters

    • msg: Message

    Returns void

Protected onChildAdded

  • A message handler invoked on a 'child-added' message.

    Notes

    The default implementation of this handler is a no-op.

    Parameters

    Returns void

Protected onChildRemoved

  • A message handler invoked on a 'child-removed' message.

    Notes

    The default implementation of this handler is a no-op.

    Parameters

    Returns void

Protected onCloseRequest

  • onCloseRequest(msg: Message): void

Protected onFitRequest

  • onFitRequest(msg: Message): void
  • A message handler invoked on a 'fit-request' message.

    Notes

    The default implementation of this handler is a no-op.

    Parameters

    • msg: Message

    Returns void

Protected onResize

  • A message handler invoked on a 'resize' message.

    Notes

    The default implementation of this handler is a no-op.

    Parameters

    Returns void

Protected onUpdateRequest

  • onUpdateRequest(msg: Message): void

open

  • open(x: number, y: number, options?: MenuWidget.IOpenOptions): void

Protected preserveFocusedElement

  • preserveFocusedElement(previousFocusedElement?: Element | null): boolean

processMessage

  • processMessage(msg: Message): void
  • Process a message sent to the widget.

    Parameters

    • msg: Message

      The message sent to the widget.

      Notes

      Subclasses may reimplement this method as needed.

    Returns void

removeClass

  • removeClass(name: string): void
  • Remove a class name from the widget's DOM node.

    Parameters

    • name: string

      The class name to remove from the node.

      Notes

      If the class name is not yet added to the node, this is a no-op.

      The class name must not contain whitespace.

    Returns void

removeItem

  • removeItem(item: IItem): void
  • Remove an item from the menu.

    Parameters

    • item: IItem

      The item to remove from the menu.

      Notes

      This is a no-op if the item is not in the menu.

    Returns void

removeItemAt

  • removeItemAt(index: number): void
  • Remove the item at a given index from the menu.

    Parameters

    • index: number

      The index of the item to remove.

      Notes

      This is a no-op if the index is out of range.

    Returns void

Protected restoreFocusedElement

  • restoreFocusedElement(): boolean

Protected runWithPreservedFocusContext

  • runWithPreservedFocusContext(what: () => void): void

setFlag

  • setFlag(flag: Flag): void
  • Set the given widget flag.

    Notes

    This will not typically be called directly by user code.

    Parameters

    Returns void

setHidden

  • setHidden(hidden: boolean): void
  • Show or hide the widget according to a boolean value.

    Parameters

    • hidden: boolean

      true to hide the widget, or false to show it.

      Notes

      This is a convenience method for hide() and show().

    Returns void

show

  • show(): void
  • Show the widget and make it visible to its parent widget.

    Notes

    This causes the isHidden property to be false.

    If the widget is not explicitly hidden, this is a no-op.

    Returns void

testFlag

  • testFlag(flag: Flag): boolean
  • Test whether the given widget flag is set.

    Notes

    This will not typically be called directly by user code.

    Parameters

    Returns boolean

toggleClass

  • toggleClass(name: string, force?: undefined | false | true): boolean
  • Toggle a class name on the widget's DOM node.

    Parameters

    • name: string

      The class name to toggle on the node.

    • Optional force: undefined | false | true

      Whether to force add the class (true) or force remove the class (false). If not provided, the presence of the class will be toggled from its current state.

    Returns boolean

    true if the class is now present, false otherwise.

    Notes

    The class name must not contain whitespace.

triggerActiveItem

  • triggerActiveItem(): void
  • Trigger the active menu item.

    Notes

    If the active item is a submenu, it will be opened and the first item will be activated.

    If the active item is a command, the command will be executed.

    If the menu is not attached, this is a no-op.

    If there is no active item, this is a no-op.

    Returns void

update

  • update(): void
  • Post an 'update-request' message to the widget.

    Notes

    This is a simple convenience method for posting the message.

    Returns void

Private updateSubMenus