changeset 20097:32ab95bbfb99

merge of '5a3c2bb6d5725a73e614aa69d0e5beb04aba2d19' and '6a0f0f76df315783640509fd6961bbd5a395e0ec'
author Sadrul Habib Chowdhury <imadil@gmail.com>
date Mon, 17 Sep 2007 04:28:08 +0000
parents e638dec3d76b (current diff) 470feb3084a4 (diff)
children 93ea759f6ec9
files
diffstat 1 files changed, 26 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/finch/libgnt/gntentry.c	Sun Sep 16 18:11:48 2007 +0000
+++ b/finch/libgnt/gntentry.c	Mon Sep 17 04:28:08 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);
 	}