diff options
author | Matthias Clasen <mclasen@redhat.com> | 2005-11-29 19:34:15 +0000 |
---|---|---|
committer | Matthias Clasen <matthiasc@src.gnome.org> | 2005-11-29 19:34:15 +0000 |
commit | 924765a2fe8015290a4bd26ad93d5ad33091fd24 (patch) | |
tree | 288561c2ee6d2e681c9f00386f10a725bf01739c /gtk/gtktreeselection.c | |
parent | 62ed8cb11504bb077f93b5e5d97ee561754642f0 (diff) | |
download | gtk+-924765a2fe8015290a4bd26ad93d5ad33091fd24.tar.gz |
Properly handle model changes in GtkTreeSelection: (#322569, Milosz
2005-11-29 Matthias Clasen <mclasen@redhat.com>
Properly handle model changes in GtkTreeSelection: (#322569,
Milosz Derezynski)
* gtk/gtktreeselection.c (gtk_tree_selection_selected_foreach):
Get a reference to the model, and stop the iteration if the model
of the treeview is changed on the way.
* gtk/gtktreeprivate.h:
* gtk/gtktreeselection.c (_gtk_tree_selection_emit_changed): New
private function to emit the GtkTreeSelection::changed signal.
* gtk/gtktreeview.c (gtk_tree_view_set_model): Call
_gtk_tree_selection_emit_changed() when the model changes.
Diffstat (limited to 'gtk/gtktreeselection.c')
-rw-r--r-- | gtk/gtktreeselection.c | 52 |
1 files changed, 30 insertions, 22 deletions
diff --git a/gtk/gtktreeselection.c b/gtk/gtktreeselection.c index 9bc15100a3..90a0dac174 100644 --- a/gtk/gtktreeselection.c +++ b/gtk/gtktreeselection.c @@ -614,8 +614,9 @@ gtk_tree_selection_selected_foreach (GtkTreeSelection *selection, GtkRBTree *tree; GtkRBNode *node; GtkTreeIter iter; + GtkTreeModel *model; - guint inserted_id, deleted_id, reordered_id; + gulong inserted_id, deleted_id, reordered_id, changed_id; gboolean stop = FALSE; g_return_if_fail (GTK_IS_TREE_SELECTION (selection)); @@ -645,19 +646,22 @@ gtk_tree_selection_selected_foreach (GtkTreeSelection *selection, while (node->left != tree->nil) node = node->left; + model = selection->tree_view->priv->model; + g_object_ref (model); + /* connect to signals to monitor changes in treemodel */ - inserted_id = g_signal_connect_swapped (selection->tree_view->priv->model, - "row_inserted", + inserted_id = g_signal_connect_swapped (model, "row_inserted", G_CALLBACK (model_changed), &stop); - deleted_id = g_signal_connect_swapped (selection->tree_view->priv->model, - "row_deleted", + deleted_id = g_signal_connect_swapped (model, "row_deleted", G_CALLBACK (model_changed), &stop); - reordered_id = g_signal_connect_swapped (selection->tree_view->priv->model, - "rows_reordered", + reordered_id = g_signal_connect_swapped (model, "rows_reordered", G_CALLBACK (model_changed), &stop); + changed_id = g_signal_connect_swapped (selection->tree_view, "notify::model", + G_CALLBACK (model_changed), + &stop); /* find the node internally */ path = gtk_tree_path_new_first (); @@ -666,9 +670,8 @@ gtk_tree_selection_selected_foreach (GtkTreeSelection *selection, { if (GTK_RBNODE_FLAG_SET (node, GTK_RBNODE_IS_SELECTED)) { - gtk_tree_model_get_iter (selection->tree_view->priv->model, - &iter, path); - (* func) (selection->tree_view->priv->model, path, &iter, data); + gtk_tree_model_get_iter (model, &iter, path); + (* func) (model, path, &iter, data); } if (stop) @@ -721,20 +724,18 @@ out: if (path) gtk_tree_path_free (path); - g_signal_handler_disconnect (selection->tree_view->priv->model, - inserted_id); - g_signal_handler_disconnect (selection->tree_view->priv->model, - deleted_id); - g_signal_handler_disconnect (selection->tree_view->priv->model, - reordered_id); + g_signal_handler_disconnect (model, inserted_id); + g_signal_handler_disconnect (model, deleted_id); + g_signal_handler_disconnect (model, reordered_id); + g_signal_handler_disconnect (selection->tree_view, changed_id); + g_object_unref (model); /* check if we have to spew a scary message */ if (stop) - g_warning - ("The model has been modified from within gtk_tree_selection_selected_foreach.\n" - "This function is for observing the selections of the tree only. If\n" - "you are trying to get all selected items from the tree, try using\n" - "gtk_tree_selection_get_selected_rows instead.\n"); + g_warning ("The model has been modified from within gtk_tree_selection_selected_foreach.\n" + "This function is for observing the selections of the tree only. If\n" + "you are trying to get all selected items from the tree, try using\n" + "gtk_tree_selection_get_selected_rows instead.\n"); } /** @@ -1482,7 +1483,14 @@ _gtk_tree_selection_internal_select_node (GtkTreeSelection *selection, gtk_tree_path_free (anchor_path); if (dirty) - g_signal_emit (selection, tree_selection_signals[CHANGED], 0); + g_signal_emit (selection, tree_selection_signals[CHANGED], 0); +} + + +void +_gtk_tree_selection_emit_changed (GtkTreeSelection *selection) +{ + g_signal_emit (selection, tree_selection_signals[CHANGED], 0); } /* NOTE: Any {un,}selection ever done _MUST_ be done through this function! |