[eog] EogCloseConfirmationDialog: Convert to GtkMessageDialog



commit 4804e68c3398a0fc1840a3efbbea6d497f4cd0a5
Author: Felix Riemann <friemann gnome org>
Date:   Sun Nov 19 19:17:50 2017 +0100

    EogCloseConfirmationDialog: Convert to GtkMessageDialog
    
    This makes the dialog look more modern like the dialogs in
    other GNOME apps.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=787188

 src/eog-close-confirmation-dialog.c |  127 ++++++-----------------------------
 src/eog-close-confirmation-dialog.h |    4 +-
 2 files changed, 22 insertions(+), 109 deletions(-)
---
diff --git a/src/eog-close-confirmation-dialog.c b/src/eog-close-confirmation-dialog.c
index f945358..5574967 100644
--- a/src/eog-close-confirmation-dialog.c
+++ b/src/eog-close-confirmation-dialog.c
@@ -81,7 +81,7 @@ struct _EogCloseConfirmationDialogPrivate
 
 #define IMAGE_COLUMN_HEIGHT 40
 
-G_DEFINE_TYPE_WITH_PRIVATE(EogCloseConfirmationDialog, eog_close_confirmation_dialog, GTK_TYPE_DIALOG)
+G_DEFINE_TYPE_WITH_PRIVATE(EogCloseConfirmationDialog, eog_close_confirmation_dialog, 
GTK_TYPE_MESSAGE_DIALOG)
 
 static void     set_unsaved_image              (EogCloseConfirmationDialog *dlg,
                                                 const GList                  *list);
@@ -193,24 +193,15 @@ add_buttons (EogCloseConfirmationDialog          *dlg,
 static void
 eog_close_confirmation_dialog_init (EogCloseConfirmationDialog *dlg)
 {
-       AtkObject *atk_obj;
-
        dlg->priv = eog_close_confirmation_dialog_get_instance_private (dlg);
 
-       gtk_container_set_border_width (GTK_CONTAINER (dlg), 5);
-       gtk_box_set_spacing (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dlg))), 14);
        gtk_window_set_resizable (GTK_WINDOW (dlg), FALSE);
-       gtk_window_set_skip_taskbar_hint (GTK_WINDOW (dlg), TRUE);
 
        gtk_window_set_title (GTK_WINDOW (dlg), "");
 
        gtk_window_set_modal (GTK_WINDOW (dlg), TRUE);
        gtk_window_set_destroy_with_parent (GTK_WINDOW (dlg), TRUE);
 
