[nautilus/wip/coreyberla/app-chooser-fixes: 1/3] app-chooser: Only switch defaults if the user actually initiated a change




commit 46a52c9962222f9ea4757a83d8087a1845cadd15
Author: Corey Berla <corey berla me>
Date:   Sun Aug 7 21:13:23 2022 -0700

    app-chooser: Only switch defaults if the user actually initiated a change
    
    The app chooser resets the default simply dependent on whether the
    GtkSwitch is active or inactive.  We need to check whether the user
    actually initiated that change, so store a boolean default_changed
    that toggles based on the set-state signal from the switch.

 src/nautilus-app-chooser.c | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)
---
diff --git a/src/nautilus-app-chooser.c b/src/nautilus-app-chooser.c
index 18c1dcdad..25864c95e 100644
--- a/src/nautilus-app-chooser.c
+++ b/src/nautilus-app-chooser.c
@@ -19,6 +19,7 @@ struct _NautilusAppChooser
     gchar *content_type;
     gchar *file_name;
     gboolean single_content_type;
+    gboolean default_changed;
 
     GtkWidget *app_chooser_widget_box;
     GtkWidget *label_description;
@@ -56,14 +57,14 @@ open_button_clicked_cb (GtkButton          *button,
         return;
     }
 
-    if (state)
+    if (state && self->default_changed)
     {
         info = gtk_app_chooser_get_app_info (GTK_APP_CHOOSER (self->app_chooser_widget));
         g_app_info_set_as_default_for_type (info, self->content_type,
                                             &error);
         g_signal_emit_by_name (nautilus_signaller_get_current (), "mime-data-changed");
     }
-    else
+    else if (self->default_changed)
     {
         g_app_info_reset_type_associations (self->content_type);
         g_signal_emit_by_name (nautilus_signaller_get_current (), "mime-data-changed");
@@ -100,6 +101,18 @@ on_application_selected (GtkAppChooserWidget *widget,
     is_default = default_app != NULL && g_app_info_equal (info, default_app);
 
     gtk_switch_set_state (GTK_SWITCH (self->set_as_default_switch), is_default);
+    self->default_changed = FALSE;
+}
+
+static gboolean
+on_switch_state_set (GtkSwitch *object,
+                     gboolean   state,
+                     gpointer   user_data)
+{
+    NautilusAppChooser *self = user_data;
+
+    self->default_changed = TRUE;
+    return FALSE;
 }
 
 static void
@@ -184,6 +197,8 @@ nautilus_app_chooser_constructed (GObject *object)
                       "application-selected",
                       G_CALLBACK (on_application_selected),
                       self);
+    g_signal_connect_object (self->set_as_default_switch, "state-set",
+                             G_CALLBACK (on_switch_state_set), self, 0);
 
     if (self->file_name != NULL)
     {


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