pidgin.next.minor: 40ae5e59: Add a GtkIMHtml function that causes the...
markdoliner at pidgin.im
markdoliner at pidgin.im
Wed Jan 28 04:00:41 EST 2009
-----------------------------------------------------------------
Revision: 40ae5e59927eadc96dc7575a62370d0a2eb18235
Ancestor: 917752686724d1f24ddeeb381cb0e857de193495
Author: markdoliner at pidgin.im
Date: 2009-01-28T08:57:55
Branch: im.pidgin.pidgin.next.minor
URL: http://d.pidgin.im/viewmtn/revision/info/40ae5e59927eadc96dc7575a62370d0a2eb18235
Modified files:
ChangeLog.API pidgin/gtkimhtml.c pidgin/gtkimhtml.h
pidgin/gtkrequest.c pidgin/gtksavedstatuses.c
ChangeLog:
Add a GtkIMHtml function that causes the widget to actually insert a
newline when the user presses the return key. This is used in the
saved status editor and the gtkrequest html input box.
Implementing this was kind of a pain. I think it would be better if
gtkimhtml.c didn't do anything with return and we changed gtkconv to
watch for that key press and send the message.
-------------- next part --------------
============================================================
--- ChangeLog.API ad6dfbba26938faec68d65d0d3e284c9a0c4ce11
+++ ChangeLog.API 607b5b7b162a9664bf511df6f422f439fe1d8c2b
@@ -47,6 +47,7 @@ version 2.6.0 (??/??/????):
* gtk_imhtml_link_get_url, gtk_imhtml_link_get_text_tag,
gtk_imhtml_link_activate functions to process GtkIMHtmlLink
objects from GtkIMHtml protocol callbacks.
+ * gtk_imhtml_set_return_inserts_newline
* pidgin_blist_set_theme
* pidgin_blist_get_theme
* pidgin_sound_is_customized
============================================================
--- pidgin/gtkimhtml.c 79c793226b2f9ce62c3f3f58858bf46a07671e01
+++ pidgin/gtkimhtml.c cc5ec5c3ae3cb9f066516efee2885305964b425b
@@ -5837,3 +5837,35 @@ const GtkTextTag * gtk_imhtml_link_get_t
return link->tag;
}
+static gboolean return_add_newline_cb(GtkWidget *widget, gpointer data)
+{
+ GtkTextBuffer *buffer;
+ GtkTextMark *mark;
+ GtkTextIter iter;
+
+ buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(widget));
+
+ /* Delete any currently selected text */
+ gtk_text_buffer_delete_selection(buffer, TRUE, TRUE);
+
+ /* Insert a newline at the current cursor position */
+ mark = gtk_text_buffer_get_insert(buffer);
+ gtk_text_buffer_get_iter_at_mark(buffer, &iter, mark);
+ gtk_imhtml_insert_html_at_iter(GTK_IMHTML(widget), "\n", 0, &iter);
+
+ /*
+ * If we just newlined ourselves past the end of the visible area
+ * then scroll down so the cursor is in view.
+ */
+ gtk_text_view_scroll_to_mark(GTK_TEXT_VIEW(widget),
+ gtk_text_buffer_get_insert(buffer),
+ 0, FALSE, 0.0, 0.0);
+
+ return TRUE;
+}
+
+void gtk_imhtml_set_return_inserts_newline(GtkIMHtml *imhtml)
+{
+ g_signal_connect(G_OBJECT(imhtml), "message_send",
+ G_CALLBACK(return_add_newline_cb), NULL);
+}
============================================================
--- pidgin/gtkimhtml.h b1c57b37d54fbf29e51f0c3bc3131f05f9c49b02
+++ pidgin/gtkimhtml.h 6dac39c2445e8fbe2a6dbec29f5c89403d7dea5e
@@ -948,6 +948,17 @@ gboolean gtk_imhtml_link_activate(GtkIMH
*/
gboolean gtk_imhtml_link_activate(GtkIMHtmlLink *link);
+/**
+ * By default this widget intercepts presses of the "return" key and
+ * emits the "message_send" signal instead. If you don't want this
+ * behavior, and you want the standard GtkTextView behavior of
+ * inserting a newline into the buffer, then call this function.
+ *
+ * @param imhtml The GtkIMHtml where you want the "return" key to add
+ * newline and not emit the "message_send" signal.
+ */
+void gtk_imhtml_set_return_inserts_newline(GtkIMHtml *imhtml);
+
/*@}*/
#ifdef __cplusplus
============================================================
--- pidgin/gtkrequest.c 8d0e42dd888c889f62638224f61bb5d04c0457c3
+++ pidgin/gtkrequest.c 7fea788d48c6cf310240672883771ca712fb3d4b
@@ -384,6 +384,8 @@ pidgin_request_input(const char *title,
gtk_imhtml_append_text(GTK_IMHTML(entry), default_value, GTK_IMHTML_NO_SCROLL);
gtk_box_pack_start(GTK_BOX(vbox), frame, TRUE, TRUE, 0);
gtk_widget_show(frame);
+
+ gtk_imhtml_set_return_inserts_newline(GTK_IMHTML(entry));
}
else {
if (multiline) {
============================================================
--- pidgin/gtksavedstatuses.c 2f28c8feb6dfef962f4eea7d5a892b9fe9eb4761
+++ pidgin/gtksavedstatuses.c 377e0b29361893d9bfd3ad87f5d450c9b8e38020
@@ -1218,6 +1218,8 @@ pidgin_status_editor_show(gboolean edit,
gtk_container_set_focus_chain(GTK_CONTAINER(hbox), focus_chain);
g_list_free(focus_chain);
+ gtk_imhtml_set_return_inserts_newline(dialog->message);
+
if ((saved_status != NULL) && (purple_savedstatus_get_message(saved_status) != NULL))
gtk_imhtml_append_text(GTK_IMHTML(text),
purple_savedstatus_get_message(saved_status), 0);
More information about the Commits
mailing list