[planner: 51/61] planner-window: Make use of GtkMessageDialog secondary text support




commit b9fdc9b175fb788223fd759203e27361ad9c56b2
Author: Mart Raudsepp <leio gentoo org>
Date:   Sun Jan 3 02:24:25 2021 +0200

    planner-window: Make use of GtkMessageDialog secondary text support
    
    Secondary text support was added to GtkMessageDialog since GTK 2.6.
    Make use of it, instead of manually markup formatting it.
    This changes the primary text a bit bigger, and starts wrapping the
    secondary text, because the hack that was used to get it to not wrap
    won't work with GTK3 (GSEAL). It's bad to disable the wrapping anyhow,
    as some translation might theoretically make it much longer, thus
    need the wrapping, and the old wrap disabling seems to rely on the
    button texts making the dialog very wide already (which again might
    be more narrow in some other languages).
    
    This also allowed to remove some temporary string allocations, as
    the "new" gtk_message_dialog_format_secondary_text can handle
    printf()-style formatting on its own.

 src/planner-window.c | 65 +++++++++++++++++++---------------------------------
 1 file changed, 23 insertions(+), 42 deletions(-)
---
diff --git a/src/planner-window.c b/src/planner-window.c
index c14441f7..3def8208 100644
--- a/src/planner-window.c
+++ b/src/planner-window.c
@@ -1309,19 +1309,26 @@ static gboolean
 window_confirm_exit_run (PlannerWindow *window)
 {
        PlannerWindowPriv *priv;
-       gchar            *time_str;
        GtkWidget        *dialog;
        GtkWidget        *quit_button, *cancel_button, *save_button;
        gint              ret;
        gint              minutes;
        gint              hours;
        gchar            *name;
-       gchar            *tmp;
        const gchar      *uri;
        gboolean          is_sql = FALSE;
 
        priv = window->priv;
 
+       name = window_get_name (window);
+       dialog = gtk_message_dialog_new (GTK_WINDOW (window),
+                                        GTK_DIALOG_MODAL |
+                                        GTK_DIALOG_DESTROY_WITH_PARENT,
+                                        GTK_MESSAGE_WARNING,
+                                        GTK_BUTTONS_NONE,
+                                        _("Save changes to document '%s' before closing?"), name);
+       g_free (name);
+
        minutes = (gint) (g_timer_elapsed (priv->last_saved, NULL) / 60);
 
        minutes = MAX (1, minutes);
@@ -1329,53 +1336,27 @@ window_confirm_exit_run (PlannerWindow *window)
        minutes -= 60 * hours;
 
        if (hours == 0 && minutes == 1) {
-               time_str = g_strdup (_("If you don't save, changes made "
-                                      "the last minute will be discarded."));
+               gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
+                       _("If you don't save, changes made the last minute will be discarded."));
        }
        else if (hours == 0) {
-               time_str =
-                       g_strdup_printf (ngettext(
-                                          "If you don't save, changes made "
-                                          "the last %d minute will be "
-                                          "discarded.",
-                                          "If you don't save, changes made "
-                                          "the last %d minutes will be "
-                                          "discarded.", minutes), minutes);
+               gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
+                       ngettext("If you don't save, changes made the last %d minute will be discarded.",
+                                "If you don't save, changes made the last %d minutes will be discarded.",
+                                minutes),
+                       minutes);
        }
        else if (hours == 1) {
-               time_str = g_strdup (_("If you don't save, changes made "
-                                      "the last hour will be "
-                                      "discarded."));
+               gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
+                       _("If you don't save, changes made the last hour will be discarded."));
        } else {
-               time_str =
-                       g_strdup_printf (ngettext("If you don't save, changes made "
-                                          "the last %d hour will be "
-                                          "discarded.",
-                                          "If you don't save, changes made "
-                                          "the last %d hours will be "
-                                          "discarded.", hours), hours);
+               gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
+                       ngettext("If you don't save, changes made the last %d hour will be discarded.",
+                                "If you don't save, changes made the last %d hours will be discarded.",
+                                hours),
+                       hours);
        }
 
-       name = window_get_name (window);
-
-       tmp = g_strdup_printf (_("Save changes to document '%s' before closing?"), name);
-
-       dialog = gtk_message_dialog_new (GTK_WINDOW (window),
-                                        GTK_DIALOG_MODAL |
-                                        GTK_DIALOG_DESTROY_WITH_PARENT,
-                                        GTK_MESSAGE_WARNING,
-                                        GTK_BUTTONS_NONE,
-                                        "<b>%s</b>\n%s", tmp, time_str);
-       g_free (name);
-       g_free (time_str);
-       g_free (tmp);
-
-       g_object_set (GTK_MESSAGE_DIALOG (dialog)->label,
-                     "use-markup", TRUE,
-                     "wrap", FALSE,
-                     "selectable", FALSE,
-                     NULL);
-
        uri = mrp_project_get_uri (priv->project);
        if (uri && strncmp (uri, "sql://", 6) == 0) {
                /* Hack. */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]