]> hydra-www.ietfng.org Git - gtetrinet/commitdiff
added nick autocompletion to the partyline
authorDaniel Carbonell Fraj <bocata@src.gnome.org>
Wed, 4 Jun 2003 20:17:00 +0000 (20:17 +0000)
committerDaniel Carbonell Fraj <bocata@src.gnome.org>
Wed, 4 Jun 2003 20:17:00 +0000 (20:17 +0000)
ChangeLog
src/partyline.c

index d4e3e88a849b28462f6ed899700830410fc5ab73..3669bd101b8729aa05871b27e99622361d3a48a5 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
 2003-06-04  Dani Carbonell  <bocata@panete.net>
 
+       * 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.
index 905206ee4c065289944a3e8df4d8004cb49f51be..80793b47a6d16668e85e109f87c33afe816aa27a 100644 (file)
@@ -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;