From 7251efce83a7c26d4377ace3e894a6da1e0c15e5 Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Mon, 12 Aug 2019 01:06:14 +0200 Subject: [PATCH] Add Lua-Dialog support for FileChooserWidget (save file) --- gtk2_ardour/luadialog.cc | 52 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) diff --git a/gtk2_ardour/luadialog.cc b/gtk2_ardour/luadialog.cc index 0ff6e3fac2..9ce1e4b03c 100644 --- a/gtk2_ardour/luadialog.cc +++ b/gtk2_ardour/luadialog.cc @@ -525,11 +525,12 @@ public: if (!path.empty ()) { switch (a) { case Gtk::FILE_CHOOSER_ACTION_OPEN: - case Gtk::FILE_CHOOSER_ACTION_SAVE: case Gtk::FILE_CHOOSER_ACTION_SELECT_FOLDER: _fc.set_filename (path); break; + case Gtk::FILE_CHOOSER_ACTION_SAVE: case Gtk::FILE_CHOOSER_ACTION_CREATE_FOLDER: + /* not supported by Gtk::FileChooserButton */ break; } } @@ -550,6 +551,43 @@ protected: }; +class LuaFileChooserWidget : public LuaDialogWidget +{ +public: + LuaFileChooserWidget (std::string const& key, std::string const& title, Gtk::FileChooserAction a, const std::string& path) + : LuaDialogWidget (key, title) + , _fc (a) + { + Gtkmm2ext::add_volume_shortcuts (_fc); + if (!path.empty ()) { + switch (a) { + case Gtk::FILE_CHOOSER_ACTION_OPEN: + case Gtk::FILE_CHOOSER_ACTION_SELECT_FOLDER: + _fc.set_filename (path); + break; + case Gtk::FILE_CHOOSER_ACTION_SAVE: + case Gtk::FILE_CHOOSER_ACTION_CREATE_FOLDER: + _fc.set_filename (path); + _fc.set_current_name (Glib::path_get_basename (path)); + break; + break; + } + } + } + + Gtk::Widget* widget () + { + return &_fc; + } + + void assign (luabridge::LuaRef* rv) const + { + (*rv)[_key] = std::string (_fc.get_filename ()); + } + +protected: + Gtk::FileChooserWidget _fc; +}; /******************************************************************************* * Lua Parameter Dialog @@ -691,6 +729,18 @@ Dialog::Dialog (std::string const& title, luabridge::LuaRef lr) path = i.value ()["path"].cast (); } w = new LuaFileChooser (key, title, Gtk::FILE_CHOOSER_ACTION_SELECT_FOLDER, path); + } else if (type == "createfile") { + std::string path; + if (i.value ()["path"].isString ()) { + path = i.value ()["path"].cast (); + } + w = new LuaFileChooserWidget (key, title, Gtk::FILE_CHOOSER_ACTION_SAVE, path); + } else if (type == "createdir") { + std::string path; + if (i.value ()["path"].isString ()) { + path = i.value ()["path"].cast (); + } + w = new LuaFileChooserWidget (key, title, Gtk::FILE_CHOOSER_ACTION_CREATE_FOLDER, path); } else if (type == "color") { w = new LuaColorPicker (key); }