changeset 22797:900c7b5660d5

Allow replacing smileys with texts in conversations/logs. This should be helpful for all those users who paste code in conversations.
author Sadrul Habib Chowdhury <imadil@gmail.com>
date Sat, 03 May 2008 02:49:53 +0000
parents 5e6b42e77fb7
children fc1e708ddf92
files ChangeLog pidgin/gtkimhtml.c
diffstat 2 files changed, 33 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Fri May 02 23:16:11 2008 +0000
+++ b/ChangeLog	Sat May 03 02:49:53 2008 +0000
@@ -24,6 +24,9 @@
 	  workspaces the "Present" option should.
 	* Add a preference to set Escape as the keyboard shortcut for closing
 	  the conversation window.
+	* Add an option in the context menu to disable smileys in the selected
+	  text in the conversation history/log viewer. This should help people who
+	  regularly paste code in conversations.
 
 	General:
 	* The configure script now dies on more absent dependencies.  The
--- a/pidgin/gtkimhtml.c	Fri May 02 23:16:11 2008 +0000
+++ b/pidgin/gtkimhtml.c	Sat May 03 02:49:53 2008 +0000
@@ -814,9 +814,30 @@
 	gtk_imhtml_clear_formatting(imhtml);
 }
 
+static void disable_smiley_selected(GtkMenuItem *item, GtkIMHtml *imhtml)
+{
+	GtkTextIter start, end;
+	GtkTextMark *mark;
+	char *text;
+
+	if (!gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end))
+		return;
+
+	text = gtk_imhtml_get_markup_range(imhtml, &start, &end);
+
+	mark = gtk_text_buffer_get_selection_bound(imhtml->text_buffer);
+	gtk_text_buffer_delete_selection(imhtml->text_buffer, FALSE, FALSE);
+
+	gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &start, mark);
+	gtk_imhtml_insert_html_at_iter(imhtml, text, GTK_IMHTML_NO_NEWLINE | GTK_IMHTML_NO_SMILEY, &start);
+
+	g_free(text);
+}
+
 static void hijack_menu_cb(GtkIMHtml *imhtml, GtkMenu *menu, gpointer data)
 {
 	GtkWidget *menuitem;
+	GtkTextIter start, end;
 
 	menuitem = gtk_menu_item_new_with_mnemonic(_("Paste as Plain _Text"));
 	gtk_widget_show(menuitem);
@@ -842,6 +863,15 @@
 	gtk_menu_shell_insert(GTK_MENU_SHELL(menu), menuitem, 5);
 
 	g_signal_connect(G_OBJECT(menuitem), "activate", G_CALLBACK(clear_formatting_cb), imhtml);
+
+	menuitem = gtk_menu_item_new_with_mnemonic(_("Disable _smileys in selected text"));
+	gtk_widget_show(menuitem);
+	if (gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end)) {
+		g_signal_connect(G_OBJECT(menuitem), "activate", G_CALLBACK(disable_smiley_selected), imhtml);
+	} else {
+		gtk_widget_set_sensitive(menuitem, FALSE);
+	}
+	gtk_menu_shell_insert(GTK_MENU_SHELL(menu), menuitem, 6);
 }
 
 static char *
@@ -1458,10 +1488,8 @@
 
 static void gtk_imhtml_init (GtkIMHtml *imhtml)
 {
-	GtkTextIter iter;
 	imhtml->text_buffer = gtk_text_buffer_new(NULL);
 	imhtml->undo_manager = gtk_source_undo_manager_new(imhtml->text_buffer);
-	gtk_text_buffer_get_end_iter (imhtml->text_buffer, &iter);
 	gtk_text_view_set_buffer(GTK_TEXT_VIEW(imhtml), imhtml->text_buffer);
 	gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(imhtml), GTK_WRAP_WORD_CHAR);
 	gtk_text_view_set_pixels_above_lines(GTK_TEXT_VIEW(imhtml), 2);