Make sorting optional for `forms.setdropdownitems` (squashed PR #2923)

* Add optional sort parameter to SetDropdownItems method

* Improve docs, use pattern matching

Co-authored-by: YoshiRulz <OSSYoshiRulz@gmail.com>
This commit is contained in:
Chris W 2021-09-08 06:18:51 +02:00 committed by GitHub
parent 56a9e333e9
commit 38f3cdb687
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 7 deletions

View File

@ -1168,9 +1168,9 @@ namespace BizHawk.Client.EmuHawk
return 0;
}
[LuaMethodExample("forms.setdropdownitems( 332, { \"item1\", \"item2\" } );")]
[LuaMethod("setdropdownitems", "Sets the items for a given dropdown box")]
public void SetDropdownItems(int handle, LuaTable items)
[LuaMethodExample("forms.setdropdownitems(dropdown_handle, { \"item1\", \"item2\" });")]
[LuaMethod("setdropdownitems", "Updates the item list of a dropdown menu. The optional third parameter toggles alphabetical sorting of items, pass false to skip sorting.")]
public void SetDropdownItems(int handle, LuaTable items, bool alphabetize = true)
{
try
{
@ -1186,13 +1186,12 @@ namespace BizHawk.Client.EmuHawk
{
if (control.Handle == ptr)
{
if (control is LuaDropDown)
if (control is LuaDropDown ldd)
{
var dropdownItems = _th.EnumerateValues<string>(items).ToList();
dropdownItems.Sort();
(control as LuaDropDown).SetItems(dropdownItems);
if (alphabetize) dropdownItems.Sort();
ldd.SetItems(dropdownItems);
}
return;
}
}