Add a model and collections for tracking menu items.
Review Request #13630 — Created March 13, 2024 and submitted
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.
- Change Summary:
-
change:checked
signals are now always triggered, and are never silenced, letting UIs properly update their state when unchecking.- Added module-level docstrings for unit tests.
- Commits:
-
Summary ID 5013052b5e761d4cc6a337c1c96d01ed79558452 4597d7dbca74ed04e283e25433c33014f19a6e33 - Diff:
-
Revision 2 (+2354 -4)
Checks run (2 succeeded)
- Change Summary:
-
Actually updated with the new changes.
- Commits:
-
Summary ID 4597d7dbca74ed04e283e25433c33014f19a6e33 170360f5af6c75c26e4f86272597314bb89e1b68 - Diff:
-
Revision 3 (+2382 -4)