mirror of https://gitlab.com/cppit/jucipp
6 changed files with 112 additions and 49 deletions
@ -1,32 +1,70 @@ |
|||||||
#include "dialogs.h" |
#include "dialogs.h" |
||||||
|
#include "juci.h" |
||||||
|
#include "singletons.h" |
||||||
|
|
||||||
std::string Dialog::open_folder() { |
namespace sigc { |
||||||
return gtk_dialog("Open Folder", |
#ifndef SIGC_FUNCTORS_DEDUCE_RESULT_TYPE_WITH_DECLTYPE |
||||||
{std::make_pair("Cancel", Gtk::RESPONSE_CANCEL),std::make_pair("Open", Gtk::RESPONSE_OK)}, |
template <typename Functor> |
||||||
Gtk::FILE_CHOOSER_ACTION_SELECT_FOLDER); |
struct functor_trait<Functor, false> { |
||||||
|
typedef decltype (::sigc::mem_fun(std::declval<Functor&>(), |
||||||
|
&Functor::operator())) _intermediate; |
||||||
|
typedef typename _intermediate::result_type result_type; |
||||||
|
typedef Functor functor_type; |
||||||
|
}; |
||||||
|
#else |
||||||
|
SIGC_FUNCTORS_DEDUCE_RESULT_TYPE_WITH_DECLTYPE |
||||||
|
#endif |
||||||
} |
} |
||||||
|
|
||||||
std::string Dialog::new_file() { |
Dialog::Message::Message(const std::string &text): Gtk::Window(Gtk::WindowType::WINDOW_POPUP), label(text) { |
||||||
return gtk_dialog("New File", |
auto font_desc=label.get_pango_context()->get_font_description(); |
||||||
{std::make_pair("Cancel", Gtk::RESPONSE_CANCEL), std::make_pair("Save", Gtk::RESPONSE_OK)}, |
font_desc.set_size(font_desc.get_size()*2); |
||||||
Gtk::FILE_CHOOSER_ACTION_SAVE); |
label.create_pango_context(); |
||||||
} |
label.get_pango_context()->set_font_description(font_desc); |
||||||
|
add(label); |
||||||
|
|
||||||
std::string Dialog::new_folder() { |
property_decorated()=false; |
||||||
return gtk_dialog("New Folder", |
set_accept_focus(false); |
||||||
{std::make_pair("Cancel", Gtk::RESPONSE_CANCEL),std::make_pair("Create", Gtk::RESPONSE_OK)}, |
set_skip_taskbar_hint(true); |
||||||
Gtk::FILE_CHOOSER_ACTION_CREATE_FOLDER); |
|
||||||
} |
|
||||||
|
|
||||||
std::string Dialog::open_file() { |
auto g_application=g_application_get_default(); |
||||||
return gtk_dialog("Open File", |
auto gio_application=Glib::wrap(g_application, true); |
||||||
{std::make_pair("Cancel", Gtk::RESPONSE_CANCEL),std::make_pair("Select", Gtk::RESPONSE_OK)}, |
auto application=Glib::RefPtr<Application>::cast_static(gio_application); |
||||||
Gtk::FILE_CHOOSER_ACTION_OPEN); |
set_transient_for(*application->window); |
||||||
|
set_position(Gtk::WindowPosition::WIN_POS_CENTER_ON_PARENT); |
||||||
|
label.signal_draw().connect([this](const Cairo::RefPtr<Cairo::Context>& cr) { |
||||||
|
label_drawn=true; |
||||||
|
return false; |
||||||
|
}); |
||||||
|
show_all(); |
||||||
} |
} |
||||||
|
|
||||||
std::string Dialog::save_file_as(const boost::filesystem::path &file_path) { |
void Dialog::Message::wait_until_drawn() { |
||||||
return gtk_dialog("Save File As", |
while(gtk_events_pending() || !label_drawn) |
||||||
{std::make_pair("Cancel", Gtk::RESPONSE_CANCEL),std::make_pair("Save", Gtk::RESPONSE_OK)}, |
gtk_main_iteration(); |
||||||
Gtk::FILE_CHOOSER_ACTION_SAVE, file_path.string()); |
|
||||||
} |
} |
||||||
|
|
||||||
|
std::string Dialog::gtk_dialog(const std::string &title, |
||||||
|
const std::vector<std::pair<std::string, Gtk::ResponseType>> &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<Application>::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() : ""; |
||||||
|
} |
||||||
|
|||||||
@ -0,0 +1,32 @@ |
|||||||
|
#include "dialogs.h" |
||||||
|
|
||||||
|
std::string Dialog::open_folder() { |
||||||
|
return gtk_dialog("Open Folder", |
||||||
|
{std::make_pair("Cancel", Gtk::RESPONSE_CANCEL),std::make_pair("Open", Gtk::RESPONSE_OK)}, |
||||||
|
Gtk::FILE_CHOOSER_ACTION_SELECT_FOLDER); |
||||||
|
} |
||||||
|
|
||||||
|
std::string Dialog::new_file() { |
||||||
|
return gtk_dialog("New File", |
||||||
|
{std::make_pair("Cancel", Gtk::RESPONSE_CANCEL), std::make_pair("Save", Gtk::RESPONSE_OK)}, |
||||||
|
Gtk::FILE_CHOOSER_ACTION_SAVE); |
||||||
|
} |
||||||
|
|
||||||
|
std::string Dialog::new_folder() { |
||||||
|
return gtk_dialog("New Folder", |
||||||
|
{std::make_pair("Cancel", Gtk::RESPONSE_CANCEL),std::make_pair("Create", Gtk::RESPONSE_OK)}, |
||||||
|
Gtk::FILE_CHOOSER_ACTION_CREATE_FOLDER); |
||||||
|
} |
||||||
|
|
||||||
|
std::string Dialog::open_file() { |
||||||
|
return gtk_dialog("Open File", |
||||||
|
{std::make_pair("Cancel", Gtk::RESPONSE_CANCEL),std::make_pair("Select", Gtk::RESPONSE_OK)}, |
||||||
|
Gtk::FILE_CHOOSER_ACTION_OPEN); |
||||||
|
} |
||||||
|
|
||||||
|
std::string Dialog::save_file_as(const boost::filesystem::path &file_path) { |
||||||
|
return gtk_dialog("Save File As", |
||||||
|
{std::make_pair("Cancel", Gtk::RESPONSE_CANCEL),std::make_pair("Save", Gtk::RESPONSE_OK)}, |
||||||
|
Gtk::FILE_CHOOSER_ACTION_SAVE, file_path.string()); |
||||||
|
} |
||||||
|
|
||||||
Loading…
Reference in new issue