gtk+/tests/treestoretest.c



The file gtk+/tests/treestoretest.c has buttons to edit rows in a
GtkTreeModelSort wrapping a GtkTreeStore, but they don't actually work.
Included is a patch to fix this. I want to learn; critique (even
criticism) of how well the patch was done is welcome.

-- 
Stuart Jansen                   /"\    ASCII Ribbon Campaign
passageira {remove}bigfoot com  \ /    No HTML/RTF in email
                                 X     No Word docs in email
                                / \    Respect for open standards
Index: treestoretest.c
===================================================================
RCS file: /cvs/gnome/gtk+/tests/treestoretest.c,v
retrieving revision 1.28
diff -u -r1.28 treestoretest.c
--- treestoretest.c	2001/10/24 18:36:49	1.28
+++ treestoretest.c	2002/01/22 01:55:56
@@ -35,6 +35,20 @@
 }
 
 static void
+convert_model_and_iter (GtkTreeModel **model, GtkTreeIter *selected)
+{
+  GtkTreeIter sort_selected = *selected; 
+  GtkTreeModelSort *sort_model = GTK_TREE_MODEL_SORT(*model);
+  *model = gtk_tree_model_sort_get_model(sort_model); 
+  if (*model && selected) 
+    {
+      gtk_tree_model_sort_convert_iter_to_child_iter(sort_model, 
+		                                     selected, 
+						     &sort_selected);
+    }
+}
+
+static void
 iter_remove (GtkWidget *button, GtkTreeView *tree_view)
 {
   GtkTreeIter selected;
@@ -46,7 +60,11 @@
 				       NULL,
 				       &selected))
     {
-      if (GTK_IS_TREE_STORE (model))
+      if (GTK_IS_TREE_MODEL_SORT(model))
+        { 
+	  convert_model_and_iter(&model, &selected);
+        }
+      if (GTK_IS_TREE_STORE (model)) 
 	{
 	  gtk_tree_store_remove (GTK_TREE_STORE (model), &selected);
 	}
@@ -66,6 +84,10 @@
 				       NULL,
 				       &selected))
     {
+      if (GTK_IS_TREE_MODEL_SORT(model))
+        {
+	  convert_model_and_iter(&model, &selected);
+	}
       gtk_tree_store_insert (GTK_TREE_STORE (model),
 			     &iter,
 			     &selected,
@@ -73,6 +95,10 @@
     }
   else
     {
+      if (GTK_IS_TREE_MODEL_SORT(model))
+        {
+	  convert_model_and_iter(&model, NULL);
+	}
       gtk_tree_store_insert (GTK_TREE_STORE (model),
 			     &iter,
 			     NULL,
@@ -93,6 +119,10 @@
   if (gtk_tree_selection_get_selected (gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view)),
 				       NULL, &selected))
     {
+      if (GTK_IS_TREE_MODEL_SORT(model))
+        {
+	  convert_model_and_iter(&model, &selected);
+	}
       gtk_tree_store_set (GTK_TREE_STORE (model),
 			  &selected,
 			  1,
@@ -112,6 +142,10 @@
 				       NULL,
 				       &selected))
     {
+      if (GTK_IS_TREE_MODEL_SORT(model))
+        {
+	  convert_model_and_iter(&model, &selected);
+	}
       gtk_tree_store_insert_before (GTK_TREE_STORE (model),
 				    &iter,
 				    NULL,
@@ -119,6 +153,10 @@
     }
   else
     {
+      if (GTK_IS_TREE_MODEL_SORT(model))
+        {
+	  convert_model_and_iter(&model, NULL);
+	}
       gtk_tree_store_insert_before (GTK_TREE_STORE (model),
 				    &iter,
 				    NULL,
@@ -139,6 +177,10 @@
 				       NULL,
 				       &selected))
     {
+      if (GTK_IS_TREE_MODEL_SORT(model))
+        {
+	  convert_model_and_iter(&model, &selected);
+	}
       if (GTK_IS_TREE_STORE (model))
 	{
 	  gtk_tree_store_insert_after (GTK_TREE_STORE (model),
@@ -150,6 +192,10 @@
     }
   else
     {
+      if (GTK_IS_TREE_MODEL_SORT(model))
+        {
+	  convert_model_and_iter(&model, NULL);
+	}
       if (GTK_IS_TREE_STORE (model))
 	{
 	  gtk_tree_store_insert_after (GTK_TREE_STORE (model),
@@ -171,6 +217,10 @@
 
   if (gtk_tree_selection_get_selected (selection, NULL, &selected))
     {
+      if (GTK_IS_TREE_MODEL_SORT(model))
+        {
+	  convert_model_and_iter(&model, &selected);
+	}
       if (GTK_IS_TREE_STORE (model))
 	{
 	  gtk_tree_store_prepend (GTK_TREE_STORE (model),
@@ -181,6 +231,10 @@
     }
   else
     {
+      if (GTK_IS_TREE_MODEL_SORT(model))
+        {
+	  convert_model_and_iter(&model, NULL);
+	}
       if (GTK_IS_TREE_STORE (model))
 	{
 	  gtk_tree_store_prepend (GTK_TREE_STORE (model),
@@ -202,6 +256,10 @@
 				       NULL,
 				       &selected))
     {
+      if (GTK_IS_TREE_MODEL_SORT(model))
+        {
+	  convert_model_and_iter(&model, &selected);
+	}
       if (GTK_IS_TREE_STORE (model))
 	{
 	  gtk_tree_store_append (GTK_TREE_STORE (model), &iter, &selected);
@@ -210,6 +268,10 @@
     }
   else
     {
+      if (GTK_IS_TREE_MODEL_SORT(model))
+        {
+	  convert_model_and_iter(&model, NULL);
+	}
       if (GTK_IS_TREE_STORE (model))
 	{
 	  gtk_tree_store_append (GTK_TREE_STORE (model), &iter, NULL);


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