[nautilus] file-operations: Delay FileConflictDialog activation



commit b4cc5fc070a9a1288934d3ae45bceba2b0ceb3a0
Author: Álvaro Costa <alvaroc dev gmail com>
Date:   Fri Nov 26 18:43:38 2021 -0300

    file-operations: Delay FileConflictDialog activation
    
    Just as the error, warning and question dialogs, the FileConflictDialog
    may also pop up unexpectedly during a lengthier operation.
    
    The same idea of the previous commit is applied here.
    
    Fixes https://gitlab.gnome.org/GNOME/nautilus/-/issues/1988

 src/nautilus-file-conflict-dialog.c  | 27 +++++++++++++++++++++++++++
 src/nautilus-file-conflict-dialog.h  |  2 ++
 src/nautilus-file-operations.c       |  4 ++++
 src/nautilus-operations-ui-manager.c |  9 +++++++++
 src/nautilus-operations-ui-manager.h |  1 +
 5 files changed, 43 insertions(+)
---
diff --git a/src/nautilus-file-conflict-dialog.c b/src/nautilus-file-conflict-dialog.c
index 727b09806..0adc39142 100644
--- a/src/nautilus-file-conflict-dialog.c
+++ b/src/nautilus-file-conflict-dialog.c
@@ -48,6 +48,7 @@ struct _NautilusFileConflictDialog
     GtkWidget *expander;
     GtkWidget *entry;
     GtkWidget *checkbox;
+    GtkWidget *cancel_button;
     GtkWidget *skip_button;
     GtkWidget *rename_button;
     GtkWidget *replace_button;
