# HG changeset patch # User Sadrul Habib Chowdhury # Date 1190003264 0 # Node ID 470feb3084a422cd0639cbc596a269c4fe517176 # Parent 94874ffc37606526105eafea372a01d0857351e2 Tab-complete as much as possible when there are multiple suggests. diff -r 94874ffc3760 -r 470feb3084a4 finch/libgnt/gntentry.c --- a/finch/libgnt/gntentry.c Sun Sep 16 15:07:16 2007 +0000 +++ b/finch/libgnt/gntentry.c Mon Sep 17 04:27:44 2007 +0000 @@ -100,6 +100,15 @@ return changed; } +static int +max_common_prefix(const char *s, const char *t) +{ + const char *f = s; + while (*f && *t && *f == *t++) + f++; + return f - s; +} + static gboolean show_suggest_dropdown(GntEntry *entry) { @@ -110,6 +119,7 @@ GList *iter; const char *text = NULL; const char *sgst = NULL; + int max = -1; if (entry->word) { @@ -121,14 +131,13 @@ else suggest = g_strdup(entry->start); len = strlen(suggest); /* Don't need to use the utf8-function here */ - + if (entry->ddown == NULL) { GntWidget *box = gnt_vbox_new(FALSE); entry->ddown = gnt_tree_new(); gnt_tree_set_compare_func(GNT_TREE(entry->ddown), (GCompareFunc)g_utf8_collate); gnt_box_add_widget(GNT_BOX(box), entry->ddown); - /* XXX: Connect to the "activate" signal for the dropdown tree */ GNT_WIDGET_SET_FLAGS(box, GNT_WIDGET_TRANSIENT); @@ -151,6 +160,10 @@ gnt_tree_create_row(GNT_TREE(entry->ddown), text), NULL, NULL); count++; + if (max == -1) + max = strlen(text) - len; + else if (max) + max = MIN(max, max_common_prefix(sgst + len, text + len)); sgst = text; } } @@ -163,6 +176,17 @@ destroy_suggest(entry); return complete_suggest(entry, sgst); } else { + if (max > 0) { + GntWidget *ddown = entry->ddown; + char *match = g_strndup(sgst + len, max); + entry->ddown = NULL; + gnt_entry_key_pressed(GNT_WIDGET(entry), match); + g_free(match); + if (entry->ddown) + gnt_widget_destroy(ddown); + else + entry->ddown = ddown; + } gnt_widget_draw(entry->ddown->parent); }