pidgin: 0e144589: Allow binding 'Paste as Plain Text'.

sadrul at pidgin.im sadrul at pidgin.im
Mon Mar 22 16:15:46 EDT 2010


-----------------------------------------------------------------
Revision: 0e144589184fd7d2e01d09ef9c7b69c331623a98
Ancestor: 95ba441d77fc560a693ae0aae28b37402bc5ec2f
Author: sadrul at pidgin.im
Date: 2010-03-22T20:15:55
Branch: im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/0e144589184fd7d2e01d09ef9c7b69c331623a98

Modified files:
        ChangeLog ChangeLog.API doc/gtkimhtml-signals.dox
        doc/gtkrc-2.0 pidgin/gtkimhtml.c

ChangeLog: 

Allow binding 'Paste as Plain Text'.

This should be useful when people paste non-plaintext text as plaintext
text often enough that right-click -> 'Paste as Plain Text' isn't good
enough.

-------------- next part --------------
============================================================
--- ChangeLog	8deb216640622fa2be2c44185069ae144564ae59
+++ ChangeLog	b8ef6a53202058da4e50fb93a34aacda5974815d
@@ -25,6 +25,9 @@ version 2.7.0 (??/??/????):
 	* Added a menu set mood globally for all mood-supporting accounts
 	  (currently XMPP and ICQ).
 	* Use standard (but small) GTK+ buttons instead of custom "X" symbol.
+	* Default binding of Ctrl+Shift+v to 'Paste as Plain Text' in
+	  conversation windows. This can be changed in .gtkrc-2.0. For example,
+	  Ctrl+v can be bound to 'Paste as Plain Text' by default.
 
 	Bonjour:
 	* Added support for IPv6. (Thanks to T_X for testing)
============================================================
--- ChangeLog.API	ac6feb5a6a5302009a688e04eff9d1edb88e5c72
+++ ChangeLog.API	bfd6faa6704ed0051e07dca5e2ffbd30eb895ae1
@@ -31,6 +31,7 @@ version 2.7.0 (??/??/????):
 		* pidgin_dialogs_developers (should not be used by anything but Pidgin)
 		* pidgin_dialogs_translators (should not be used by anything but Pidgin)
 		* gtk_imhtmltoolbar_switch_active_conversation
+		* 'paste' signal for GtkIMHtml (more in gtkimhtml-signals.dox)
 
 version 2.6.6 (02/18/2010):
 	libpurple:
============================================================
--- doc/gtkimhtml-signals.dox	16f0508b05a409b7cc1fb791d286739c98dddb13
+++ doc/gtkimhtml-signals.dox	0ce5ddc062d81c5fffea1722898420234dabe7cf
@@ -6,6 +6,7 @@
   @signal format_function_clear
   @signal format_function_toggle
   @signal format_function_update
+  @paste
  @endsignals
 
  @see gtkimhtml.h
@@ -57,6 +58,17 @@ void (*format_function_update)(GtkIMHtml
   @signaldesc Emitted when the cursor has moved and formatting has changed
   @param imhtml The GtkIMHtml emitting the signal.
   @param data   User defined data.
+
+ @signaldef paste
+ 	@signalproto
+void (*paste) (GtkIMHtml *imhtml, char *format)
+	@endsignalproto
+	@signaldef Emitted when paste from the clipboard is requested.
+	@param imhtml  The GtkIMHtml emitting the signal.
+	@param format  If 'text', then the formatting of the clipboard content
+	               will be removed before pasting. If empty or 'html', then
+		       the formatting will not be removed. Any other value for
+		       this parameter is ignored and nothing is pasted.
  @endsignaldef
 */
 // vim: syntax=c.doxygen tw=75 et
============================================================
--- doc/gtkrc-2.0	47b8d94af7581137ef22597b66af1851e256b7e6
+++ doc/gtkrc-2.0	e50da3ded996c96a3b5ca91a5f5a092bfdc9fc10
@@ -81,6 +81,12 @@ binding "my-bindings"
 	bind "<alt>F2" { "format_toggle" (2) }
 # Ctrl-alt-shift-f3 toggles underline
 	bind "<ctrl><alt><shift>F3" { "format_toggle" (4) }
+
+# Ctrl-v to paste as plain text
+	bind "<ctrl>v" { "paste" ("text") }
+
+# Ctrl-Shift-v for normal 'Paste'
+	bind "<ctrl><shift>v" { "paste" ("html") }
 }
   
 widget "*pidgin_conv_entry" binding "my-bindings"
============================================================
--- pidgin/gtkimhtml.c	d84b3f6d60897bd416858137f6a4c66e16a409d4
+++ pidgin/gtkimhtml.c	9cb010301b9c7a9dc63755c8a1e758ca46c8ad6f
@@ -152,6 +152,7 @@ enum {
 	MESSAGE_SEND,
 	UNDO,
 	REDO,
+	PASTE,
 	LAST_SIGNAL
 };
 static guint signals [LAST_SIGNAL] = { 0 };
