changeset 24322:f0d5d78e8e47

Make the Send button insensitive when there is no text in the input buffer. Has a few minor format changes from the original patch by Gabriel. Fixes #7529.
author Elliott Sales de Andrade <qulogic@pidgin.im>
date Thu, 13 Nov 2008 05:33:24 +0000
parents 068557dd121a
children 157bcca38f4c
files pidgin/plugins/sendbutton.c
diffstat 1 files changed, 30 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/pidgin/plugins/sendbutton.c	Thu Nov 13 04:32:54 2008 +0000
+++ b/pidgin/plugins/sendbutton.c	Thu Nov 13 05:33:24 2008 +0000
@@ -37,9 +37,20 @@
 }
 
 static void
+input_buffer_changed(GtkTextBuffer *text_buffer, GtkWidget *send_button)
+{
+	if (gtk_text_buffer_get_char_count(text_buffer) != 0)
+		gtk_widget_set_sensitive(send_button, TRUE);
+	else
+		gtk_widget_set_sensitive(send_button, FALSE);
+}
+
+static void
 create_send_button_pidgin(PidginConversation *gtkconv)
 {
 	GtkWidget *send_button;
+	GtkTextBuffer *buf;
+	guint signal_id;
 
 	send_button = g_object_get_data(G_OBJECT(gtkconv->lower_hbox),
 	                                "send_button");
@@ -54,6 +65,16 @@
 	                 FALSE, 0);
 	gtk_widget_show(send_button);
 
+	buf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(gtkconv->entry));
+	if (buf) {
+		signal_id = g_signal_connect(G_OBJECT(buf), "changed",
+		                             G_CALLBACK(input_buffer_changed),
+		                             send_button);
+		g_object_set_data(G_OBJECT(send_button), "buffer-signal",
+		                  GINT_TO_POINTER(signal_id));
+		input_buffer_changed(buf, send_button);
+	}
+ 
 	g_object_set_data(G_OBJECT(gtkconv->lower_hbox), "send_button",
 	                  send_button);
 }
@@ -66,6 +87,15 @@
 	send_button = g_object_get_data(G_OBJECT(gtkconv->lower_hbox),
 	                                "send_button");
 	if (send_button != NULL) {
+		GtkTextBuffer *buf;
+		guint signal_id;
+
+		buf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(gtkconv->entry));
+		signal_id = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(send_button),
+		                                              "buffer-signal"));
+		if (buf && signal_id)
+			g_signal_handler_disconnect(G_OBJECT(buf), signal_id);
+
 		gtk_widget_destroy(send_button);
 		g_object_set_data(G_OBJECT(gtkconv->lower_hbox),
 		                  "send_button", NULL);