tree_store->sort_list = NULL;
tree_store->sort_column_id = GTK_TREE_SORTABLE_UNSORTED_SORT_COLUMN_ID;
tree_store->columns_dirty = FALSE;
+
+ tree_store->row_changed_id = g_signal_lookup ("row_changed", GTK_TYPE_TREE_MODEL);
+ tree_store->row_inserted_id = g_signal_lookup ("row_inserted", GTK_TYPE_TREE_MODEL);
+ tree_store->row_has_child_toggled_id = g_signal_lookup ("row_has_child_toggled", GTK_TYPE_TREE_MODEL);
+ tree_store->rows_reordered_id = g_signal_lookup ("rows_reordered", GTK_TYPE_TREE_MODEL);
}
/**
if (emit_signal)
{
- GtkTreePath *path;
-
- path = foo_tree_store_get_path (GTK_TREE_MODEL (tree_store), iter);
- gtk_tree_model_row_changed (GTK_TREE_MODEL (tree_store), path, iter);
- gtk_tree_path_free (path);
+ if (g_signal_has_handler_pending (tree_store, tree_store->row_changed_id, 0, FALSE))
+ {
+ GtkTreePath *path;
+ path = foo_tree_store_get_path (GTK_TREE_MODEL (tree_store), iter);
+ gtk_tree_model_row_changed (GTK_TREE_MODEL (tree_store), path, iter);
+ gtk_tree_path_free (path);
+ }
}
}
GtkTreeIter *parent,
gint position)
{
- GtkTreePath *path;
GNode *parent_node;
GNode *new_node;
iter->user_data = new_node;
g_node_insert (parent_node, position, new_node);
- path = foo_tree_store_get_path (GTK_TREE_MODEL (tree_store), iter);
- gtk_tree_model_row_inserted (GTK_TREE_MODEL (tree_store), path, iter);
-
- if (parent_node != tree_store->root)
+ if (g_signal_has_handler_pending (tree_store, tree_store->row_inserted_id, 0, FALSE) ||
+ g_signal_has_handler_pending (tree_store, tree_store->row_has_child_toggled_id, 0, FALSE))
{
- if (new_node->prev == NULL && new_node->next == NULL)
- {
- gtk_tree_path_up (path);
- gtk_tree_model_row_has_child_toggled (GTK_TREE_MODEL (tree_store), path, parent);
- }
+ GtkTreePath *path;
+
+ path = foo_tree_store_get_path (GTK_TREE_MODEL (tree_store), iter);
+ gtk_tree_model_row_inserted (GTK_TREE_MODEL (tree_store), path, iter);
+
+ if (parent_node != tree_store->root)
+ {
+ if (new_node->prev == NULL && new_node->next == NULL)
+ {
+ gtk_tree_path_up (path);
+ gtk_tree_model_row_has_child_toggled (GTK_TREE_MODEL (tree_store), path, parent);
+ }
+ }
+
+ gtk_tree_path_free (path);
}
- gtk_tree_path_free (path);
-
validate_tree ((FooTreeStore*)tree_store);
}
iter.stamp = tree_store->stamp;
iter.user_data = parent;
- path = foo_tree_store_get_path (GTK_TREE_MODEL (tree_store), &iter);
- gtk_tree_model_rows_reordered (GTK_TREE_MODEL (tree_store),
- path, &iter, new_order);
- gtk_tree_path_free (path);
+
+ if (g_signal_has_handler_pending (tree_store, tree_store->row_inserted_id, 0, FALSE))
+ {
+ path = foo_tree_store_get_path (GTK_TREE_MODEL (tree_store), &iter);
+ gtk_tree_model_rows_reordered (GTK_TREE_MODEL (tree_store),
+ path, &iter, new_order);
+ gtk_tree_path_free (path);
+ }
+
g_free (new_order);
g_array_free (sort_array, TRUE);
int model_column,
GtkSortType default_sort)
{
- gboolean was_sorted = FALSE;
- int old_column;
- GtkSortType old_type;
+ int column;
+ GtkSortType type;
GtkTreeSortable *old_model;
GtkAdjustment *adjustment;
old_model = GTK_TREE_SORTABLE (gtk_tree_view_get_model (view));
- if (old_model)
+ if (!(old_model && gtk_tree_sortable_get_sort_column_id (
+ GTK_TREE_SORTABLE (old_model), &column, &type)))
{
- was_sorted = gtk_tree_sortable_get_sort_column_id (
- GTK_TREE_SORTABLE (old_model), &old_column, &old_type);
+ column = model_column;
+ type = default_sort;
}
-
+
+ /* Setting the sort column here prevents the "rows_reordered"
+ * signal from being emitted when the model is attached to
+ * a treeview. This is desirable because at that point there
+ * is a handler attached, which means the signal will actually
+ * be emitted.
+ */
+ gtk_tree_sortable_set_sort_column_id (
+ GTK_TREE_SORTABLE (model), column, type);
+
gtk_tree_view_set_model (view, model);
-
- if (was_sorted)
- tree_view_set_sort_column (view, old_column, old_type);
- else
- tree_view_set_sort_column (view, model_column, default_sort);
+
+ tree_view_set_sort_column (view, column, type);
/* Workaround for GTK+ crack, see bug 405625 */
adjustment = gtk_tree_view_get_vadjustment (view);