Add a model and collections for tracking menu items.

Review Request #13630 — Created March 13, 2024 and submitted — Latest diff uploaded

Information

Ink
master

Reviewers

This introduces the model-level support for menus, consisting of three
parts:

  • MenuItem: This is a model containing state for any kind of supported
    menu item (a standard action item, checkbox menu item, radio menu
    item, or a separator).

  • MenuItemsCollection: A collection of menu items, which will be used
    as the backing for a menu view.

  • MenuItemsRadioGroup: A radio group for tracking menu items, which
    ensures only one item can be marked as checked at a time.

The design for MenuItem consolidates all state for all types into one
model, rather than having subclasses for each type. There are a few
reasons for this:

  1. It makes it easier to maintain items in a collection and still allow
    instantiation of new entries via the collection's .add().

  2. It avoids needing to do instanceof checks for different operations.

  3. It seems to be common practice (looking at the Apple, Windows, and
    GTK foundational classes for menu items).

The upcoming MenuView will make use of these classes to provide a full
menu implementation.

Unit tests pass.

Tested this thoroughly with the in-progress MenuView work.

Diff Revision 3 (Latest)

orig
1
2
3

Commits

First Last Summary ID Author
Add a model and collections for tracking menu items.
This introduces the model-level support for menus, consisting of three parts: * `MenuItem`: This is a model containing state for any kind of supported menu item (a standard action item, checkbox menu item, radio menu item, or a separator). * `MenuItemsCollection`: A collection of menu items, which will be used as the backing for a menu view. * `MenuItemsRadioGroup`: A radio group for tracking menu items, which ensures only one item can be marked as checked at a time. The design for `MenuItem` consolidates all state for all types into one model, rather than having subclasses for each type. There are a few reasons for this: 1. It makes it easier to maintain items in a collection and still allow instantiation of new entries via the collection's `.add()`. 2. It avoids needing to do `instanceof` checks for different operations. 3. It seems to be common practice (looking at the Apple, Windows, and GTK foundational classes for menu items). The upcoming `MenuView` will make use of these classes to provide a full menu implementation.
170360f5af6c75c26e4f86272597314bb89e1b68 Christian Hammond
src/ink/js/components/collections/index.ts
src/ink/js/components/collections/menuItemsCollection.ts
src/ink/js/components/collections/menuItemsRadioGroup.ts
src/ink/js/components/collections/tests/menuItemsRadioGroupTests.ts
src/ink/js/components/models/index.ts
src/ink/js/components/models/menuItemModel.ts
src/ink/js/components/models/tests/menuItemModelTests.ts
Loading...