[gtk+/gtk-2.90] Factory out functions to emit row_inserted, row_changed, row_deleted
- From: Christian Dywan <cdywan src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [gtk+/gtk-2.90] Factory out functions to emit row_inserted, row_changed, row_deleted
- Date: Fri, 16 Oct 2009 14:01:26 +0000 (UTC)
commit ade2ef3f3888c07606db28091e4b7dbf56368280
Author: Federico Mena Quintero <federico novell com>
Date: Wed Sep 2 17:10:46 2009 -0500
Factory out functions to emit row_inserted, row_changed, row_deleted
This is to avoid temporary variables for the path/iter and to avoid duplicated code.
Signed-off-by: Federico Mena Quintero <federico novell com>
gtk/gtkfilesystemmodel.c | 70 ++++++++++++++++++++++++++++-----------------
1 files changed, 43 insertions(+), 27 deletions(-)
---
diff --git a/gtk/gtkfilesystemmodel.c b/gtk/gtkfilesystemmodel.c
index 0baad5e..c2fe884 100644
--- a/gtk/gtkfilesystemmodel.c
+++ b/gtk/gtkfilesystemmodel.c
@@ -192,12 +192,44 @@ gtk_tree_path_new_from_node (GtkFileSystemModel *model, guint id)
}
static void
-node_set_visible (GtkFileSystemModel *model, guint id, gboolean visible)
+emit_row_inserted_for_node (GtkFileSystemModel *model, guint id)
+{
+ GtkTreePath *path;
+ GtkTreeIter iter;
+
+ path = gtk_tree_path_new_from_node (model, id);
+ ITER_INIT_FROM_INDEX (model, &iter, id);
+ gtk_tree_model_row_inserted (GTK_TREE_MODEL (model), path, &iter);
+ gtk_tree_path_free (path);
+}
+
+static void
+emit_row_changed_for_node (GtkFileSystemModel *model, guint id)
{
- FileModelNode *node = get_node (model, id);
GtkTreePath *path;
GtkTreeIter iter;
+ path = gtk_tree_path_new_from_node (model, id);
+ ITER_INIT_FROM_INDEX (model, &iter, id);
+ gtk_tree_model_row_changed (GTK_TREE_MODEL (model), path, &iter);
+ gtk_tree_path_free (path);
+}
+
+static void
+emit_row_deleted_for_visible_index (GtkFileSystemModel *model, guint visible_index)
+{
+ GtkTreePath *path;
+
+ path = gtk_tree_path_new_from_indices (visible_index, -1);
+ gtk_tree_model_row_deleted (GTK_TREE_MODEL (model), path);
+ gtk_tree_path_free (path);
+}
+
+static void
+node_set_visible (GtkFileSystemModel *model, guint id, gboolean visible)
+{
+ FileModelNode *node = get_node (model, id);
+
if (node->visible == visible ||
node->frozen_add)
return;
@@ -206,18 +238,18 @@ node_set_visible (GtkFileSystemModel *model, guint id, gboolean visible)
{
node->visible = TRUE;
node_invalidate_index (model, id);
- path = gtk_tree_path_new_from_node (model, id);
- ITER_INIT_FROM_INDEX (model, &iter, id);
- gtk_tree_model_row_inserted (GTK_TREE_MODEL (model), path, &iter);
- gtk_tree_path_free (path);
+ emit_row_inserted_for_node (model, id);
}
else
{
- path = gtk_tree_path_new_from_node (model, id);
+ guint visible_index;
+
+ visible_index = node_get_index (model, id);
+ g_assert (visible_index < model->files->len);
+
node->visible = FALSE;
node_invalidate_index (model, id);
- gtk_tree_model_row_deleted (GTK_TREE_MODEL (model), path);
- gtk_tree_path_free (path);
+ emit_row_deleted_for_visible_index (model, visible_index);
}
}
@@ -1664,15 +1696,7 @@ _gtk_file_system_model_update_file (GtkFileSystemModel *model,
}
if (node->visible)
- {
- GtkTreePath *path;
- GtkTreeIter iter;
-
- path = gtk_tree_path_new_from_node (model, id);
- ITER_INIT_FROM_INDEX (model, &iter, id);
- gtk_tree_model_row_changed (GTK_TREE_MODEL (model), path, &iter);
- gtk_tree_path_free (path);
- }
+ emit_row_changed_for_node (model, id);
if (requires_resort)
gtk_file_system_model_sort_node (model, id);
@@ -1845,15 +1869,7 @@ _gtk_file_system_model_clear_cache (GtkFileSystemModel *model,
}
if (changed && node->visible)
- {
- GtkTreePath *path;
- GtkTreeIter iter;
-
- path = gtk_tree_path_new_from_node (model, i);
- ITER_INIT_FROM_INDEX (model, &iter, i);
- gtk_tree_model_row_changed (GTK_TREE_MODEL (model), path, &iter);
- gtk_tree_path_free (path);
- }
+ emit_row_changed_for_node (model, i);
}
/* FIXME: resort? */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]