[nautilus/1344-be-a-little-more-helpful-with-renaming-duplicate-files: 220/223] file-conflict-dialog: Tie default action to expander




commit 64a9b9c20fbf240cf7f112b933c4ed9cb1cdcbc9
Author: António Fernandes <antoniof gnome org>
Date:   Wed Jan 29 23:36:59 2020 +0000

    file-conflict-dialog: Tie default action to expander
    
    The default action "Replace" is changed to "Rename" if a different name
    is set in the entry inside the "Select a new name..." expander.
    
    This means we have unconsistent UI states, when "Select a new name..."
    is expanded but the action is "Replace", and when it is collapsed but
    the default action is "Rename".
    
    Instead, let's tie the default action to the expander's state.

 src/nautilus-file-conflict-dialog.c | 48 ++++++++++++++++++-------------------
 1 file changed, 24 insertions(+), 24 deletions(-)
---
diff --git a/src/nautilus-file-conflict-dialog.c b/src/nautilus-file-conflict-dialog.c
index fdcaf2d81..8adb4bb14 100644
--- a/src/nautilus-file-conflict-dialog.c
+++ b/src/nautilus-file-conflict-dialog.c
@@ -168,38 +168,32 @@ static void
 entry_text_changed_cb (GtkEditable                *entry,
                        NautilusFileConflictDialog *dialog)
 {
-    /* The rename button is visible only if there's text
-     * in the entry.
-     */
     if  (g_strcmp0 (gtk_entry_get_text (GTK_ENTRY (entry)), "") != 0 &&
          g_strcmp0 (gtk_entry_get_text (GTK_ENTRY (entry)), dialog->conflict_name) != 0)
     {
-        gtk_widget_hide (dialog->replace_button);
-        gtk_widget_show (dialog->rename_button);
-
-        gtk_widget_set_sensitive (dialog->checkbox, FALSE);
-
-        gtk_dialog_set_default_response (GTK_DIALOG (dialog), CONFLICT_RESPONSE_RENAME);
+        gtk_widget_set_sensitive (dialog->rename_button, TRUE);
     }
     else
     {
-        gtk_widget_hide (dialog->rename_button);
-        gtk_widget_show (dialog->replace_button);
-
-        gtk_widget_set_sensitive (dialog->checkbox, TRUE);
-
-        gtk_dialog_set_default_response (GTK_DIALOG (dialog), CONFLICT_RESPONSE_REPLACE);
+        gtk_widget_set_sensitive (dialog->rename_button, FALSE);
     }
 }
 
 static void
-expander_activated_cb (GtkExpander                *w,
-                       NautilusFileConflictDialog *dialog)
+on_expanded_notify (GtkExpander                *w,
+                    GParamSpec                 *pspec,
+                    NautilusFileConflictDialog *dialog)
 {
     int start_pos, end_pos;
 
-    if (!gtk_expander_get_expanded (w))
+    if (gtk_expander_get_expanded (w))
     {
+        gtk_widget_hide (dialog->replace_button);
+        gtk_widget_show (dialog->rename_button);
+        gtk_dialog_set_default_response (GTK_DIALOG (dialog), CONFLICT_RESPONSE_RENAME);
+
+        gtk_widget_set_sensitive (dialog->checkbox, FALSE);
+
         if (g_strcmp0 (gtk_entry_get_text (GTK_ENTRY (dialog->entry)), dialog->conflict_name) == 0)
         {
             gtk_widget_grab_focus (dialog->entry);
@@ -208,6 +202,14 @@ expander_activated_cb (GtkExpander                *w,
             gtk_editable_select_region (GTK_EDITABLE (dialog->entry), start_pos, end_pos);
         }
     }
+    else
+    {
+        gtk_widget_hide (dialog->rename_button);
+        gtk_widget_show (dialog->replace_button);
+        gtk_dialog_set_default_response (GTK_DIALOG (dialog), CONFLICT_RESPONSE_REPLACE);
+
+        gtk_widget_set_sensitive (dialog->checkbox, TRUE);
+    }
 }
 
 static void
@@ -215,11 +217,8 @@ checkbox_toggled_cb (GtkToggleButton            *t,
                      NautilusFileConflictDialog *dialog)
 {
     gtk_widget_set_sensitive (dialog->expander, !gtk_toggle_button_get_active (t));
-    gtk_widget_set_sensitive (dialog->rename_button, !gtk_toggle_button_get_active (t));
 
-    if  (!gtk_toggle_button_get_active (t) &&
-         g_strcmp0 (gtk_entry_get_text (GTK_ENTRY (dialog->entry)), "") != 0 &&
-         g_strcmp0 (gtk_entry_get_text (GTK_ENTRY (dialog->entry)), dialog->conflict_name) != 0)
+    if  (!gtk_toggle_button_get_active (t))
     {
         gtk_widget_hide (dialog->replace_button);
         gtk_widget_show (dialog->rename_button);
@@ -290,8 +289,8 @@ nautilus_file_conflict_dialog_init (NautilusFileConflictDialog *fcd)
     /* Setup the expander for the rename action */
     fcd->expander = gtk_expander_new_with_mnemonic (_("_Select a new name for the destination"));
     gtk_box_pack_start (GTK_BOX (vbox2), fcd->expander, FALSE, FALSE, 0);
-    g_signal_connect (fcd->expander, "activate",
-                      G_CALLBACK (expander_activated_cb), dialog);
+    g_signal_connect (fcd->expander, "notify::expanded",
+                      G_CALLBACK (on_expanded_notify), dialog);
 
     hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
     gtk_container_add (GTK_CONTAINER (fcd->expander), hbox);
@@ -332,6 +331,7 @@ nautilus_file_conflict_dialog_init (NautilusFileConflictDialog *fcd)
                                                 _("Re_name"),
                                                 CONFLICT_RESPONSE_RENAME);
     gtk_widget_hide (fcd->rename_button);
+    gtk_widget_set_no_show_all (fcd->rename_button, TRUE);
 
     fcd->replace_button = gtk_dialog_add_button (dialog,
                                                  _("Re_place"),


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