diff --git a/src/dialog.cpp b/src/dialog.cpp index ca29bc9..caa9adb 100644 --- a/src/dialog.cpp +++ b/src/dialog.cpp @@ -1,6 +1,7 @@ #include "dialog.hpp" #include "filesystem.hpp" #include +#include Dialog::Message::Message(const std::string &text, std::function &&on_cancel, bool show_progress_bar) : Gtk::Window(Gtk::WindowType::WINDOW_POPUP) { set_transient_for(*Glib::RefPtr::cast_dynamic(Gtk::Application::get_default())->get_active_window()); @@ -52,6 +53,15 @@ bool Dialog::Message::on_delete_event(GdkEventAny *event) { return true; } +Dialog::MessageDialog::MessageDialog(Gtk::Window &parent, const Glib::ustring &message, bool use_markup, Gtk::MessageType type, Gtk::ButtonsType buttons, bool modal) + : Gtk::MessageDialog(parent, message, use_markup, type, buttons, modal) {} + +int Dialog::MessageDialog::run() { + auto response = Gtk::MessageDialog::run(); + Glib::RefPtr::cast_dynamic(Gtk::Application::get_default())->get_active_window()->present(); + return response; +} + std::string Dialog::gtk_dialog(const boost::filesystem::path &path, const std::string &title, const std::vector> &buttons, Gtk::FileChooserAction action) { @@ -95,7 +105,12 @@ std::string Dialog::gtk_dialog(const boost::filesystem::path &path, const std::s for(auto &button : buttons) dialog.add_button(button.first, button.second); - return dialog.run() == Gtk::RESPONSE_OK ? dialog.get_filename() : ""; + + dialog.show_all(); + dialog.present(); + auto response = dialog.run(); + Glib::RefPtr::cast_dynamic(Gtk::Application::get_default())->get_active_window()->present(); + return response == Gtk::RESPONSE_OK ? dialog.get_filename() : ""; } std::string Dialog::open_folder(const boost::filesystem::path &path) { diff --git a/src/dialog.hpp b/src/dialog.hpp index 5ea0230..e6603fa 100644 --- a/src/dialog.hpp +++ b/src/dialog.hpp @@ -18,6 +18,12 @@ public: Gtk::ProgressBar progress_bar; }; + class MessageDialog : public Gtk::MessageDialog { + public: + MessageDialog(Gtk::Window &parent, const Glib::ustring &message, bool use_markup = false, Gtk::MessageType type = Gtk::MESSAGE_INFO, Gtk::ButtonsType buttons = Gtk::BUTTONS_OK, bool modal = false); + int run(); + }; + private: static std::string gtk_dialog(const boost::filesystem::path &path, const std::string &title, const std::vector> &buttons, diff --git a/src/directories.cpp b/src/directories.cpp index 26ff42e..a0b7ecc 100644 --- a/src/directories.cpp +++ b/src/directories.cpp @@ -1,5 +1,6 @@ #include "directories.hpp" #include "config.hpp" +#include "dialog.hpp" #include "entrybox.hpp" #include "filesystem.hpp" #include "info.hpp" @@ -352,15 +353,16 @@ Directories::Directories() : Gtk::ListViewText(1) { menu_item_delete.signal_activate().connect([this] { if(menu_popup_row_path.empty()) return; - Gtk::MessageDialog dialog(*static_cast(get_toplevel()), "Delete?", false, Gtk::MESSAGE_QUESTION, Gtk::BUTTONS_YES_NO); + Dialog::MessageDialog dialog(*static_cast(get_toplevel()), "Delete?", false, Gtk::MESSAGE_QUESTION, Gtk::BUTTONS_YES_NO); Gtk::Image image; image.set_from_icon_name("dialog-warning", Gtk::BuiltinIconSize::ICON_SIZE_DIALOG); dialog.set_image(image); dialog.set_default_response(Gtk::RESPONSE_NO); dialog.set_secondary_text("Are you sure you want to delete " + filesystem::get_short_path(menu_popup_row_path).string() + "?"); dialog.show_all(); - int result = dialog.run(); - if(result == Gtk::RESPONSE_YES) { + dialog.present(); + int response = dialog.run(); + if(response == Gtk::RESPONSE_YES) { boost::system::error_code ec; bool is_directory = boost::filesystem::is_directory(menu_popup_row_path, ec); diff --git a/src/notebook.cpp b/src/notebook.cpp index 6ca1a86..c4368ab 100644 --- a/src/notebook.cpp +++ b/src/notebook.cpp @@ -238,16 +238,17 @@ bool Notebook::open(const boost::filesystem::path &file_path_, Position position if(show_dialog) { show_dialog = false; // Install rust-analyzer - Gtk::MessageDialog dialog(*static_cast(get_toplevel()), "Install Rust language server?", false, Gtk::MESSAGE_QUESTION, Gtk::BUTTONS_YES_NO); + Dialog::MessageDialog dialog(*static_cast(get_toplevel()), "Install Rust language server?", false, Gtk::MESSAGE_QUESTION, Gtk::BUTTONS_YES_NO); Gtk::Image image; image.set_from_icon_name("dialog-question", Gtk::BuiltinIconSize::ICON_SIZE_DIALOG); dialog.set_image(image); dialog.set_default_response(Gtk::RESPONSE_YES); dialog.set_secondary_text("Rust language server not found. Would you like to install rust-analyzer?"); dialog.show_all(); - int result = dialog.run(); + dialog.present(); + int response = dialog.run(); dialog.hide(); - if(result == Gtk::RESPONSE_YES) { + if(response == Gtk::RESPONSE_YES) { bool canceled = false; Dialog::Message message("Installing rust-analyzer", [&canceled] { canceled = true; @@ -611,16 +612,17 @@ void Notebook::install_rust() { static bool show_dialog = true; if(show_dialog) { show_dialog = false; - Gtk::MessageDialog dialog(*static_cast(get_toplevel()), "Install Rust?", false, Gtk::MESSAGE_QUESTION, Gtk::BUTTONS_YES_NO); + Dialog::MessageDialog dialog(*static_cast(get_toplevel()), "Install Rust?", false, Gtk::MESSAGE_QUESTION, Gtk::BUTTONS_YES_NO); Gtk::Image image; image.set_from_icon_name("dialog-question", Gtk::BuiltinIconSize::ICON_SIZE_DIALOG); dialog.set_image(image); dialog.set_default_response(Gtk::RESPONSE_YES); dialog.set_secondary_text("Rust not found. Would you like to install Rust?"); dialog.show_all(); - int result = dialog.run(); + dialog.present(); + int response = dialog.run(); dialog.hide(); - if(result == Gtk::RESPONSE_YES) { + if(response == Gtk::RESPONSE_YES) { bool canceled = false; Dialog::Message message("Installing Rust", [&canceled] { canceled = true; @@ -924,17 +926,18 @@ void Notebook::set_current_view(Source::View *view) { } bool Notebook::save_modified_dialog(size_t index) { - Gtk::MessageDialog dialog(*static_cast(get_toplevel()), "Save file?", false, Gtk::MESSAGE_QUESTION, Gtk::BUTTONS_YES_NO); + Dialog::MessageDialog dialog(*static_cast(get_toplevel()), "Save file?", false, Gtk::MESSAGE_QUESTION, Gtk::BUTTONS_YES_NO); Gtk::Image image; image.set_from_icon_name("document-save", Gtk::BuiltinIconSize::ICON_SIZE_DIALOG); dialog.set_image(image); dialog.set_default_response(Gtk::RESPONSE_YES); dialog.set_secondary_text("Do you want to save " + filesystem::get_short_path(get_view(index)->file_path).string() + "?"); dialog.show_all(); - int result = dialog.run(); - if(result == Gtk::RESPONSE_YES) + dialog.present(); + int response = dialog.run(); + if(response == Gtk::RESPONSE_YES) return save(index); - else if(result == Gtk::RESPONSE_NO) + else if(response == Gtk::RESPONSE_NO) return true; return false; } diff --git a/src/project.cpp b/src/project.cpp index cf7dc15..f041dcb 100644 --- a/src/project.cpp +++ b/src/project.cpp @@ -1,6 +1,7 @@ #include "project.hpp" #include "commands.hpp" #include "config.hpp" +#include "dialog.hpp" #include "directories.hpp" #include "filesystem.hpp" #include "menu.hpp" @@ -799,7 +800,7 @@ void Project::Clang::recreate_build() { bool has_debug_build = !debug_build_path.empty() && boost::filesystem::exists(debug_build_path, ec); if(has_default_build || has_debug_build) { - Gtk::MessageDialog dialog(*static_cast(Notebook::get().get_toplevel()), "Recreate Build?", false, Gtk::MESSAGE_QUESTION, Gtk::BUTTONS_YES_NO); + Dialog::MessageDialog dialog(*static_cast(Notebook::get().get_toplevel()), "Recreate Build?", false, Gtk::MESSAGE_QUESTION, Gtk::BUTTONS_YES_NO); Gtk::Image image; image.set_from_icon_name("dialog-question", Gtk::BuiltinIconSize::ICON_SIZE_DIALOG); dialog.set_image(image); @@ -814,6 +815,7 @@ void Project::Clang::recreate_build() { } dialog.set_secondary_text(message + "?"); dialog.show_all(); + dialog.present(); if(dialog.run() != Gtk::RESPONSE_YES) return; Usages::Clang::erase_all_caches_for_project(build->project_path, default_build_path); diff --git a/src/window.cpp b/src/window.cpp index 62891b9..a664181 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -156,6 +156,7 @@ Window::Window() { about.signal_response().connect([this](int d) { about.hide(); + present(); }); about.set_logo_icon_name("juci");