Add a model and collections for tracking menu items.
Review Request #13630 — Created March 13, 2024 and submitted — Latest diff uploaded
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:
-
It makes it easier to maintain items in a collection and still allow
instantiation of new entries via the collection's.add()
. -
It avoids needing to do
instanceof
checks for different operations. -
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.