|
8 | 8 | #include "..\dialogs\LuaChooseBox.h"
|
9 | 9 | #include "..\dialogs\LuaChooseList.h"
|
10 | 10 | #include "..\dialogs\LuaChooseListMulti.h"
|
| 11 | +#include "..\dialogs\FunctionListDlg.h" |
11 | 12 | #include "..\dmetaph.h"
|
12 | 13 | #include <direct.h>
|
13 | 14 |
|
@@ -1563,39 +1564,114 @@ static int shell_execute (lua_State *L)
|
1563 | 1564 | } // end of shell_execute
|
1564 | 1565 |
|
1565 | 1566 |
|
| 1567 | +// arg1 is dialog title |
| 1568 | +// arg2 is table of key/value pairs - value is shown |
| 1569 | +// arg3 is initial filter |
| 1570 | + |
| 1571 | +int filterpicker (lua_State *L) |
| 1572 | + { |
| 1573 | + const char * filtertitle = luaL_optstring (L, 1, "Filter"); |
| 1574 | + const char * initialfilter = luaL_optstring (L, 3, ""); |
| 1575 | + |
| 1576 | + if (strlen (filtertitle) > 100) |
| 1577 | + luaL_error (L, "title too long (max 100 characters)"); |
| 1578 | + |
| 1579 | + const int table = 2; |
| 1580 | + |
| 1581 | + if (!lua_istable (L, table)) |
| 1582 | + luaL_error (L, "must have table of choices as 2nd argument"); |
| 1583 | + |
| 1584 | +CFunctionListDlg dlg; |
| 1585 | + |
| 1586 | + dlg.m_strTitle = filtertitle; |
| 1587 | + dlg.m_strFilter = initialfilter; |
| 1588 | + |
| 1589 | + // standard Lua table iteration |
| 1590 | + for (lua_pushnil (L); lua_next (L, table) != 0; lua_pop (L, 1)) |
| 1591 | + { |
| 1592 | + if (!lua_isstring (L, -2)) |
| 1593 | + luaL_error (L, "table must have string or number keys"); |
| 1594 | + |
| 1595 | + if (!lua_isstring (L, -1)) |
| 1596 | + luaL_error (L, "table must have string or number values"); |
| 1597 | + |
| 1598 | + // value can simply be converted to a string |
| 1599 | + string sValue = lua_tostring (L, -1); |
| 1600 | + |
| 1601 | + // get key |
| 1602 | + CKeyValuePair kv (sValue); |
| 1603 | + |
| 1604 | + if (lua_type (L, -2) == LUA_TSTRING) |
| 1605 | + { |
| 1606 | + kv.sKey_ = lua_tostring (L, -2); |
| 1607 | + } |
| 1608 | + else |
| 1609 | + { // not string, should be number :) |
| 1610 | + // cannot do lua_tostring because that confuses lua_next |
| 1611 | + kv.bNumber_ = true; |
| 1612 | + kv.iKey_ = lua_tonumber (L, -2); |
| 1613 | + } // end of key being a number |
| 1614 | + |
| 1615 | + |
| 1616 | + dlg.m_data.push_back (kv); |
| 1617 | + |
| 1618 | + } // end of looping through table |
| 1619 | + |
| 1620 | + |
| 1621 | + if (dlg.DoModal () != IDOK) |
| 1622 | + lua_pushnil (L); |
| 1623 | + else |
| 1624 | + { // not cancelled |
| 1625 | + if (dlg.m_result.sValue_ == "") |
| 1626 | + lua_pushnil (L); // no choice made |
| 1627 | + else |
| 1628 | + { // get key of choice |
| 1629 | + if (dlg.m_result.bNumber_) |
| 1630 | + lua_pushnumber (L, dlg.m_result.iKey_); |
| 1631 | + else |
| 1632 | + lua_pushstring (L, dlg.m_result.sKey_.c_str ()); |
| 1633 | + } |
| 1634 | + } |
| 1635 | + |
| 1636 | + return 1; // 1 result |
| 1637 | + |
| 1638 | +} // end of filterpicker |
| 1639 | + |
| 1640 | + |
1566 | 1641 |
|
1567 | 1642 | // table of operations
|
1568 | 1643 | static const struct luaL_reg xmllib [] =
|
1569 | 1644 | {
|
1570 | 1645 |
|
1571 |
| - {"activatenotepad", activatenotepad}, |
1572 |
| - {"appendtonotepad", appendtonotepad}, |
1573 |
| - {"callbackslist", callbackslist}, |
1574 |
| - {"choose", choose}, |
1575 |
| - {"directorypicker", directorypicker}, |
1576 |
| - {"edit_distance", edit_distance}, |
1577 |
| - {"editbox", editbox}, |
1578 |
| - {"filepicker", filepicker}, |
1579 |
| - {"fontpicker", fontpicker}, |
1580 |
| - {"functionargs", functionargs}, |
1581 |
| - {"functionlist", functionlist}, |
1582 |
| - {"getfontfamilies", getfontfamilies}, |
1583 |
| - {"info", info}, |
1584 |
| - {"inputbox", inputbox}, |
1585 |
| - {"listbox", listbox}, |
1586 |
| - {"metaphone", metaphone}, |
1587 |
| - {"msgbox", msgbox}, // msgbox - not Unicode |
1588 |
| - {"multilistbox", multilistbox}, |
1589 |
| - {"showdebugstatus", showdebugstatus}, |
1590 |
| - {"sendtofront", send_to_front}, |
1591 |
| - {"shellexecute", shell_execute}, |
1592 |
| - {"spellcheckdialog", spellcheckdialog}, |
1593 |
| - {"umsgbox", umsgbox}, // msgbox - UTF8 |
1594 |
| - {"utf8decode", utf8decode}, |
1595 |
| - {"utf8encode", utf8encode}, |
1596 |
| - {"utf8sub", utf8sub}, |
1597 |
| - {"utf8valid", utf8valid}, |
1598 |
| - {"xmlread", xmlread}, |
| 1646 | + {"activatenotepad", activatenotepad}, |
| 1647 | + {"appendtonotepad", appendtonotepad}, |
| 1648 | + {"callbackslist", callbackslist}, |
| 1649 | + {"choose", choose}, |
| 1650 | + {"directorypicker", directorypicker}, |
| 1651 | + {"edit_distance", edit_distance}, |
| 1652 | + {"editbox", editbox}, |
| 1653 | + {"filepicker", filepicker}, |
| 1654 | + {"filterpicker", filterpicker}, |
| 1655 | + {"fontpicker", fontpicker}, |
| 1656 | + {"functionargs", functionargs}, |
| 1657 | + {"functionlist", functionlist}, |
| 1658 | + {"getfontfamilies", getfontfamilies}, |
| 1659 | + {"info", info}, |
| 1660 | + {"inputbox", inputbox}, |
| 1661 | + {"listbox", listbox}, |
| 1662 | + {"metaphone", metaphone}, |
| 1663 | + {"msgbox", msgbox}, // msgbox - not Unicode |
| 1664 | + {"multilistbox", multilistbox}, |
| 1665 | + {"showdebugstatus", showdebugstatus}, |
| 1666 | + {"sendtofront", send_to_front}, |
| 1667 | + {"shellexecute", shell_execute}, |
| 1668 | + {"spellcheckdialog", spellcheckdialog}, |
| 1669 | + {"umsgbox", umsgbox}, // msgbox - UTF8 |
| 1670 | + {"utf8decode", utf8decode}, |
| 1671 | + {"utf8encode", utf8encode}, |
| 1672 | + {"utf8sub", utf8sub}, |
| 1673 | + {"utf8valid", utf8valid}, |
| 1674 | + {"xmlread", xmlread}, |
1599 | 1675 |
|
1600 | 1676 |
|
1601 | 1677 | {NULL, NULL}
|
|
0 commit comments