GUI options to select FLAC as media format
[ardour.git] / gtk2_ardour / luadialog.cc
index 90464d26afae4374b9b4f225f16bc18f9dc73604..5932b234df99e0ce46ff4abe5de5f98b099fd95a 100644 (file)
@@ -28,6 +28,7 @@
 #include "widgets/ardour_dropdown.h"
 #include "widgets/slider_controller.h"
 
+#include "stripable_colorpicker.h"
 #include "ardour_dialog.h"
 #include "luadialog.h"
 #include "splash.h"
@@ -169,6 +170,25 @@ protected:
        Gtk::HSeparator _sep;
 };
 
+class LuaColorPicker : public LuaDialogWidget
+{
+public:
+       LuaColorPicker (std::string const& key)
+               : LuaDialogWidget (key, "", 0, 1)
+       {}
+
+       Gtk::Widget* widget ()
+       {
+               return &_cs;
+       }
+       void assign (luabridge::LuaRef* rv) const {
+               uint32_t rgba = ARDOUR_UI_UTILS::gdk_color_to_rgba(_cs.get_color());
+               (*rv)[_key] = rgba;
+       }
+protected:
+       Gtk::ColorButton _cs;
+};
+
 class LuaDialogCheckbox : public LuaDialogWidget
 {
 public:
@@ -504,14 +524,8 @@ public:
                        switch (a) {
                                case Gtk::FILE_CHOOSER_ACTION_OPEN:
                                case Gtk::FILE_CHOOSER_ACTION_SAVE:
-                                       if (Glib::file_test (path, Glib::FILE_TEST_IS_REGULAR|Glib::FILE_TEST_EXISTS)) {
-                                               _fc.set_filename (path);
-                                       }
-                                       break;
                                case Gtk::FILE_CHOOSER_ACTION_SELECT_FOLDER:
-                                       if (Glib::file_test (path, Glib::FILE_TEST_IS_DIR|Glib::FILE_TEST_EXISTS)) {
-                                               _fc.set_filename (path);
-                                       }
+                                       _fc.set_filename (path);
                                        break;
                                case Gtk::FILE_CHOOSER_ACTION_CREATE_FOLDER:
                                        break;
@@ -675,6 +689,8 @@ Dialog::Dialog (std::string const& title, luabridge::LuaRef lr)
                                path = i.value ()["path"].cast<std::string> ();
                        }
                        w = new LuaFileChooser (key, title, Gtk::FILE_CHOOSER_ACTION_SELECT_FOLDER, path);
+               } else if (type == "color") {
+                       w = new LuaColorPicker (key);
                }
 
                if (w) {
@@ -694,7 +710,14 @@ Dialog::Dialog (std::string const& title, luabridge::LuaRef lr)
        Gtk::Table* table = Gtk::manage (new Gtk::Table ());
        table->set_col_spacings (20);
        table->set_row_spacings (8);
-       _ad.get_vbox ()->pack_start (*table);
+       table->signal_size_allocate ().connect (sigc::mem_fun (this, &Dialog::table_size_alloc));
+
+       _scroller.set_shadow_type(Gtk::SHADOW_NONE);
+       _scroller.set_border_width(0);
+       _scroller.add (*table);
+       _scroller.set_policy (Gtk::POLICY_NEVER, Gtk::POLICY_NEVER);
+
+       _ad.get_vbox ()->pack_start (_scroller);
 
        int row = 0;
        int last_end = -1;
@@ -755,3 +778,13 @@ Dialog::run (lua_State *L)
        luabridge::push (L, rv);
        return 1;
 }
+
+void
+Dialog::table_size_alloc (Gtk::Allocation& allocation)
+{
+       /* XXX: consider using 0.75 * screen-height instead of 512 */
+       if (allocation.get_height () > 512) {
+               _scroller.set_policy (Gtk::POLICY_NEVER, Gtk::POLICY_AUTOMATIC);
+               _ad.set_size_request (-1, 512);
+       }
+}