Choice items
A ChoiceItem (in UIToolbox) is one choice: Text, Detail, Icon, Group, Enabled and InsertText (for an AutoCompleteField). A string converts to a ChoiceItem with only the text. The same list of items can fill a SearchDropdown and a context menu:
var commands = new List<ChoiceItem>
{
new("New", "Ctrl+N", group: "File"),
new("Print", "Ctrl+P", group: "File", enabled: false),
new("Undo", "Ctrl+Z", group: "Edit")
};
search.Items = commands;
var menu = new ContextMenuComponent();
menu.AddItems(commands, item => run(item.Text));
ContextMenuComponent.AddItems(items, picked)adds aMenuItemfor each item. The detail is the shortcut text on the right. The icon and the enabled state carry over. A separator goes between two groups.pickedgets theChoiceItemthat runs.ChoiceListis the popup list ofSearchDropdown,ComboBoxandAutoCompleteField: anAnchoredPopupwith aListViewof group headers and items. A new control that suggests choices can use it.SetItemsshows the items,MoveHighlightandPickHighlightedare the Up, Down and Enter keys, andPickedandClosedreport back.IsSelected,Query,MakeItemandBindItemwork as they do onSearchDropdown.- Migration from 0.1.0:
SearchDropdown.FilterandSearchDropdown.HighlightTextare now onChoiceList.BindItemis nowAction<VisualElement, ChoiceItem>. The row classes aretb-choice-list__*(see SearchDropdown), and--tb-search-dropdown-matchis now--tb-choice-list-match.