[nautilus/gtk4-preparation-trunk: 29/46] properties-window: Add discoverable Forget action




commit b6e72382ec6630e1161441ee13ca366908de76c0
Author: António Fernandes <antoniof gnome org>
Date:   Thu Dec 16 13:57:19 2021 +0000

    properties-window: Add discoverable Forget action
    
    The "Forget association" action is found in a single item context menu
    in the Open with tab of Properties window.
    
    Single item context menus are discouraged design and the feature is
    not discoverable. Other actions have buttons.
    
    Furthermore, this is implemented using two GTK features that are gone
    in GTK 4: GtkAppChooserWidget::populate-popup and GtkMenuShell.
    
    Just add a button instead. This is due a redesign later anyway.

 src/nautilus-properties-window.c               | 55 +++++++++-----------------
 src/resources/ui/nautilus-properties-window.ui | 16 +++++++-
 2 files changed, 33 insertions(+), 38 deletions(-)
---
diff --git a/src/nautilus-properties-window.c b/src/nautilus-properties-window.c
index 40f819cff..7b810877f 100644
--- a/src/nautilus-properties-window.c
+++ b/src/nautilus-properties-window.c
@@ -199,6 +199,7 @@ struct _NautilusPropertiesWindow
     GtkWidget *app_chooser_widget_box;
     GtkWidget *app_chooser_widget;
     GtkWidget *reset_button;
+    GtkWidget *forget_button;
     GtkWidget *add_button;
     GtkWidget *set_as_default_button;
     char *content_type;
@@ -4451,15 +4452,14 @@ add_clicked_cb (GtkButton *button,
 }
 
 static void
-remove_clicked_cb (GtkMenuItem *item,
-                   gpointer     user_data)
+forget_clicked_cb (GtkButton *button,
+                   gpointer   user_data)
 {
     NautilusPropertiesWindow *self = NAUTILUS_PROPERTIES_WINDOW (user_data);
     g_autoptr (GAppInfo) info = NULL;
 
     info = gtk_app_chooser_get_app_info (GTK_APP_CHOOSER (self->app_chooser_widget));
-
-    if (info)
+    if (info != NULL)
     {
         g_autoptr (GError) error = NULL;
 
@@ -4472,33 +4472,12 @@ remove_clicked_cb (GtkMenuItem *item,
                          GTK_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (self))),
                          GTK_MESSAGE_ERROR);
         }
-
         gtk_app_chooser_refresh (GTK_APP_CHOOSER (self->app_chooser_widget));
     }
 
     g_signal_emit_by_name (nautilus_signaller_get_current (), "mime-data-changed");
 }
 
-static void
-populate_popup_cb (GtkAppChooserWidget *widget,
-                   GtkMenu             *menu,
-                   GAppInfo            *app,
-                   gpointer             user_data)
-{
-    GtkWidget *item;
-    NautilusPropertiesWindow *self = NAUTILUS_PROPERTIES_WINDOW (user_data);
-
-    if (g_app_info_can_remove_supports_type (app))
-    {
-        item = gtk_menu_item_new_with_label (_("Forget association"));
-        gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
-        gtk_widget_show (item);
-
-        g_signal_connect (item, "activate",
-                          G_CALLBACK (remove_clicked_cb), self);
-    }
-}
-
 static void
 reset_clicked_cb (GtkButton *button,
                   gpointer   user_data)
@@ -4579,15 +4558,19 @@ application_selected_cb (GtkAppChooserWidget *widget,
 {
     NautilusPropertiesWindow *self = NAUTILUS_PROPERTIES_WINDOW (user_data);
     g_autoptr (GAppInfo) default_app = NULL;
+    gboolean is_default;
+    gboolean can_add;
+    gboolean can_remove;
 
     default_app = g_app_info_get_default_for_type (self->content_type, FALSE);
-    if (default_app != NULL)
-    {
-        gtk_widget_set_sensitive (self->set_as_default_button,
-                                  !g_app_info_equal (info, default_app));
-    }
-    gtk_widget_set_sensitive (self->add_button,
-                              app_info_can_add (info, self->content_type));
+
+    is_default = default_app != NULL && g_app_info_equal (info, default_app);
+    can_add = app_info_can_add (info, self->content_type);
+    can_remove = !is_default && !can_add && g_app_info_can_remove_supports_type (info);
+
+    gtk_widget_set_sensitive (self->forget_button, can_remove);
+    gtk_widget_set_sensitive (self->add_button, can_add);
+    gtk_widget_set_sensitive (self->set_as_default_button, !is_default);
 }
 
 static void
@@ -4650,6 +4633,9 @@ setup_app_chooser_area (NautilusPropertiesWindow *self)
     g_signal_connect (self->reset_button, "clicked",
                       G_CALLBACK (reset_clicked_cb),
                       self);
+    g_signal_connect (self->forget_button, "clicked",
+                      G_CALLBACK (forget_clicked_cb),
+                      self);
     g_signal_connect (self->add_button, "clicked",
                       G_CALLBACK (add_clicked_cb),
                       self);
@@ -4669,10 +4655,6 @@ setup_app_chooser_area (NautilusPropertiesWindow *self)
                       "application-selected",
                       G_CALLBACK (application_selected_cb),
                       self);
-    g_signal_connect (self->app_chooser_widget,
-                      "populate-popup",
-                      G_CALLBACK (populate_popup_cb),
-                      self);
 
     application_chooser_apply_labels (self);
 }
@@ -5422,6 +5404,7 @@ nautilus_properties_window_class_init (NautilusPropertiesWindowClass *klass)
     gtk_widget_class_bind_template_child (widget_class, NautilusPropertiesWindow, open_with_label);
     gtk_widget_class_bind_template_child (widget_class, NautilusPropertiesWindow, app_chooser_widget_box);
     gtk_widget_class_bind_template_child (widget_class, NautilusPropertiesWindow, reset_button);
+    gtk_widget_class_bind_template_child (widget_class, NautilusPropertiesWindow, forget_button);
     gtk_widget_class_bind_template_child (widget_class, NautilusPropertiesWindow, add_button);
     gtk_widget_class_bind_template_child (widget_class, NautilusPropertiesWindow, set_as_default_button);
 }
diff --git a/src/resources/ui/nautilus-properties-window.ui b/src/resources/ui/nautilus-properties-window.ui
index f69bf01bb..5728d4f3a 100644
--- a/src/resources/ui/nautilus-properties-window.ui
+++ b/src/resources/ui/nautilus-properties-window.ui
@@ -1333,6 +1333,18 @@
                         <property name="position">0</property>
                       </packing>
                     </child>
+                    <child>
+                      <object class="GtkButton" id="forget_button">
+                        <property name="label" translatable="yes">_Forget</property>
+                        <property name="visible">True</property>
+                        <property name="can_focus">True</property>
+                        <property name="receives_default">True</property>
+                        <property name="use_underline">True</property>
+                      </object>
+                      <packing>
+                        <property name="position">1</property>
+                      </packing>
+                    </child>
                     <child>
                       <object class="GtkButton" id="add_button">
                         <property name="label" translatable="yes">_Add</property>
@@ -1342,7 +1354,7 @@
                         <property name="use_underline">True</property>
                       </object>
                       <packing>
-                        <property name="position">1</property>
+                        <property name="position">2</property>
                       </packing>
                     </child>
                     <child>
@@ -1353,7 +1365,7 @@
                         <property name="receives_default">True</property>
                       </object>
                       <packing>
-                        <property name="position">2</property>
+                        <property name="position">3</property>
                       </packing>
                     </child>
                   </object>


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