summaryrefslogtreecommitdiff
path: root/gtk2_ardour/luadialog.cc
diff options
context:
space:
mode:
authorRobin Gareus <robin@gareus.org>2019-08-12 01:06:14 +0200
committerRobin Gareus <robin@gareus.org>2019-08-12 01:37:35 +0200
commit7251efce83a7c26d4377ace3e894a6da1e0c15e5 (patch)
tree56fe6f9bf94f5760003162bd9ab65316b71a37da /gtk2_ardour/luadialog.cc
parent807061f96f6bbb3d353068e610a0d97cad1e760a (diff)
Add Lua-Dialog support for FileChooserWidget (save file)
Diffstat (limited to 'gtk2_ardour/luadialog.cc')
-rw-r--r--gtk2_ardour/luadialog.cc52
1 files changed, 51 insertions, 1 deletions
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<std::string> ();
}
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<std::string> ();
+ }
+ 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<std::string> ();
+ }
+ w = new LuaFileChooserWidget (key, title, Gtk::FILE_CHOOSER_ACTION_CREATE_FOLDER, path);
} else if (type == "color") {
w = new LuaColorPicker (key);
}