@@ -1343,6 +1344,15 @@ static gboolean imhtml_message_send(GtkI
 	return FALSE;
 }
 
+static void
+imhtml_paste_cb(GtkIMHtml *imhtml, const char *str)
+{
+	if (!str || !*str || !strcmp(str, "html"))
+		g_signal_emit_by_name(imhtml, "paste_clipboard");
+	else if (!strcmp(str, "text"))
+		paste_unformatted_cb(NULL, imhtml);
+}
+
 static void imhtml_toggle_format(GtkIMHtml *imhtml, GtkIMHtmlButtons buttons)
 {
 	/* since this function is the handler for the formatting keystrokes,
@@ -1513,24 +1523,31 @@ static void gtk_imhtml_class_init (GtkIM
 					     NULL,
 					     0, g_cclosure_marshal_VOID__VOID,
 					     G_TYPE_NONE, 0);
-        signals [UNDO] = g_signal_new ("undo",
-                        		      G_TYPE_FROM_CLASS (klass),
-		                              G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
-                		              G_STRUCT_OFFSET (GtkIMHtmlClass, undo),
-		                              NULL,
-		                              NULL,
-                		              gtksourceview_marshal_VOID__VOID,
-		                              G_TYPE_NONE,
-		                              0);
-        signals [REDO] = g_signal_new ("redo",
-                        		      G_TYPE_FROM_CLASS (klass),
-		                              G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
-		                              G_STRUCT_OFFSET (GtkIMHtmlClass, redo),
-		                              NULL,
-		                              NULL,
-		                              gtksourceview_marshal_VOID__VOID,
-		                              G_TYPE_NONE,
-		                              0);
+	signals[PASTE] = g_signal_new("paste",
+					     G_TYPE_FROM_CLASS(gobject_class),
+					     G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
+						 0,
+					     NULL,
+					     0, g_cclosure_marshal_VOID__STRING,
+					     G_TYPE_NONE, 1, G_TYPE_STRING);
+	signals [UNDO] = g_signal_new ("undo",
+			G_TYPE_FROM_CLASS (klass),
+			G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
+			G_STRUCT_OFFSET (GtkIMHtmlClass, undo),
+			NULL,
+			NULL,
+			gtksourceview_marshal_VOID__VOID,
+			G_TYPE_NONE,
+			0);
+	signals [REDO] = g_signal_new ("redo",
+			G_TYPE_FROM_CLASS (klass),
+			G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
+			G_STRUCT_OFFSET (GtkIMHtmlClass, redo),
+			NULL,
+			NULL,
+			gtksourceview_marshal_VOID__VOID,
+			G_TYPE_NONE,
+			0);
 
 
 
@@ -1615,10 +1632,10 @@ static void gtk_imhtml_class_init (GtkIM
 	gtk_binding_entry_add_signal (binding_set, GDK_r, GDK_CONTROL_MASK, "format_function_clear", 0);
 	gtk_binding_entry_add_signal (binding_set, GDK_KP_Enter, 0, "message_send", 0);
 	gtk_binding_entry_add_signal (binding_set, GDK_Return, 0, "message_send", 0);
-        gtk_binding_entry_add_signal (binding_set, GDK_z, GDK_CONTROL_MASK, "undo", 0);
-        gtk_binding_entry_add_signal (binding_set, GDK_z, GDK_CONTROL_MASK | GDK_SHIFT_MASK, "redo", 0);
-        gtk_binding_entry_add_signal (binding_set, GDK_F14, 0, "undo", 0);
-
+	gtk_binding_entry_add_signal (binding_set, GDK_z, GDK_CONTROL_MASK, "undo", 0);
+	gtk_binding_entry_add_signal (binding_set, GDK_z, GDK_CONTROL_MASK | GDK_SHIFT_MASK, "redo", 0);
+	gtk_binding_entry_add_signal (binding_set, GDK_F14, 0, "undo", 0);
+	gtk_binding_entry_add_signal(binding_set, GDK_v, GDK_CONTROL_MASK | GDK_SHIFT_MASK, "paste", 1, G_TYPE_STRING, "text");
 }
 
 static void gtk_imhtml_init (GtkIMHtml *imhtml)
@@ -1689,6 +1706,7 @@ static void gtk_imhtml_init (GtkIMHtml *
 	g_signal_connect(G_OBJECT(imhtml), "paste-clipboard", G_CALLBACK(paste_clipboard_cb), NULL);
 	g_signal_connect_after(G_OBJECT(imhtml), "realize", G_CALLBACK(imhtml_realized_remove_primary), NULL);
 	g_signal_connect(G_OBJECT(imhtml), "unrealize", G_CALLBACK(imhtml_destroy_add_primary), NULL);
+	g_signal_connect(G_OBJECT(imhtml), "paste", G_CALLBACK(imhtml_paste_cb), NULL);
 
 #ifndef _WIN32
 	g_signal_connect_after(G_OBJECT(GTK_IMHTML(imhtml)->text_buffer), "mark-set",


More information about the Commits mailing list