From 45167d5c0d3e7cc2aecccd6b15f2c3202e1b1586 Mon Sep 17 00:00:00 2001 From: Benjamin Otte Date: Sun, 21 Jun 2020 02:17:47 +0200 Subject: [PATCH 1/3] dropdown: emit notify for selected from the changed callback Otherwise we don't emit it when the selection itself changes it - for exaple because the model changed. --- gtk/gtkdropdown.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/gtk/gtkdropdown.c b/gtk/gtkdropdown.c index a95775eab6..ef151e7203 100644 --- a/gtk/gtkdropdown.c +++ b/gtk/gtkdropdown.c @@ -216,6 +216,9 @@ selection_changed (GtkSingleSelection *selection, if (GTK_IS_STRING_FILTER (filter)) gtk_string_filter_set_search (GTK_STRING_FILTER (filter), ""); gtk_single_selection_set_selected (GTK_SINGLE_SELECTION (self->popup_selection), selected); + + g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_SELECTED]); + g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_SELECTED_ITEM]); } static void @@ -809,9 +812,6 @@ gtk_drop_down_set_selected (GtkDropDown *self, return; gtk_single_selection_set_selected (GTK_SINGLE_SELECTION (self->selection), position); - - g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_SELECTED]); - g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_SELECTED_ITEM]); } /** From 3549f4390244f7eec33ea0f8be507e8cf304f620 Mon Sep 17 00:00:00 2001 From: Benjamin Otte Date: Sun, 21 Jun 2020 02:14:53 +0200 Subject: [PATCH 2/3] demo: Use GtkDropDown::selected-item --- demos/gtk-demo/listview_colors.c | 35 ++------------------------------ 1 file changed, 2 insertions(+), 33 deletions(-) diff --git a/demos/gtk-demo/listview_colors.c b/demos/gtk-demo/listview_colors.c index 420ddc7b38..6911b44c8e 100644 --- a/demos/gtk-demo/listview_colors.c +++ b/demos/gtk-demo/listview_colors.c @@ -471,29 +471,6 @@ get_title (gpointer item) return g_strdup ((char *)g_object_get_data (G_OBJECT (item), "title")); } -static gboolean -set_item (GBinding *binding, - const GValue *from, - GValue *to, - gpointer data) -{ - GObject *source = g_binding_get_source (binding); - GListModel *model; - guint selected; - gpointer item; - - selected = g_value_get_uint (from); - - model = gtk_drop_down_get_model (GTK_DROP_DOWN (source)); - item = g_list_model_get_item (model, selected); - - g_value_set_object (to, item); - - g_clear_object (&item); - - return TRUE; -} - GtkWidget * create_color_grid (void) { @@ -663,11 +640,7 @@ do_listview_colors (GtkWidget *do_widget) gtk_drop_down_set_model (GTK_DROP_DOWN (dropdown), G_LIST_MODEL (sorters)); g_object_unref (sorters); - g_object_bind_property_full (dropdown, "selected", - model, "sorter", - G_BINDING_SYNC_CREATE, - set_item, NULL, - NULL, NULL); + g_object_bind_property (dropdown, "selected-item", model, "sorter", G_BINDING_SYNC_CREATE); factories = g_list_store_new (GTK_TYPE_LIST_ITEM_FACTORY); @@ -698,11 +671,7 @@ do_listview_colors (GtkWidget *do_widget) gtk_drop_down_set_model (GTK_DROP_DOWN (dropdown), G_LIST_MODEL (factories)); g_object_unref (factories); - g_object_bind_property_full (dropdown, "selected", - gridview, "factory", - G_BINDING_SYNC_CREATE, - set_item, NULL, - NULL, NULL); + g_object_bind_property (dropdown, "selected-item", gridview, "factory", G_BINDING_SYNC_CREATE); g_object_unref (model); } From 62b214ffdfdf864fcc60e686689637d871eb89d6 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Sun, 21 Jun 2020 01:20:05 -0400 Subject: [PATCH 3/3] filechooserwidget: Use gtk_drop_down_get_selected_item This showed up as a test failure when we get NULL as selected item and then try to unref it. Luckily get_selected_item is transfer none, so we don't have to worry about it. --- gtk/gtkfilechooserwidget.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/gtk/gtkfilechooserwidget.c b/gtk/gtkfilechooserwidget.c index 064846c955..94eb40c05d 100644 --- a/gtk/gtkfilechooserwidget.c +++ b/gtk/gtkfilechooserwidget.c @@ -6929,17 +6929,13 @@ filter_combo_changed (GtkDropDown *dropdown, GParamSpec *pspec, GtkFileChooserWidget *impl) { - gint new_index; GtkFileFilter *new_filter; - new_index = gtk_drop_down_get_selected (dropdown); - new_filter = g_list_model_get_item (G_LIST_MODEL (impl->filters), new_index); - set_current_filter (impl, new_filter); + new_filter = gtk_drop_down_get_selected_item (dropdown); if (impl->location_entry != NULL) _gtk_file_chooser_entry_set_file_filter (GTK_FILE_CHOOSER_ENTRY (impl->location_entry), new_filter); - g_object_unref (new_filter); } static gboolean