summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Otte <otte@redhat.com>2020-07-12 07:49:53 +0200
committerBenjamin Otte <otte@redhat.com>2020-07-16 20:43:16 +0200
commitde56e892aaecfe6f338a35177b255e127569b2d5 (patch)
tree4624e53367101e5bc5fa0ade7b1c1e074d8f49a8
parente518c1f2f32a50b3c2907208634ce7ee43fffa7b (diff)
downloadgtk+-de56e892aaecfe6f338a35177b255e127569b2d5.tar.gz
listitemmanager: Do a better job on double items
Previously, we would unparent the existing item that we were about to reuse, and not the duplicate one. Change that.
-rw-r--r--gtk/gtklistitemmanager.c20
1 files changed, 7 insertions, 13 deletions
diff --git a/gtk/gtklistitemmanager.c b/gtk/gtklistitemmanager.c
index 34c52e48bd..7cad397ffa 100644
--- a/gtk/gtklistitemmanager.c
+++ b/gtk/gtklistitemmanager.c
@@ -577,13 +577,11 @@ gtk_list_item_manager_model_items_changed_cb (GListModel *model,
GtkListItemManager *self)
{
GHashTable *change;
- GHashTableIter iter;
- gpointer list_item;
GSList *l;
guint n_items;
n_items = g_list_model_get_n_items (G_LIST_MODEL (self->model));
- change = g_hash_table_new (g_direct_hash, g_direct_equal);
+ change = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL, (GDestroyNotify )gtk_widget_unparent);
gtk_list_item_manager_remove_items (self, change, position, removed);
gtk_list_item_manager_add_items (self, position, added);
@@ -727,12 +725,6 @@ gtk_list_item_manager_model_items_changed_cb (GListModel *model,
tracker->widget = GTK_LIST_ITEM_WIDGET (item->widget);
}
- g_hash_table_iter_init (&iter, change);
- while (g_hash_table_iter_next (&iter, NULL, &list_item))
- {
- gtk_list_item_manager_release_list_item (self, NULL, list_item);
- }
-
g_hash_table_unref (change);
gtk_widget_queue_resize (self->widget);
@@ -1073,10 +1065,12 @@ gtk_list_item_manager_release_list_item (GtkListItemManager *self,
if (change != NULL)
{
- if (g_hash_table_insert (change, gtk_list_item_widget_get_item (GTK_LIST_ITEM_WIDGET (item)), item))
- return;
-
- g_warning ("FIXME: Handle the same item multiple times in the list.\nLars says this totally should not happen, but here we are.");
+ if (!g_hash_table_replace (change, gtk_list_item_widget_get_item (GTK_LIST_ITEM_WIDGET (item)), item))
+ {
+ g_warning ("FIXME: Handle the same item multiple times in the list.\nLars says this totally should not happen, but here we are.");
+ }
+
+ return;
}
gtk_widget_unparent (item);