[gimp] Fix GimpContainerView::set_context() to really set all rows of a tree



commit b2a1583c2b5fd1ad450b761d17cc0c47802aa5ff
Author: Michael Natterer <mitch gimp org>
Date:   Fri Aug 28 10:15:38 2009 +0200

    Fix GimpContainerView::set_context() to really set all rows of a tree

 app/widgets/gimpcontainertreeview.c |   39 +++++++++++++++----------
 app/widgets/gimplayertreeview.c     |   54 ++++++++++++++++++++++------------
 2 files changed, 58 insertions(+), 35 deletions(-)
---
diff --git a/app/widgets/gimpcontainertreeview.c b/app/widgets/gimpcontainertreeview.c
index b8a5627..7846316 100644
--- a/app/widgets/gimpcontainertreeview.c
+++ b/app/widgets/gimpcontainertreeview.c
@@ -556,6 +556,26 @@ gimp_container_tree_view_set_container (GimpContainerView *view,
   gtk_tree_view_columns_autosize (tree_view->view);
 }
 
+static gboolean
+gimp_container_tree_view_set_context_foreach (GtkTreeModel *model,
+                                              GtkTreePath  *path,
+                                              GtkTreeIter  *iter,
+                                              gpointer      data)
+{
+  GimpContext      *context = data;
+  GimpViewRenderer *renderer;
+
+  gtk_tree_model_get (model, iter,
+                      GIMP_CONTAINER_TREE_VIEW_COLUMN_RENDERER, &renderer,
+                      -1);
+
+  gimp_view_renderer_set_context (renderer, context);
+
+  g_object_unref (renderer);
+
+  return FALSE;
+}
+
 static void
 gimp_container_tree_view_set_context (GimpContainerView *view,
                                       GimpContext       *context)
@@ -566,22 +586,9 @@ gimp_container_tree_view_set_context (GimpContainerView *view,
 
   if (tree_view->model)
     {
-      GtkTreeIter iter;
-      gboolean    iter_valid;
-
-      for (iter_valid = gtk_tree_model_get_iter_first (tree_view->model, &iter);
-           iter_valid;
-           iter_valid = gtk_tree_model_iter_next (tree_view->model, &iter))
-        {
-          GimpViewRenderer *renderer;
-
-          gtk_tree_model_get (tree_view->model, &iter,
-                              GIMP_CONTAINER_TREE_VIEW_COLUMN_RENDERER, &renderer,
-                              -1);
-
-          gimp_view_renderer_set_context (renderer, context);
-          g_object_unref (renderer);
-        }
+      gtk_tree_model_foreach (tree_view->model,
+                              gimp_container_tree_view_set_context_foreach,
+                              context);
     }
 }
 
diff --git a/app/widgets/gimplayertreeview.c b/app/widgets/gimplayertreeview.c
index a90ab44..258acaf 100644
--- a/app/widgets/gimplayertreeview.c
+++ b/app/widgets/gimplayertreeview.c
@@ -500,6 +500,35 @@ gimp_layer_tree_view_set_container (GimpContainerView *view,
     }
 }
 
+typedef struct
+{
+  gint         mask_column;
+  GimpContext *context;
+} SetContextForeachData;
+
+static gboolean
+gimp_layer_tree_view_set_context_foreach (GtkTreeModel *model,
+                                          GtkTreePath  *path,
+                                          GtkTreeIter  *iter,
+                                          gpointer      data)
+{
+  SetContextForeachData *context_data = data;
+  GimpViewRenderer      *renderer;
+
+  gtk_tree_model_get (model, iter,
+                      context_data->mask_column, &renderer,
+                      -1);
+
+  if (renderer)
+    {
+      gimp_view_renderer_set_context (renderer, context_data->context);
+
+      g_object_unref (renderer);
+    }
+
+  return FALSE;
+}
+
 static void
 gimp_layer_tree_view_set_context (GimpContainerView *view,
                                   GimpContext       *context)
@@ -511,25 +540,12 @@ gimp_layer_tree_view_set_context (GimpContainerView *view,
 
   if (tree_view->model)
     {
-      GtkTreeIter iter;
-      gboolean    iter_valid;
-
-      for (iter_valid = gtk_tree_model_get_iter_first (tree_view->model, &iter);
-           iter_valid;
-           iter_valid = gtk_tree_model_iter_next (tree_view->model, &iter))
-        {
-          GimpViewRenderer *renderer;
+      SetContextForeachData context_data = { layer_view->priv->model_column_mask,
+                                             context };
 
-          gtk_tree_model_get (tree_view->model, &iter,
-                              layer_view->priv->model_column_mask, &renderer,
-                              -1);
-
-          if (renderer)
-            {
-              gimp_view_renderer_set_context (renderer, context);
-              g_object_unref (renderer);
-            }
-        }
+      gtk_tree_model_foreach (tree_view->model,
+                              gimp_layer_tree_view_set_context_foreach,
+                              &context_data);
     }
 }
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]