From fc775dfa5be74efba4cee9a80f67a802e9c98121 Mon Sep 17 00:00:00 2001 From: Benjamin Otte Date: Sat, 5 Nov 2011 20:38:28 +0100 Subject: entrycompletion: Export gtk_entry_completion_compute_prefix() I want to use it in the file chooser entry autocomplete code. --- gtk/gtkentrycompletion.c | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) (limited to 'gtk/gtkentrycompletion.c') diff --git a/gtk/gtkentrycompletion.c b/gtk/gtkentrycompletion.c index 4847b9d696..b7e9b6b3e4 100644 --- a/gtk/gtkentrycompletion.c +++ b/gtk/gtkentrycompletion.c @@ -1693,19 +1693,32 @@ gtk_entry_completion_cursor_on_match (GtkEntryCompletion *completion, return TRUE; } -static gchar * -gtk_entry_completion_compute_prefix (GtkEntryCompletion *completion) +/** + * gtk_entry_completion_compute_prefix: + * @completion: the entry completion + * @key: The text to complete for + * + * Computes the common prefix that is shared by all rows in @completion + * that start with @key. If no row matches @key, %NULL will be returned. + * Note that a text column must have been set for this function to work, + * see gtk_entry_completion_set_text_column() for details. + * + * Returns: (transfer: full): The common prefix all rows starting with @key + * or %NULL if no row matches @key. + * + * Since: 3.4 + **/ +gchar * +gtk_entry_completion_compute_prefix (GtkEntryCompletion *completion, + const char *key) { GtkTreeIter iter; gchar *prefix = NULL; gboolean valid; - const gchar *key; if (completion->priv->text_column < 0) return NULL; - key = gtk_entry_get_text (GTK_ENTRY (completion->priv->entry)); - valid = gtk_tree_model_get_iter_first (GTK_TREE_MODEL (completion->priv->filter_model), &iter); @@ -1874,7 +1887,9 @@ gtk_entry_completion_insert_prefix (GtkEntryCompletion *completion) g_signal_handler_block (completion->priv->entry, completion->priv->insert_text_id); - prefix = gtk_entry_completion_compute_prefix (completion); + prefix = gtk_entry_completion_compute_prefix (completion, + gtk_entry_get_text (GTK_ENTRY (completion->priv->entry))); + if (prefix) { g_signal_emit (completion, entry_completion_signals[INSERT_PREFIX], -- cgit v1.2.1