GtkFontChooser: Now shearch filters each individual term rather than the whole string at once

This commit is contained in:
Alberto Ruiz 2011-05-11 16:47:15 +02:00 committed by Matthias Clasen
parent db2ef8ce51
commit 5ccc66d855

View File

@ -785,40 +785,49 @@ populate_list (GtkFontChooser *fontchooser, GtkTreeView* treeview, GtkListStore*
gboolean gboolean
visible_func (GtkTreeModel *model, GtkTreeIter *iter, gpointer data) visible_func (GtkTreeModel *model, GtkTreeIter *iter, gpointer data)
{ {
gboolean result = FALSE; gboolean result = TRUE;
GtkFontChooserPrivate *priv = (GtkFontChooserPrivate*) data; GtkFontChooserPrivate *priv = (GtkFontChooserPrivate*) data;
const gchar *search_text = (const gchar*)gtk_entry_get_text (GTK_ENTRY (priv->search_entry)); const gchar *search_text = (const gchar*)gtk_entry_get_text (GTK_ENTRY (priv->search_entry));
gchar *font_name; gchar *font_name;
gchar *font_name_casefold; gchar *term;
gchar *search_text_casefold; 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, gtk_tree_model_get (model, iter,
PREVIEW_TITLE_COLUMN, &font_name, PREVIEW_TITLE_COLUMN, &font_name,
-1); -1);
/* Covering some corner cases to speed up the result */ if (font_name == NULL)
if (font_name == NULL || return FALSE;
strlen (search_text) > strlen (font_name))
{ split_terms = g_strsplit (search_text, " ", 0);
g_free (font_name); term = split_terms[0];
return FALSE;
} while (term && result)
if (strlen (search_text) == 0) {
{ gchar* font_name_casefold = g_utf8_casefold (font_name, -1);
g_free (font_name); gchar* term_casefold = g_utf8_casefold (term, -1);
return TRUE;
} if (g_strrstr (font_name_casefold, term_casefold))
result = result && TRUE;
font_name_casefold = g_utf8_casefold (font_name, -1); else
search_text_casefold = g_utf8_casefold (search_text, -1); result = FALSE;
if (g_strrstr (font_name_casefold, search_text_casefold)) n_terms++;
result = TRUE; term = split_terms[n_terms];
g_free (term_casefold);
g_free (font_name_casefold);
}
g_free (search_text_casefold);
g_free (font_name_casefold);
g_free (font_name); g_free (font_name);
g_strfreev (split_terms);
return result; return result;
} }
@ -830,13 +839,13 @@ gtk_font_chooser_bootstrap_fontlist (GtkFontChooser* fontchooser)
GtkTreeViewColumn *col; GtkTreeViewColumn *col;
fontchooser->priv->model = gtk_list_store_new (4, fontchooser->priv->model = gtk_list_store_new (4,
PANGO_TYPE_FONT_FAMILY, PANGO_TYPE_FONT_FAMILY,
PANGO_TYPE_FONT_FACE, PANGO_TYPE_FONT_FACE,
G_TYPE_STRING, G_TYPE_STRING,
G_TYPE_STRING); G_TYPE_STRING);
fontchooser->priv->filter = gtk_tree_model_filter_new (GTK_TREE_MODEL (fontchooser->priv->model), fontchooser->priv->filter = gtk_tree_model_filter_new (GTK_TREE_MODEL (fontchooser->priv->model),
NULL); NULL);
g_object_unref (fontchooser->priv->model); g_object_unref (fontchooser->priv->model);
gtk_tree_model_filter_set_visible_func (GTK_TREE_MODEL_FILTER (fontchooser->priv->filter), gtk_tree_model_filter_set_visible_func (GTK_TREE_MODEL_FILTER (fontchooser->priv->filter),