summaryrefslogtreecommitdiff
path: root/gtk/gtkentrycompletion.c
diff options
context:
space:
mode:
authorBenjamin Otte <otte@redhat.com>2011-11-05 20:38:28 +0100
committerBenjamin Otte <otte@redhat.com>2011-12-16 20:09:12 +0100
commitfc775dfa5be74efba4cee9a80f67a802e9c98121 (patch)
tree5934f2ff57fba4b227458dee1b1e32858baacc3f /gtk/gtkentrycompletion.c
parent1ac6ace87d904da1672e7bae01cf1d16e509accb (diff)
downloadgtk+-fc775dfa5be74efba4cee9a80f67a802e9c98121.tar.gz
entrycompletion: Export gtk_entry_completion_compute_prefix()
I want to use it in the file chooser entry autocomplete code.
Diffstat (limited to 'gtk/gtkentrycompletion.c')
-rw-r--r--gtk/gtkentrycompletion.c27
1 files changed, 21 insertions, 6 deletions
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],