From 33cb59e5c6e993861d354d3740f2d2298339952b Mon Sep 17 00:00:00 2001 From: Vivek Thazhathattil <63693789+VivekThazhathattil@users.noreply.github.com> Date: Sat, 17 Jul 2021 01:24:23 +0530 Subject: [PATCH] Fix some blank messageboxes that shows no context except the 'OK' button (#3214) * fix empty error msg box * free markup escaped strings --- src/util/XojMsgBox.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/util/XojMsgBox.cpp b/src/util/XojMsgBox.cpp index 97bdc6e7..b7dce4fb 100644 --- a/src/util/XojMsgBox.cpp +++ b/src/util/XojMsgBox.cpp @@ -22,12 +22,15 @@ void XojMsgBox::showErrorToUser(GtkWindow* win, const string& msg) { GtkWidget* dialog = gtk_message_dialog_new_with_markup(win, GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, nullptr); - gtk_message_dialog_set_markup(GTK_MESSAGE_DIALOG(dialog), msg.c_str()); + + char* formattedMsg = g_markup_escape_text(msg.c_str(), -1); + gtk_message_dialog_set_markup(GTK_MESSAGE_DIALOG(dialog), formattedMsg); if (win != nullptr) { gtk_window_set_transient_for(GTK_WINDOW(dialog), win); } gtk_dialog_run(GTK_DIALOG(dialog)); gtk_widget_destroy(dialog); + g_free(formattedMsg); } auto XojMsgBox::showPluginMessage(const string& pluginName, const string& msg, const map& button, @@ -40,7 +43,8 @@ auto XojMsgBox::showPluginMessage(const string& pluginName, const string& msg, c GtkWidget* dialog = gtk_message_dialog_new_with_markup(defaultWindow, GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR, GTK_BUTTONS_NONE, nullptr); - gtk_message_dialog_set_markup(GTK_MESSAGE_DIALOG(dialog), header.c_str()); + char* formattedHeader = g_markup_escape_text(header.c_str(), -1); + gtk_message_dialog_set_markup(GTK_MESSAGE_DIALOG(dialog), formattedHeader); if (defaultWindow != nullptr) { gtk_window_set_transient_for(GTK_WINDOW(dialog), defaultWindow); @@ -52,12 +56,11 @@ auto XojMsgBox::showPluginMessage(const string& pluginName, const string& msg, c g_object_set_property(G_OBJECT(dialog), "secondary-text", &val); g_value_unset(&val); - for (auto& kv: button) { - gtk_dialog_add_button(GTK_DIALOG(dialog), kv.second.c_str(), kv.first); - } + for (auto& kv: button) { gtk_dialog_add_button(GTK_DIALOG(dialog), kv.second.c_str(), kv.first); } int res = gtk_dialog_run(GTK_DIALOG(dialog)); gtk_widget_destroy(dialog); + g_free(formattedHeader); return res; }