# HG changeset patch # User Daniel Atallah # Date 1190003360 0 # Node ID 93ea759f6ec9102e082b91773fa0c5343a100553 # Parent 32ab95bbfb99dcf5df52a0c0f73b3bac98121899# Parent 2a9f3a499b0d740294f2d9e0be4768909e6f447b merge of '18e1f28f6de13344c37092b56e228eec61772fd7' and 'de1eb82a27b8733c877b2b4634ac2f86d8c71cfd' diff -r 2a9f3a499b0d -r 93ea759f6ec9 finch/libgnt/gntentry.c --- a/finch/libgnt/gntentry.c Mon Sep 17 03:47:45 2007 +0000 +++ b/finch/libgnt/gntentry.c Mon Sep 17 04:29:20 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); }