changeset 18557:212c2bec5c97

Allow using custom search functions.
author Sadrul Habib Chowdhury <imadil@gmail.com>
date Thu, 19 Jul 2007 08:25:26 +0000
parents 5e1412f4e67a
children 4de7e6c4e5be
files ChangeLog.API finch/libgnt/gnttree.c finch/libgnt/gnttree.h
diffstat 3 files changed, 24 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog.API	Tue Jul 17 11:09:03 2007 +0000
+++ b/ChangeLog.API	Thu Jul 19 08:25:26 2007 +0000
@@ -106,6 +106,8 @@
 			* gnt_tree_set_column_width_ratio
 			* gnt_tree_set_column_resizable
 			* gnt_tree_set_column_is_right_aligned
+			* gnt_tree_set_search_function, gnt_tree_set_search_column,
+			  gnt_tree_is_searching
 			* 'file-selected' signal is emited for GntFileSel
 			* gnt_style_parse_bool
 			* gnt_util_set_trigger_widget
--- a/finch/libgnt/gnttree.c	Tue Jul 17 11:09:03 2007 +0000
+++ b/finch/libgnt/gnttree.c	Thu Jul 19 08:25:26 2007 +0000
@@ -55,6 +55,7 @@
 	GString *search;
 	int search_timeout;
 	int search_column;
+	gboolean (*search_func)(GntTree *tree, gpointer key, const char *current);
 
 	GCompareFunc compare;
 	int lastvisible;
@@ -159,9 +160,12 @@
 	GntTree *t = row->tree;
 	if (t->priv->search && t->priv->search->len > 0) {
 		GntTreeCol *col = (col = g_list_nth_data(row->columns, t->priv->search_column)) ? col : row->columns->data;
-		char *one = g_utf8_casefold(col->text, -1);
-		char *two = g_utf8_casefold(t->priv->search->str, -1);
-		char *z = strstr(one, two);
+		char *one, *two, *z;
+		if (t->priv->search_func)
+			return t->priv->search_func(t, row->key, col->text);
+		one = g_utf8_casefold(col->text, -1);
+		two = g_utf8_casefold(t->priv->search->str, -1);
+		z = strstr(one, two);
 		g_free(one);
 		g_free(two);
 		if (z == NULL)
@@ -1803,3 +1807,9 @@
 	return (tree->priv->search != NULL);
 }
 
+void gnt_tree_set_search_function(GntTree *tree,
+		gboolean (*func)(GntTree *tree, gpointer key, const char *current))
+{
+	tree->priv->search_func = func;
+}
+
--- a/finch/libgnt/gnttree.h	Tue Jul 17 11:09:03 2007 +0000
+++ b/finch/libgnt/gnttree.h	Thu Jul 19 08:25:26 2007 +0000
@@ -516,6 +516,15 @@
  */
 gboolean gnt_tree_is_searching(GntTree *tree);
 
+/**
+ * Set a custom search function.
+ *
+ * @param tree  The tree
+ * @param func  The custom search function
+ */
+void gnt_tree_set_search_function(GntTree *tree,
+		gboolean (*func)(GntTree *tree, gpointer key, const char *current));
+
 G_END_DECLS
 
 #endif /* GNT_TREE_H */