@@ -245,6 +246,7 @@ nautilus_file_conflict_dialog_class_init (NautilusFileConflictDialogClass *klass
     gtk_widget_class_bind_template_child (widget_class, NautilusFileConflictDialog, expander);
     gtk_widget_class_bind_template_child (widget_class, NautilusFileConflictDialog, entry);
     gtk_widget_class_bind_template_child (widget_class, NautilusFileConflictDialog, checkbox);
+    gtk_widget_class_bind_template_child (widget_class, NautilusFileConflictDialog, cancel_button);
     gtk_widget_class_bind_template_child (widget_class, NautilusFileConflictDialog, rename_button);
     gtk_widget_class_bind_template_child (widget_class, NautilusFileConflictDialog, replace_button);
     gtk_widget_class_bind_template_child (widget_class, NautilusFileConflictDialog, skip_button);
@@ -258,6 +260,31 @@ nautilus_file_conflict_dialog_class_init (NautilusFileConflictDialogClass *klass
     G_OBJECT_CLASS (klass)->finalize = do_finalize;
 }
 
+static gboolean
+activate_buttons (NautilusFileConflictDialog *fcd)
+{
+    gtk_widget_set_sensitive (GTK_WIDGET (fcd->cancel_button), TRUE);
+    gtk_widget_set_sensitive (GTK_WIDGET (fcd->skip_button), TRUE);
+    gtk_widget_set_sensitive (GTK_WIDGET (fcd->rename_button), TRUE);
+    gtk_widget_set_sensitive (GTK_WIDGET (fcd->replace_button), TRUE);
+    gtk_widget_set_sensitive (GTK_WIDGET (fcd->expander), TRUE);
+    return G_SOURCE_REMOVE;
+}
+
+void
+nautilus_file_conflict_dialog_delay_buttons_activation (NautilusFileConflictDialog *fcd)
+{
+    gtk_widget_set_sensitive (GTK_WIDGET (fcd->cancel_button), FALSE);
+    gtk_widget_set_sensitive (GTK_WIDGET (fcd->skip_button), FALSE);
+    gtk_widget_set_sensitive (GTK_WIDGET (fcd->rename_button), FALSE);
+    gtk_widget_set_sensitive (GTK_WIDGET (fcd->replace_button), FALSE);
+    gtk_widget_set_sensitive (GTK_WIDGET (fcd->expander), FALSE);
+
+    g_timeout_add_seconds (BUTTON_ACTIVATION_DELAY_IN_SECONDS,
+                           G_SOURCE_FUNC (activate_buttons),
+                           fcd);
+}
+
 char *
 nautilus_file_conflict_dialog_get_new_name (NautilusFileConflictDialog *dialog)
 {
diff --git a/src/nautilus-file-conflict-dialog.h b/src/nautilus-file-conflict-dialog.h
index e7d34f6fd..c62b43018 100644
--- a/src/nautilus-file-conflict-dialog.h
+++ b/src/nautilus-file-conflict-dialog.h
@@ -54,6 +54,8 @@ void nautilus_file_conflict_dialog_disable_skip (NautilusFileConflictDialog *fcd
 void nautilus_file_conflict_dialog_disable_replace (NautilusFileConflictDialog *fcd);
 void nautilus_file_conflict_dialog_disable_apply_to_all (NautilusFileConflictDialog *fcd);
 
+void nautilus_file_conflict_dialog_delay_buttons_activation (NautilusFileConflictDialog *fdc);
+
 char*      nautilus_file_conflict_dialog_get_new_name     (NautilusFileConflictDialog *dialog);
 gboolean   nautilus_file_conflict_dialog_get_apply_to_all (NautilusFileConflictDialog *dialog);
 
diff --git a/src/nautilus-file-operations.c b/src/nautilus-file-operations.c
index 73ccaf487..72ae0d2c8 100644
--- a/src/nautilus-file-operations.c
+++ b/src/nautilus-file-operations.c
@@ -5257,15 +5257,19 @@ handle_copy_move_conflict (CommonJob *job,
     g_autofree gchar *basename = NULL;
     g_autoptr (GFile) suggested_file = NULL;
     g_autofree gchar *suggestion = NULL;
+    gboolean should_start_inactive;
 
     g_timer_stop (job->time);
     nautilus_progress_info_pause (job->progress);
 
+    should_start_inactive = is_long_job (job);
+
     basename = g_file_get_basename (dest);
     suggested_file = nautilus_generate_unique_file_in_directory (dest_dir, basename);
     suggestion = g_file_get_basename (suggested_file);
 
     response = copy_move_conflict_ask_user_action (job->parent_window,
+                                                   should_start_inactive,
                                                    src,
                                                    dest,
                                                    dest_dir,
diff --git a/src/nautilus-operations-ui-manager.c b/src/nautilus-operations-ui-manager.c
index 0d2afb5af..be6badcbe 100644
--- a/src/nautilus-operations-ui-manager.c
+++ b/src/nautilus-operations-ui-manager.c
@@ -100,6 +100,8 @@ typedef struct
 
     GtkWindow *parent;
 
+    gboolean should_start_inactive;
+
     FileConflictResponse *response;
 
     NautilusFile *source;
@@ -484,6 +486,11 @@ run_file_conflict_dialog (gpointer user_data)
 
     data->dialog = nautilus_file_conflict_dialog_new (data->parent);
 
+    if (data->should_start_inactive)
+    {
+        nautilus_file_conflict_dialog_delay_buttons_activation (data->dialog);
+    }
+
     files = g_list_prepend (files, data->source);
     files = g_list_prepend (files, data->destination);
     files = g_list_prepend (files, data->destination_directory_file);
@@ -504,6 +511,7 @@ run_file_conflict_dialog (gpointer user_data)
 
 FileConflictResponse *
 copy_move_conflict_ask_user_action (GtkWindow *parent_window,
+                                    gboolean   should_start_inactive,
                                     GFile     *source_name,
                                     GFile     *destination_name,
                                     GFile     *destination_directory_name,
@@ -514,6 +522,7 @@ copy_move_conflict_ask_user_action (GtkWindow *parent_window,
 
     data = g_slice_new0 (FileConflictDialogData);
     data->parent = parent_window;
+    data->should_start_inactive = should_start_inactive;
     data->source_name = source_name;
     data->destination_name = destination_name;
     data->destination_directory_name = destination_directory_name;
diff --git a/src/nautilus-operations-ui-manager.h b/src/nautilus-operations-ui-manager.h
index 052a0da92..3bd4512d0 100644
--- a/src/nautilus-operations-ui-manager.h
+++ b/src/nautilus-operations-ui-manager.h
@@ -14,6 +14,7 @@ typedef struct {
 void file_conflict_response_free (FileConflictResponse *data);
 
 FileConflictResponse * copy_move_conflict_ask_user_action (GtkWindow *parent_window,
+                                                           gboolean   should_start_inactive,
                                                            GFile     *src,
                                                            GFile     *dest,
                                                            GFile     *dest_dir,


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