-       atk_obj = gtk_widget_get_accessible (GTK_WIDGET (dlg));
-       atk_object_set_role (atk_obj, ATK_ROLE_ALERT);
-       atk_object_set_name (atk_obj, _("Question"));
-
        g_signal_connect (dlg,
                          "response",
                          G_CALLBACK (response_cb),
@@ -345,6 +336,7 @@ eog_close_confirmation_dialog_new (GtkWindow *parent,
 
        dlg = GTK_WIDGET (g_object_new (EOG_TYPE_CLOSE_CONFIRMATION_DIALOG,
                                        "unsaved_images", unsaved_images,
+                                       "message-type", GTK_MESSAGE_QUESTION,
                                        NULL));
        g_return_val_if_fail (dlg != NULL, NULL);
 
@@ -396,11 +388,6 @@ get_text_secondary_label (EogImage *image)
 static void
 build_single_img_dialog (EogCloseConfirmationDialog *dlg)
 {
-       GtkWidget     *hbox;
-       GtkWidget     *vbox;
-       GtkWidget     *primary_label;
-       GtkWidget     *secondary_label;
-       GtkWidget     *image;
        EogImage      *img;
        const gchar   *image_name;
        gchar         *str;
@@ -411,27 +398,7 @@ build_single_img_dialog (EogCloseConfirmationDialog *dlg)
        g_return_if_fail (dlg->priv->unsaved_images->data != NULL);
        img = EOG_IMAGE (dlg->priv->unsaved_images->data);
 
-       /* Image */
-       image = gtk_image_new_from_icon_name ("dialog-warning-symbolic",
-                                             GTK_ICON_SIZE_DIALOG);
-       gtk_widget_set_valign (image, GTK_ALIGN_START);
-
        /* Primary label */
-       primary_label = gtk_label_new (NULL);
-       gtk_label_set_line_wrap (GTK_LABEL (primary_label), TRUE);
-       gtk_label_set_use_markup (GTK_LABEL (primary_label), TRUE);
-       gtk_widget_set_halign (primary_label, GTK_ALIGN_START);
-       gtk_widget_set_valign (primary_label, GTK_ALIGN_START);
-       gtk_label_set_max_width_chars(GTK_LABEL (primary_label), 72);
-       /* Allow fallback to char-based wrapping as filenames
-        * don't need to have "words". */
-       gtk_label_set_line_wrap_mode(GTK_LABEL (primary_label),
-                                    PANGO_WRAP_WORD_CHAR);
-G_GNUC_BEGIN_IGNORE_DEPRECATIONS
-       gtk_misc_set_alignment(GTK_MISC (primary_label), 0.0, 0.5);
-G_GNUC_END_IGNORE_DEPRECATIONS
-       gtk_label_set_selectable (GTK_LABEL (primary_label), TRUE);
-
        image_name = eog_image_get_caption (img);
 
        str = g_markup_printf_escaped (_("Save changes to image “%s” before closing?"),
@@ -439,40 +406,16 @@ G_GNUC_END_IGNORE_DEPRECATIONS
        markup_str = g_strconcat ("<span weight=\"bold\" size=\"larger\">", str, "</span>", NULL);
        g_free (str);
 
-       gtk_label_set_markup (GTK_LABEL (primary_label), markup_str);
+       gtk_message_dialog_set_markup (GTK_MESSAGE_DIALOG (dlg), markup_str);
        g_free (markup_str);
 
        /* Secondary label */
        str = get_text_secondary_label (img);
 
-       secondary_label = gtk_label_new (str);
+       //secondary_label = gtk_label_new (str);
+       gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dlg),
+                                                 "%s", str);
        g_free (str);
-       gtk_label_set_line_wrap (GTK_LABEL (secondary_label), TRUE);
-       gtk_label_set_max_width_chars(GTK_LABEL (secondary_label), 72);
-G_GNUC_BEGIN_IGNORE_DEPRECATIONS
-       gtk_misc_set_alignment(GTK_MISC (secondary_label), 0.0, 0.5);
-G_GNUC_END_IGNORE_DEPRECATIONS
-       gtk_widget_set_halign (secondary_label, GTK_ALIGN_START);
-       gtk_label_set_selectable (GTK_LABEL (secondary_label), TRUE);
-
-       hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
-       gtk_container_set_border_width (GTK_CONTAINER (hbox), 5);
-
-       gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);
-
-       vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12);
-
-       gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0);
-
-       gtk_box_pack_start (GTK_BOX (vbox), primary_label, TRUE, TRUE, 0);
-
-       gtk_box_pack_start (GTK_BOX (vbox), secondary_label, TRUE, TRUE, 0);
-
-       gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dlg))),
-                           hbox,
-                           FALSE,
-                           FALSE,
-                           0);
 
        if (eog_image_is_file_writable (img)) {
                buttons = EOG_CLOSE_CONFIRMATION_DIALOG_CLOSE_BUTTON |
@@ -485,9 +428,6 @@ G_GNUC_END_IGNORE_DEPRECATIONS
        }
 
        add_buttons (dlg, buttons);
-
-
-       gtk_widget_show_all (hbox);
 }
 
 static void
@@ -607,11 +547,7 @@ static void
 build_multiple_imgs_dialog (EogCloseConfirmationDialog *dlg)
 {
        EogCloseConfirmationDialogPrivate *priv;
-       GtkWidget *hbox;
-       GtkWidget *image;
        GtkWidget *vbox;
-       GtkWidget *primary_label;
-       GtkWidget *vbox2;
        GtkWidget *select_label;
        GtkWidget *scrolledwindow;
        GtkWidget *treeview;
@@ -623,31 +559,7 @@ build_multiple_imgs_dialog (EogCloseConfirmationDialog *dlg)
 
        priv = dlg->priv;
 
-       hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
-       gtk_container_set_border_width (GTK_CONTAINER (hbox), 5);
-       gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dlg))),
-                           hbox, TRUE, TRUE, 0);
-
-       /* Image */
-       image = gtk_image_new_from_icon_name ("dialog-warning-symbolic",
-                                             GTK_ICON_SIZE_DIALOG);
-       gtk_widget_set_valign (image, GTK_ALIGN_START);
-       gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0);
-
-       vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12);
-       gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0);
-
        /* Primary label */
-       primary_label = gtk_label_new (NULL);
-       gtk_label_set_line_wrap (GTK_LABEL (primary_label), TRUE);
-       gtk_label_set_use_markup (GTK_LABEL (primary_label), TRUE);
-       gtk_widget_set_halign (primary_label, GTK_ALIGN_START);
-       gtk_label_set_max_width_chars (GTK_LABEL (primary_label), 72);
-G_GNUC_BEGIN_IGNORE_DEPRECATIONS
-       gtk_misc_set_alignment(GTK_MISC (primary_label), 0.0, 0.5);
-G_GNUC_END_IGNORE_DEPRECATIONS
-       gtk_label_set_selectable (GTK_LABEL (primary_label), TRUE);
-
        str = g_strdup_printf (
                        ngettext ("There is %d image with unsaved changes. "
                                  "Save changes before closing?",
@@ -656,24 +568,27 @@ G_GNUC_END_IGNORE_DEPRECATIONS
                                  g_list_length (priv->unsaved_images)),
                        g_list_length (priv->unsaved_images));
 
