#ifndef JUCI_DIALOG_H_ #define JUCI_DIALOG_H_ #include #include #include #include #include "singletons.h" #include "juci.h" class Dialog { public: static std::string open_folder(); static std::string open_file(); static std::string new_file(); static std::string new_folder(); static std::string save_file_as(const boost::filesystem::path &file_path); private: static std::string gtk_dialog(const std::string &title, const std::vector> &buttons, Gtk::FileChooserAction gtk_options, const std::string &file_name = "") { Gtk::FileChooserDialog dialog(title, gtk_options); auto g_application=g_application_get_default(); //TODO: Post issue that Gio::Application::get_default should return pointer and not Glib::RefPtr auto gio_application=Glib::wrap(g_application, true); auto application=Glib::RefPtr::cast_static(gio_application); dialog.set_transient_for(*application->window); auto current_path=application->window->notebook.get_current_folder(); if(current_path.empty()) current_path=boost::filesystem::current_path(); gtk_file_chooser_set_current_folder((GtkFileChooser*)dialog.gobj(), current_path.string().c_str()); if (!file_name.empty()) gtk_file_chooser_set_filename((GtkFileChooser*)dialog.gobj(), file_name.c_str()); dialog.set_position(Gtk::WindowPosition::WIN_POS_CENTER_ALWAYS); for (auto &button : buttons) dialog.add_button(button.first, button.second); return dialog.run() == Gtk::RESPONSE_OK ? dialog.get_filename() : ""; } }; #endif //JUCI_DIALOG_H_