[nautilus/wip/cdavis/use-adw-message-dialog: 1/5] mime-actions: Use AdwMessageDialog




commit 18d935e920231b5c8c26e14c4564b629da2bdc70
Author: Christopher Davis <christopherdavis gnome org>
Date:   Wed Jul 6 19:53:52 2022 -0400

    mime-actions: Use AdwMessageDialog
    
    Replaces GtkMessageDialog and the use of the eel dialog APIs
    with the new AdwMessageDialog API. This gives us an adaptive
    message dialog with formatting and consistent styling without
    any effort on our part.

 src/nautilus-mime-actions.c | 131 ++++++++++++++++++++------------------------
 1 file changed, 58 insertions(+), 73 deletions(-)
---
diff --git a/src/nautilus-mime-actions.c b/src/nautilus-mime-actions.c
index 3ceb0a953..5013c38e2 100644
--- a/src/nautilus-mime-actions.c
+++ b/src/nautilus-mime-actions.c
@@ -556,7 +556,7 @@ typedef struct
 
 static void
 trash_symbolic_link_cb (GtkDialog *dialog,
-                        gint       response_id,
+                        char      *response,
                         gpointer   user_data)
 {
     g_autofree TrashBrokenSymbolicLinkData *data = NULL;
@@ -565,7 +565,7 @@ trash_symbolic_link_cb (GtkDialog *dialog,
     data = user_data;
     gtk_window_destroy (GTK_WINDOW (dialog));
 
-    if (response_id == GTK_RESPONSE_YES)
+    if (g_strcmp0 (response, "move-to-trash") == 0)
     {
         file_as_list.data = data->file;
         file_as_list.next = NULL;
@@ -582,7 +582,7 @@ report_broken_symbolic_link (GtkWindow    *parent_window,
     char *display_name;
     char *prompt;
     char *detail;
-    GtkDialog *dialog;
+    GtkWidget *dialog;
     TrashBrokenSymbolicLinkData *data;
 
     gboolean can_trash;
@@ -592,16 +592,6 @@ report_broken_symbolic_link (GtkWindow    *parent_window,
     display_name = nautilus_file_get_display_name (file);
     can_trash = nautilus_file_can_trash (file) && !nautilus_file_is_in_trash (file);
 
-    if (can_trash)
-    {
-        prompt = g_strdup_printf (_("The link “%s” is broken. Move it to Trash?"), display_name);
-    }
-    else
-    {
-        prompt = g_strdup_printf (_("The link “%s” is broken."), display_name);
-    }
-    g_free (display_name);
-
     target_path = nautilus_file_get_symbolic_link_target_path (file);
     if (target_path == NULL)
     {
@@ -615,16 +605,21 @@ report_broken_symbolic_link (GtkWindow    *parent_window,
 
     if (can_trash)
     {
-        dialog = eel_show_yes_no_dialog (prompt, detail, _("Mo_ve to Trash"), _("_Cancel"),
-                                         parent_window);
+        prompt = g_strdup_printf (_("The link “%s” is broken. Move it to Trash?"), display_name);
+        dialog = adw_message_dialog_new (parent_window, prompt, detail);
+        adw_message_dialog_add_responses (ADW_MESSAGE_DIALOG (dialog),
+                                          "cancel", _("_Cancel"),
+                                          "move-to-trash", _("Mo_ve to Trash"),
+                                          NULL);
     }
     else
     {
-        dialog = eel_show_simple_dialog (GTK_WIDGET (parent_window), GTK_MESSAGE_WARNING,
-                                         prompt, detail, _("_Cancel"), NULL);
+        prompt = g_strdup_printf (_("The link “%s” is broken."), display_name);
+        dialog = adw_message_dialog_new (parent_window, prompt, detail);
+        adw_message_dialog_add_response (ADW_MESSAGE_DIALOG (dialog),
+                                         "cancel", _("Cancel"));
     }
-
-    gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_CANCEL);
+    g_free (display_name);
 
     /* Make this modal to avoid problems with reffing the view & file
      * to keep them around in case the view changes, which would then
@@ -984,12 +979,12 @@ activate_mount_op_active (GtkMountOperation  *operation,
     }
 }
 
-static GtkDialog *
+static GtkWidget *
 show_confirm_multiple (GtkWindow *parent_window,
                        int        window_count,
                        int        tab_count)
 {
-    GtkDialog *dialog;
+    GtkWidget *dialog;
     char *prompt;
     char *detail;
 
@@ -1010,9 +1005,15 @@ show_confirm_multiple (GtkWindow *parent_window,
         detail = g_strdup_printf (ngettext ("This will open %d separate window.",
                                             "This will open %d separate windows.", window_count), 
window_count);
     }
-    dialog = eel_show_yes_no_dialog (prompt, detail,
-                                     _("_OK"), _("_Cancel"),
-                                     parent_window);
+
+    dialog = adw_message_dialog_new (parent_window, prompt, detail);
+    adw_message_dialog_add_responses (ADW_MESSAGE_DIALOG (dialog),
+                                      "cancel", _("_Cancel"),
+                                      "open-files", _("_Open Files"),
+                                      NULL);
+
+    adw_message_dialog_set_default_response (ADW_MESSAGE_DIALOG (dialog), "open-files");
+
     g_free (detail);
 
     return dialog;
@@ -1020,12 +1021,10 @@ show_confirm_multiple (GtkWindow *parent_window,
 
 static void
 on_confirm_multiple_windows_response (GtkDialog          *dialog,
-                                      int                 response_id,
+                                      gchar              *response,
                                       ActivateParameters *parameters)
 {
-    gtk_window_destroy (GTK_WINDOW (dialog));
-
-    if (response_id == GTK_RESPONSE_YES)
+    if (g_strcmp0 (response, "open-files") == 0)
     {
         unpause_activation_timed_cancel (parameters);
         activate_files_internal (parameters);
@@ -1133,7 +1132,7 @@ open_with_response_cb (GtkDialog *dialog,
 
 static void
 choose_program (GtkDialog *message_dialog,
-                int        response,
+                gchar     *response,
                 gpointer   callback_data)
 {
     GtkWidget *dialog;
@@ -1141,9 +1140,8 @@ choose_program (GtkDialog *message_dialog,
     GFile *location;
     ActivateParametersInstall *parameters = callback_data;
 
-    if (response != GTK_RESPONSE_ACCEPT)
+    if (g_strcmp0 (response, "select-application") != 0)
     {
-        gtk_window_destroy (GTK_WINDOW (message_dialog));
         activate_parameters_install_free (parameters);
         return;
     }
@@ -1181,47 +1179,37 @@ static void
 show_unhandled_type_error (ActivateParametersInstall *parameters)
 {
     GtkWidget *dialog;
+    char *body;
 
     char *mime_type = nautilus_file_get_mime_type (parameters->file);
     char *error_message = get_application_no_mime_type_handler_message (parameters->file, parameters->uri);
+
     if (g_content_type_is_unknown (mime_type))
     {
-        dialog = gtk_message_dialog_new (parameters->parent_window,
-                                         GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_MODAL,
-                                         GTK_MESSAGE_ERROR,
-                                         0,
-                                         "%s", error_message);
-        gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
-                                                  _("The file is of an unknown type"));
+        body = _("The file is of an unknown type");
     }
     else
     {
-        char *text;
-        text = g_strdup_printf (_("There is no application installed for “%s” files"), 
g_content_type_get_description (mime_type));
-
-        dialog = gtk_message_dialog_new (parameters->parent_window,
-                                         GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_MODAL,
-                                         GTK_MESSAGE_ERROR,
-                                         0,
-                                         "%s", error_message);
-        gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
-                                                  "%s", text);
-
-        g_free (text);
+        body = g_strdup_printf (_("There is no application installed for “%s” files"), 
g_content_type_get_description (mime_type));
     }
 
-    gtk_dialog_add_button (GTK_DIALOG (dialog), _("_Select Application"), GTK_RESPONSE_ACCEPT);
+    dialog = adw_message_dialog_new (parameters->parent_window, error_message, body);
+    adw_message_dialog_add_responses (ADW_MESSAGE_DIALOG (dialog),
+                                      "select-application", _("_Select Application"),
+                                      "ok", _("_OK"),
+                                      NULL);
+
+    g_free (body);
 
-    gtk_dialog_add_button (GTK_DIALOG (dialog), _("_OK"), GTK_RESPONSE_OK);
+    adw_message_dialog_set_default_response (ADW_MESSAGE_DIALOG (dialog), "ok");
 
-    gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
 
     g_object_set_data_full (G_OBJECT (dialog),
                             "mime-action:file",
                             nautilus_file_ref (parameters->file),
                             (GDestroyNotify) nautilus_file_unref);
 
-    gtk_widget_show (GTK_WIDGET (dialog));
+    gtk_window_present (GTK_WINDOW (dialog));
 
     g_signal_connect (dialog, "response",
                       G_CALLBACK (choose_program), parameters);
@@ -1301,7 +1289,7 @@ search_for_application_mime_type (ActivateParametersInstall *parameters_install,
 
 static void
 application_unhandled_file_install (GtkDialog                 *dialog,
-                                    gint                       response_id,
+                                    gchar                     *response,
                                     ActivateParametersInstall *parameters_install)
 {
     char *mime_type;
@@ -1309,7 +1297,7 @@ application_unhandled_file_install (GtkDialog                 *dialog,
     gtk_window_destroy (GTK_WINDOW (dialog));
     parameters_install->dialog = NULL;
 
-    if (response_id == GTK_RESPONSE_YES)
+    if (g_strcmp0 (response, "search-in-software") == 0)
     {
         mime_type = nautilus_file_get_mime_type (parameters_install->file);
         search_for_application_mime_type (parameters_install, mime_type);
@@ -1355,21 +1343,17 @@ pk_proxy_appeared_cb (GObject      *source,
     error_message = get_application_no_mime_type_handler_message (parameters_install->file,
                                                                   parameters_install->uri);
     /* use a custom dialog to prompt the user to install new software */
-    dialog = gtk_message_dialog_new (parameters_install->parent_window,
-                                     GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_MODAL,
-                                     GTK_MESSAGE_ERROR,
-                                     GTK_BUTTONS_NONE,
-                                     "%s", error_message);
-    gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
-                                              _("There is no application installed for “%s” files. "
-                                                "Do you want to search for an application to open this 
file?"),
-                                              g_content_type_get_description (mime_type));
-    gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE);
-
-    gtk_dialog_add_button (GTK_DIALOG (dialog), _("_Cancel"), GTK_RESPONSE_CANCEL);
-    gtk_dialog_add_button (GTK_DIALOG (dialog), _("_Search in Software"), GTK_RESPONSE_YES);
-
-    gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_YES);
+    dialog = adw_message_dialog_new (parameters_install->parent_window, error_message, NULL);
+    adw_message_dialog_add_responses (ADW_MESSAGE_DIALOG (dialog),
+                                      "cancel", _("_Cancel"),
+                                      "search-in-software", _("_Search in Software"),
+                                      NULL);
+    adw_message_dialog_format_body (ADW_MESSAGE_DIALOG (dialog),
+                                    _("There is no application installed for “%s” files. "
+                                      "Do you want to search for an application to open this file?"),
+                                    g_content_type_get_description (mime_type));
+
+    adw_message_dialog_set_default_response (ADW_MESSAGE_DIALOG (dialog), "search-in-software");
 
     parameters_install->dialog = dialog;
     parameters_install->proxy = proxy;
@@ -1377,7 +1361,7 @@ pk_proxy_appeared_cb (GObject      *source,
     g_signal_connect (dialog, "response",
                       G_CALLBACK (application_unhandled_file_install),
                       parameters_install);
-    gtk_widget_show (dialog);
+    gtk_window_present (GTK_WINDOW (dialog));
     g_free (mime_type);
 }
 
@@ -1586,12 +1570,13 @@ activate_files (ActivateParameters *parameters)
     if (parameters->user_confirmation &&
         num_tabs + num_windows > SILENT_OPEN_LIMIT)
     {
-        GtkDialog *dialog;
+        GtkWidget *dialog;
 
         pause_activation_timed_cancel (parameters);
         dialog = show_confirm_multiple (parameters->parent_window, num_windows, num_tabs);
         g_signal_connect (dialog, "response",
                           G_CALLBACK (on_confirm_multiple_windows_response), parameters);
+        gtk_window_present (GTK_WINDOW (dialog));
     }
     else
     {


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