From 9e7381022ad26f2ec70c5a1ef5bf4e8fed9cd3d4 Mon Sep 17 00:00:00 2001 From: Daniel Carbonell Fraj Date: Wed, 4 Jun 2003 20:17:00 +0000 Subject: [PATCH] added nick autocompletion to the partyline --- ChangeLog | 7 +++++++ src/partyline.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) diff --git a/ChangeLog b/ChangeLog index d4e3e88..3669bd1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,12 @@ 2003-06-04 Dani Carbonell + * src/partyline.c (is_nick): new function, it will compare the + actual string with a complete nickname. The completion will be + done with the first match. + (playerlist_complete_nick): new function, it'll launch the + iteration through the player list, calling is_nick for each nick. + (entrykey): launch the nick completion when the TAB key is hit. + * src/commands.h (show_stop_button, show_start_button): new functions. * src/commands.c: changed the button order. diff --git a/src/partyline.c b/src/partyline.c index 905206e..80793b4 100644 --- a/src/partyline.c +++ b/src/partyline.c @@ -353,6 +353,49 @@ void textentry (GtkWidget *widget) g_free (iso_text); } +static gboolean is_nick (GtkTreeModel *model, + GtkTreePath *path, + GtkTreeIter *iter, + gpointer data) +{ + gchar *nick, *aux, *down; + + gtk_tree_model_get (model, iter, 1, &nick, -1); + down = g_utf8_strdown (nick, -1); + path = path; + + if (g_str_has_prefix (down, data)) + { + aux = g_strconcat (nick, ": ", NULL); + gtk_entry_set_text (GTK_ENTRY (entrybox), aux); + gtk_editable_set_position (GTK_EDITABLE (entrybox), -1); + + g_free (aux); + g_free (nick); + g_free (down); + return TRUE; + } + else + { + g_free (nick); + g_free (down); + return FALSE; + } +} + +static void playerlist_complete_nick (void) +{ + GtkListStore *playerlist_model = GTK_LIST_STORE (gtk_tree_view_get_model (GTK_TREE_VIEW (playerlist))); + gchar *text; + + text = g_utf8_strdown (gtk_entry_get_text (GTK_ENTRY (entrybox)), -1); + if (text == NULL) return; + + gtk_tree_model_foreach (GTK_TREE_MODEL (playerlist_model), is_nick, text); + + g_free (text); +} + static gint entrykey (GtkWidget *widget, GdkEventKey *key) { int keyval = key->keyval; @@ -393,6 +436,11 @@ static gint entrykey (GtkWidget *widget, GdkEventKey *key) else if (keyval == GDK_Left || keyval == GDK_Right) { return FALSE; } + else if (keyval == GDK_Tab) + { + playerlist_complete_nick (); + return TRUE; + } else { plh_cur = plh_end; return FALSE; -- 2.50.1