GtkFontChooser: Live search implemented

This commit is contained in:
Alberto Ruiz 2011-04-16 15:17:53 +01:00 committed by Matthias Clasen
parent 693617700b
commit fb19245493

View File

@ -264,7 +264,10 @@ deleted_text_cb (GtkEntryBuffer *buffer,
guint n_chars, guint n_chars,
gpointer user_data) gpointer user_data)
{ {
g_debug( "deleted text"); GtkFontSelectionPrivate *priv = (GtkFontSelectionPrivate*)user_data;
GtkWidget *entry = priv->search_entry;
gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (priv->filter));
} }
void void
@ -274,7 +277,10 @@ inserted_text_cb (GtkEntryBuffer *buffer,
guint n_chars, guint n_chars,
gpointer user_data) gpointer user_data)
{ {
g_debug ("inserted text"); GtkFontSelectionPrivate *priv = (GtkFontSelectionPrivate*)user_data;
GtkWidget *entry = priv->search_entry;
gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER (priv->filter));
} }
static void static void
@ -354,6 +360,12 @@ gtk_font_selection_init (GtkFontSelection *fontsel)
gtk_entry_set_text (GTK_ENTRY (priv->preview), gtk_entry_set_text (GTK_ENTRY (priv->preview),
pango_language_get_sample_string (NULL)); pango_language_get_sample_string (NULL));
/* Set search icon and place holder text */
gtk_entry_set_icon_from_stock (GTK_ENTRY (priv->search_entry),
GTK_ENTRY_ICON_SECONDARY,
GTK_STOCK_FIND);
gtk_entry_set_placeholder_text (GTK_ENTRY (priv->search_entry), N_("Search font name"));
/** Callback connections **/ /** Callback connections **/
/* Connect to callback for the live search text entry */ /* Connect to callback for the live search text entry */
g_signal_connect (G_OBJECT (gtk_entry_get_buffer (GTK_ENTRY (priv->search_entry))), g_signal_connect (G_OBJECT (gtk_entry_get_buffer (GTK_ENTRY (priv->search_entry))),
@ -492,6 +504,7 @@ populate_list (GtkTreeView* treeview, GtkListStore* model)
gboolean gboolean
visible_func (GtkTreeModel *model, GtkTreeIter *iter, gpointer data) visible_func (GtkTreeModel *model, GtkTreeIter *iter, gpointer data)
{ {
gboolean result = FALSE;
GtkFontSelectionPrivate *priv = (GtkFontSelectionPrivate*) data; GtkFontSelectionPrivate *priv = (GtkFontSelectionPrivate*) 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));
@ -511,11 +524,14 @@ visible_func (GtkTreeModel *model, GtkTreeIter *iter, gpointer data)
font_name_casefold = g_utf8_casefold (font_name, -1); font_name_casefold = g_utf8_casefold (font_name, -1);
search_text_casefold = g_utf8_casefold (search_text, -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 (search_text_casefold);
g_free (font_name_casefold); g_free (font_name_casefold);
g_free (font_name); g_free (font_name);
return FALSE; return result;
} }
static void static void
@ -529,9 +545,15 @@ gtk_font_selection_bootstrap_fontlist (GtkFontSelection* fontsel)
PANGO_TYPE_FONT_FACE, PANGO_TYPE_FONT_FACE,
G_TYPE_STRING, G_TYPE_STRING,
G_TYPE_STRING); G_TYPE_STRING);
fontsel->priv->filter = gtk_tree_model_filter_new (GTK_TREE_MODEL (fontsel->priv->model), fontsel->priv->filter = gtk_tree_model_filter_new (GTK_TREE_MODEL (fontsel->priv->model),
NULL); NULL);
gtk_tree_model_filter_set_visible_func (GTK_TREE_MODEL_FILTER (fontsel->priv->filter),
visible_func,
(gpointer)fontsel->priv,
NULL);
gtk_tree_view_set_model (treeview, GTK_TREE_MODEL (fontsel->priv->filter)); gtk_tree_view_set_model (treeview, GTK_TREE_MODEL (fontsel->priv->filter));
gtk_tree_view_set_rules_hint (treeview, TRUE); gtk_tree_view_set_rules_hint (treeview, TRUE);