entrycompletion: Export gtk_entry_completion_compute_prefix()

I want to use it in the file chooser entry autocomplete code.
This commit is contained in:
Benjamin Otte 2011-11-05 20:38:28 +01:00
parent 1ac6ace87d
commit fc775dfa5b
4 changed files with 25 additions and 6 deletions

View File

@ -1135,6 +1135,7 @@ gtk_entry_completion_get_model
gtk_entry_completion_set_match_func
gtk_entry_completion_set_minimum_key_length
gtk_entry_completion_get_minimum_key_length
gtk_entry_completion_compute_prefix
gtk_entry_completion_complete
gtk_entry_completion_get_completion_prefix
gtk_entry_completion_insert_prefix

View File

@ -820,6 +820,7 @@ gtk_entry_buffer_new
gtk_entry_buffer_set_max_length
gtk_entry_buffer_set_text
gtk_entry_completion_complete
gtk_entry_completion_compute_prefix
gtk_entry_completion_delete_action
gtk_entry_completion_get_completion_prefix
gtk_entry_completion_get_entry

View File

@ -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],

View File

@ -114,6 +114,8 @@ void gtk_entry_completion_set_match_func (GtkEntryComplet
void gtk_entry_completion_set_minimum_key_length (GtkEntryCompletion *completion,
gint length);
gint gtk_entry_completion_get_minimum_key_length (GtkEntryCompletion *completion);
gchar * gtk_entry_completion_compute_prefix (GtkEntryCompletion *completion,
const char *key);
void gtk_entry_completion_complete (GtkEntryCompletion *completion);
void gtk_entry_completion_insert_prefix (GtkEntryCompletion *completion);