[gtk+/font-selection-new] GtkFontSelection: The filter entry now filters by terms instead of the entire string



commit f425e15c32d270218f529bdb36e246afe4c617f2
Author: Alberto Ruiz <aruiz gnome org>
Date:   Sun May 8 16:42:50 2011 +0100

    GtkFontSelection: The filter entry now filters by terms instead of the entire string

 gtk/gtkfontselection.c |   49 +++++++++++++++++++++++++++++------------------
 1 files changed, 30 insertions(+), 19 deletions(-)
---
diff --git a/gtk/gtkfontselection.c b/gtk/gtkfontselection.c
index 2ef304e..1a51566 100644
--- a/gtk/gtkfontselection.c
+++ b/gtk/gtkfontselection.c
@@ -840,40 +840,51 @@ populate_list (GtkFontSelection *fontsel, GtkTreeView* treeview, GtkListStore* m
 gboolean
 visible_func (GtkTreeModel *model, GtkTreeIter *iter, gpointer data)
 {
-  gboolean result = FALSE;
+  gboolean result = TRUE;
   GtkFontSelectionPrivate *priv = (GtkFontSelectionPrivate*) data;
 
   const gchar *search_text = (const gchar*)gtk_entry_get_text (GTK_ENTRY (priv->search_entry));
   gchar       *font_name;
-  gchar       *font_name_casefold;
-  gchar       *search_text_casefold;
+  gchar       *term;
+  gchar      **split_terms;
+  gint         n_terms = 0;
+
+  /* If there's no filter string we show the item */
+  if (strlen (search_text) == 0)
+    return TRUE;
 
   gtk_tree_model_get (model, iter,
                       PREVIEW_TITLE_COLUMN, &font_name,
                       -1);
 
-  /* Covering some corner cases to speed up the result */
-  if (font_name == NULL ||
-      strlen (search_text) > strlen (font_name))
+  if (font_name == NULL)
     {
       g_free (font_name);
       return FALSE;
-    }  
-  if (strlen (search_text) == 0)
-    {
-      g_free (font_name);
-      return TRUE;
     }
-  
-  font_name_casefold = g_utf8_casefold (font_name, -1);
-  search_text_casefold = g_utf8_casefold (search_text, -1);
-  
-  if (g_strrstr (font_name_casefold, search_text_casefold))
-    result = TRUE;
 
-  g_free (search_text_casefold);
-  g_free (font_name_casefold);
+  split_terms = g_strsplit (search_text, " ", 0);
+  term = split_terms[0];
+
+  while (term && result)
+  {
+    gchar* font_name_casefold = g_utf8_casefold (font_name, -1);
+    gchar* term_casefold = g_utf8_casefold (term, -1);
+
+    if (g_strrstr (font_name_casefold, term_casefold))
+	    result = result && TRUE;
+	  else
+      result = FALSE;
+
+    n_terms++;
+    term = split_terms[n_terms];
+
+    g_free (term_casefold);
+    g_free (font_name_casefold);
+  }
+
   g_free (font_name);
+
   return result;
 }
 



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