diff options
author | António Fernandes <antoniof@gnome.org> | 2021-12-16 13:57:19 +0000 |
---|---|---|
committer | António Fernandes <antoniof@gnome.org> | 2022-01-01 22:04:05 +0000 |
commit | 31700625d70a9fdd4fd04c773d5d0c736f917cdc (patch) | |
tree | fd43b5b450ca759879593d632c0d53e5f4ddab94 | |
parent | acb2f40a917a8f311764a0707d212fdbd98984e1 (diff) | |
download | nautilus-31700625d70a9fdd4fd04c773d5d0c736f917cdc.tar.gz |
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.
-rw-r--r-- | src/nautilus-properties-window.c | 55 | ||||
-rw-r--r-- | 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,7 +4472,6 @@ 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)); } @@ -4480,26 +4479,6 @@ remove_clicked_cb (GtkMenuItem *item, } 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 @@ -1334,6 +1334,18 @@ </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> <property name="visible">True</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> |