Browse Source

Fixed dialog focus problem on MacOS

merge-requests/428/merge
eidheim 4 months ago
parent
commit
423f140c3d
  1. 17
      src/dialog.cpp
  2. 6
      src/dialog.hpp
  3. 8
      src/directories.cpp
  4. 23
      src/notebook.cpp
  5. 4
      src/project.cpp
  6. 1
      src/window.cpp

17
src/dialog.cpp

@ -1,6 +1,7 @@
#include "dialog.hpp"
#include "filesystem.hpp"
#include <cmath>
#include <iostream>
Dialog::Message::Message(const std::string &text, std::function<void()> &&on_cancel, bool show_progress_bar) : Gtk::Window(Gtk::WindowType::WINDOW_POPUP) {
set_transient_for(*Glib::RefPtr<Gtk::Application>::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<Gtk::Application>::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<std::pair<std::string, Gtk::ResponseType>> &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<Gtk::Application>::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) {

6
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<std::pair<std::string, Gtk::ResponseType>> &buttons,

8
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<Gtk::Window *>(get_toplevel()), "Delete?", false, Gtk::MESSAGE_QUESTION, Gtk::BUTTONS_YES_NO);
Dialog::MessageDialog dialog(*static_cast<Gtk::Window *>(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);

23
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<Gtk::Window *>(get_toplevel()), "Install Rust language server?", false, Gtk::MESSAGE_QUESTION, Gtk::BUTTONS_YES_NO);
Dialog::MessageDialog dialog(*static_cast<Gtk::Window *>(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<Gtk::Window *>(get_toplevel()), "Install Rust?", false, Gtk::MESSAGE_QUESTION, Gtk::BUTTONS_YES_NO);
Dialog::MessageDialog dialog(*static_cast<Gtk::Window *>(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<Gtk::Window *>(get_toplevel()), "Save file?", false, Gtk::MESSAGE_QUESTION, Gtk::BUTTONS_YES_NO);
Dialog::MessageDialog dialog(*static_cast<Gtk::Window *>(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;
}

4
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<Gtk::Window *>(Notebook::get().get_toplevel()), "Recreate Build?", false, Gtk::MESSAGE_QUESTION, Gtk::BUTTONS_YES_NO);
Dialog::MessageDialog dialog(*static_cast<Gtk::Window *>(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);

1
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");

Loading…
Cancel
Save