changeset 18382:aa60f5a89286

A 'completion' signal to emit whenever user accepts a completion suggest.
author Sadrul Habib Chowdhury <imadil@gmail.com>
date Sat, 30 Jun 2007 06:41:54 +0000
parents 76b7adc8e934
children 9eb2f4d27990
files finch/libgnt/gntentry.c
diffstat 1 files changed, 20 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/finch/libgnt/gntentry.c	Sat Jun 30 05:59:07 2007 +0000
+++ b/finch/libgnt/gntentry.c	Sat Jun 30 06:41:54 2007 +0000
@@ -25,6 +25,7 @@
 
 #include "gntbox.h"
 #include "gntentry.h"
+#include "gntmarshal.h"
 #include "gntstyle.h"
 #include "gnttree.h"
 #include "gntutils.h"
@@ -32,6 +33,7 @@
 enum
 {
 	SIG_TEXT_CHANGED,
+	SIG_COMPLETION,
 	SIGS,
 };
 static guint signals[SIGS] = { 0 };
@@ -69,9 +71,12 @@
 complete_suggest(GntEntry *entry, const char *text)
 {
 	gboolean changed = FALSE;
+	int offstart = 0, offend = 0;
+
 	if (entry->word) {
 		char *s = get_beginning_of_word(entry);
 		const char *iter = text;
+		offstart = g_utf8_pointer_to_offset(entry->start, s);
 		while (*iter && toupper(*s) == toupper(*iter)) {
 			if (*s != *iter)
 				changed = TRUE;
@@ -81,10 +86,17 @@
 			gnt_entry_key_pressed(GNT_WIDGET(entry), iter);
 			changed = TRUE;
 		}
+		offend = g_utf8_pointer_to_offset(entry->start, entry->cursor);
 	} else {
+		offstart = 0;
 		gnt_entry_set_text_internal(entry, text);
 		changed = TRUE;
+		offend = g_utf8_strlen(text, -1);
 	}
+
+	if (changed)
+		g_signal_emit(G_OBJECT(entry), signals[SIG_COMPLETION], 0,
+				entry->start + offstart, entry->start + offend);
 	return changed;
 }
 
@@ -687,6 +699,14 @@
 					 g_cclosure_marshal_VOID__VOID,
 					 G_TYPE_NONE, 0);
 
+	signals[SIG_COMPLETION] =
+		g_signal_new("completion",
+					 G_TYPE_FROM_CLASS(klass),
+					 G_SIGNAL_RUN_LAST,
+					 0, NULL, NULL,
+					 gnt_closure_marshal_VOID__POINTER_POINTER,
+					 G_TYPE_NONE, 2, G_TYPE_POINTER, G_TYPE_POINTER);
+
 	gnt_bindable_class_register_action(bindable, "cursor-home", move_start,
 				GNT_KEY_CTRL_A, NULL);
 	gnt_bindable_register_binding(bindable, "cursor-home", GNT_KEY_HOME, NULL);