[gthumb] template-selector: fixed setting of the active attribute



commit ea9e2fdc5f8a81aa0af3a5554e7c6a6c370083df
Author: Paolo Bacchilega <paobac src gnome org>
Date:   Sun Apr 3 20:17:28 2011 +0200

    template-selector: fixed setting of the active attribute

 extensions/rename_series/gth-template-selector.c |   57 ++++++++++++++-------
 1 files changed, 38 insertions(+), 19 deletions(-)
---
diff --git a/extensions/rename_series/gth-template-selector.c b/extensions/rename_series/gth-template-selector.c
index 6596c2e..6104b68 100644
--- a/extensions/rename_series/gth-template-selector.c
+++ b/extensions/rename_series/gth-template-selector.c
@@ -375,6 +375,42 @@ get_format_from_value (const char *value)
 }
 
 
+static gboolean
+_gtk_tree_model_get_iter_from_attribute_id (GtkTreeModel *tree_model,
+					    GtkTreeIter  *root,
+					    const char   *attribute_id,
+					    GtkTreeIter  *result)
+{
+	GtkTreeIter  iter;
+	char        *iter_id;
+
+	if (root != NULL) {
+		gtk_tree_model_get (tree_model,
+				    root,
+				    ATTRIBUTE_ID_COLUMN, &iter_id,
+				    -1);
+		if (g_strcmp0 (attribute_id, iter_id) == 0) {
+			g_free (iter_id);
+			*result = *root;
+			return TRUE;
+		}
+
+		g_free (iter_id);
+	}
+
+	if (! gtk_tree_model_iter_children (tree_model, &iter, root))
+		return FALSE;
+
+	do {
+		if (_gtk_tree_model_get_iter_from_attribute_id (tree_model, &iter, attribute_id, result))
+			return TRUE;
+	}
+	while (gtk_tree_model_iter_next (tree_model, &iter));
+
+	return FALSE;
+}
+
+
 void
 gth_template_selector_set_value (GthTemplateSelector *self,
 				 const char          *value)
@@ -463,25 +499,8 @@ gth_template_selector_set_value (GthTemplateSelector *self,
 			GtkTreeIter   iter;
 
 			tree_model = (GtkTreeModel *) GET_WIDGET ("attribute_treestore");
-			if (gtk_tree_model_get_iter_first (tree_model, &iter)) {
-				do {
-					char *iter_id;
-
-					gtk_tree_model_get (tree_model,
-							    &iter,
-							    ATTRIBUTE_ID_COLUMN, &iter_id,
-							    -1);
-
-					if (g_strcmp0 (attribute_id, iter_id) == 0) {
-						gtk_combo_box_set_active_iter (GTK_COMBO_BOX (GET_WIDGET ("attribute_combobox")), &iter);
-						g_free (iter_id);
-						break;
-					}
-
-					g_free (iter_id);
-				}
-				while (gtk_tree_model_iter_next (tree_model, &iter));
-			}
+			if (_gtk_tree_model_get_iter_from_attribute_id (tree_model, NULL, attribute_id, &iter))
+				gtk_combo_box_set_active_iter (GTK_COMBO_BOX (GET_WIDGET ("attribute_combobox")), &iter);
 		}
 		g_free (attribute_id);
 		break;



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