-       markup_str = g_strconcat ("<span weight=\"bold\" size=\"larger\">", str, "</span>", NULL);
+       markup_str = g_strconcat ("<span weight=\"bold\" size=\"larger\">",
+                                 str, "</span>", NULL);
        g_free (str);
 
-       gtk_label_set_markup (GTK_LABEL (primary_label), markup_str);
+       gtk_message_dialog_set_markup (GTK_MESSAGE_DIALOG (dlg), markup_str);
        g_free (markup_str);
-       gtk_box_pack_start (GTK_BOX (vbox), primary_label, TRUE, TRUE, 0);
-
-       vbox2 = gtk_box_new (GTK_ORIENTATION_VERTICAL, 8);
-       gtk_box_pack_start (GTK_BOX (vbox), vbox2, TRUE, TRUE, 0);
 
+       vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 8);
+       gtk_widget_set_margin_start (vbox, 18);
+       gtk_widget_set_margin_end (vbox, 18);
+       gtk_widget_set_margin_bottom (vbox, 12);
+       gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dlg))),
+                                    vbox, TRUE, TRUE, 0);
        select_label = gtk_label_new_with_mnemonic (_("S_elect the images you want to save:"));
 
-       gtk_box_pack_start (GTK_BOX (vbox2), select_label, FALSE, FALSE, 0);
+       gtk_box_pack_start (GTK_BOX (vbox), select_label, FALSE, FALSE, 0);
        gtk_label_set_line_wrap (GTK_LABEL (select_label), TRUE);
        gtk_widget_set_halign (select_label, GTK_ALIGN_START);
 
        scrolledwindow = gtk_scrolled_window_new (NULL, NULL);
-       gtk_box_pack_start (GTK_BOX (vbox2), scrolledwindow, TRUE, TRUE, 0);
+       gtk_box_pack_start (GTK_BOX (vbox), scrolledwindow, TRUE, TRUE, 0);
        gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwindow),
                                        GTK_POLICY_AUTOMATIC,
                                        GTK_POLICY_AUTOMATIC);
@@ -688,13 +603,11 @@ G_GNUC_END_IGNORE_DEPRECATIONS
        secondary_label = gtk_label_new (_("If you don’t save, "
                                           "all your changes will be lost."));
 
-       gtk_box_pack_start (GTK_BOX (vbox2), secondary_label, FALSE, FALSE, 0);
+       gtk_box_pack_start (GTK_BOX (vbox), secondary_label, FALSE, FALSE, 0);
        gtk_label_set_line_wrap (GTK_LABEL (secondary_label), TRUE);
        gtk_label_set_max_width_chars (GTK_LABEL (secondary_label), 72);
        gtk_widget_set_halign (secondary_label, GTK_ALIGN_START);
-G_GNUC_BEGIN_IGNORE_DEPRECATIONS
-       gtk_misc_set_alignment(GTK_MISC (select_label), 0.0, 0.5);
-G_GNUC_END_IGNORE_DEPRECATIONS
+       gtk_label_set_xalign (GTK_LABEL (select_label), 0.0);
        gtk_label_set_selectable (GTK_LABEL (secondary_label), TRUE);
 
        gtk_label_set_mnemonic_widget (GTK_LABEL (select_label), treeview);
@@ -705,7 +618,7 @@ G_GNUC_END_IGNORE_DEPRECATIONS
 
        add_buttons (dlg, buttons);
 
-       gtk_widget_show_all (hbox);
+       gtk_widget_show_all (vbox);
 }
 
 static void
diff --git a/src/eog-close-confirmation-dialog.h b/src/eog-close-confirmation-dialog.h
index e8510d9..e809a32 100644
--- a/src/eog-close-confirmation-dialog.h
+++ b/src/eog-close-confirmation-dialog.h
@@ -44,7 +44,7 @@ typedef struct _EogCloseConfirmationDialogPrivate     EogCloseConfirmationDialogPri
 
 struct _EogCloseConfirmationDialog
 {
-       GtkDialog parent;
+       GtkMessageDialog parent;
 
        /*< private > */
        EogCloseConfirmationDialogPrivate *priv;
@@ -52,7 +52,7 @@ struct _EogCloseConfirmationDialog
 
 struct _EogCloseConfirmationDialogClass
 {
-       GtkDialogClass parent_class;
+       GtkMessageDialogClass parent_class;
 };
 
 /**


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