From b6124f0189269ba65ecd4e99fe52264f14d767d9 Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Tue, 5 Dec 2017 01:53:03 +0100 Subject: [PATCH] Sort LuaDialog dropdown entries by key-name --- gtk2_ardour/luadialog.cc | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/gtk2_ardour/luadialog.cc b/gtk2_ardour/luadialog.cc index 28e092c3ed..90464d26af 100644 --- a/gtk2_ardour/luadialog.cc +++ b/gtk2_ardour/luadialog.cc @@ -16,6 +16,8 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ +#include + #include #include "ardour/dB.h" @@ -451,18 +453,27 @@ protected: void populate (Gtk::Menu_Helpers::MenuList& items, luabridge::LuaRef values, std::string const& dflt) { using namespace Gtk::Menu_Helpers; + std::vector keys; + for (luabridge::Iterator i (values); !i.isNil (); ++i) { if (!i.key ().isString ()) { continue; } - std::string key = i.key ().cast (); - if (i.value ().isTable ()) { + keys.push_back (i.key ().cast ()); + } + + std::sort (keys.begin(), keys.end()); + + for (std::vector::const_iterator i = keys.begin (); i != keys.end(); ++i) { + std::string key = *i; + + if (values[key].isTable ()) { Gtk::Menu* menu = Gtk::manage (new Gtk::Menu); items.push_back (MenuElem (key, *menu)); - populate (menu->items (), i.value (), dflt); + populate (menu->items (), values[key], dflt); continue; } - luabridge::LuaRef* ref = new luabridge::LuaRef (i.value ()); + luabridge::LuaRef* ref = new luabridge::LuaRef (values[key]); _refs.push_back (ref); - items.push_back (MenuElem (i.key ().cast (), + items.push_back (MenuElem (key, sigc::bind (sigc::mem_fun (*this, &LuaDialogDropDown::dd_select), key, ref))); if (!_rv || key == dflt) {