Sort LuaDialog dropdown entries by key-name
authorRobin Gareus <robin@gareus.org>
Tue, 5 Dec 2017 00:53:03 +0000 (01:53 +0100)
committerRobin Gareus <robin@gareus.org>
Tue, 5 Dec 2017 00:55:38 +0000 (01:55 +0100)
gtk2_ardour/luadialog.cc

index 28e092c3ed1053670d1dc0a2622bcdf5e04b2c46..90464d26afae4374b9b4f225f16bc18f9dc73604 100644 (file)
@@ -16,6 +16,8 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  */
 
+#include <algorithm>
+
 #include <gtkmm.h>
 
 #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<std::string> keys;
+
                for (luabridge::Iterator i (values); !i.isNil (); ++i) {
                        if (!i.key ().isString ())  { continue; }
-                       std::string key = i.key ().cast<std::string> ();
-                       if (i.value ().isTable ())  {
+                       keys.push_back (i.key ().cast<std::string> ());
+               }
+
+               std::sort (keys.begin(), keys.end());
+
+               for (std::vector<std::string>::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<std::string> (),
+                       items.push_back (MenuElem (key,
                                                sigc::bind (sigc::mem_fun (*this, &LuaDialogDropDown::dd_select), key, ref)));
 
                        if (!_rv || key == dflt) {