Lua: Implement forms.setdropdownitems()
This commit is contained in:
parent
46586a7df9
commit
ab1b1877e8
|
@ -445,6 +445,38 @@ namespace BizHawk.Client.EmuHawk
|
|||
return string.Empty;
|
||||
}
|
||||
|
||||
[LuaMethodAttributes(
|
||||
"setdropdownitems",
|
||||
"Sets the items for a given dropdown box"
|
||||
)]
|
||||
public void SetDropdownItems(
|
||||
int handle,
|
||||
LuaTable items)
|
||||
{
|
||||
try {
|
||||
var ptr = new IntPtr(handle);
|
||||
foreach (var form in _luaForms) {
|
||||
if (form.Handle == ptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (Control control in form.Controls) {
|
||||
if (control.Handle == ptr) {
|
||||
if (control is LuaDropDown) {
|
||||
var dropdownItems = items.Values.Cast<string>().ToList();
|
||||
dropdownItems.Sort();
|
||||
(control as LuaDropDown).SetItems(dropdownItems);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
ConsoleLuaLibrary.Log(ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
[LuaMethodAttributes(
|
||||
"setlocation",
|
||||
"Sets the location of a control or form by passing in the handle of the created object"
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Windows.Forms;
|
||||
|
||||
|
@ -14,5 +13,11 @@ namespace BizHawk.Client.EmuHawk
|
|||
SelectedIndex = 0;
|
||||
DropDownStyle = ComboBoxStyle.DropDownList;
|
||||
}
|
||||
|
||||
public void SetItems(List<string> items) {
|
||||
Items.Clear();
|
||||
Items.AddRange(items.Cast<object>().ToArray());
|
||||
SelectedIndex = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue