changeset 17245:05fa005bdc59

Ignore copy/cut requests when there is no selection instead of clearing the clipboard. This is consistent with the rest of how GTK+ works. Fixes #1030
author Daniel Atallah <daniel.atallah@gmail.com>
date Wed, 23 May 2007 01:14:29 +0000
parents d8102e923bd1
children 6d940df6c095 204cbfeae945
files pidgin/gtkimhtml.c
diffstat 1 files changed, 21 insertions(+), 32 deletions(-) [+]
line wrap: on
line diff
--- a/pidgin/gtkimhtml.c	Tue May 22 22:46:07 2007 +0000
+++ b/pidgin/gtkimhtml.c	Wed May 23 01:14:29 2007 +0000
@@ -932,52 +932,41 @@
 static void copy_clipboard_cb(GtkIMHtml *imhtml, gpointer unused)
 {
 	GtkTextIter start, end;
-	GtkTextMark *sel = gtk_text_buffer_get_selection_bound(imhtml->text_buffer);
-	GtkTextMark *ins = gtk_text_buffer_get_insert(imhtml->text_buffer);
-
-	gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &start, sel);
-	gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &end, ins);
-
-	gtk_clipboard_set_with_owner(gtk_widget_get_clipboard(GTK_WIDGET(imhtml), GDK_SELECTION_CLIPBOARD),
-				     selection_targets, sizeof(selection_targets) / sizeof(GtkTargetEntry),
-				     (GtkClipboardGetFunc)gtk_imhtml_clipboard_get,
-				     (GtkClipboardClearFunc)NULL, G_OBJECT(imhtml));
-
-	if (imhtml->clipboard_html_string) {
+	if (gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end)) {
+		gtk_clipboard_set_with_owner(gtk_widget_get_clipboard(GTK_WIDGET(imhtml), GDK_SELECTION_CLIPBOARD),
+						 selection_targets, sizeof(selection_targets) / sizeof(GtkTargetEntry),
+						 (GtkClipboardGetFunc)gtk_imhtml_clipboard_get,
+						 (GtkClipboardClearFunc)NULL, G_OBJECT(imhtml));
+
 		g_free(imhtml->clipboard_html_string);
 		g_free(imhtml->clipboard_text_string);
+
+		imhtml->clipboard_html_string = gtk_imhtml_get_markup_range(imhtml, &start, &end);
+		imhtml->clipboard_text_string = gtk_imhtml_get_text(imhtml, &start, &end);
 	}
 
-	imhtml->clipboard_html_string = gtk_imhtml_get_markup_range(imhtml, &start, &end);
-	imhtml->clipboard_text_string = gtk_imhtml_get_text(imhtml, &start, &end);
-
 	g_signal_stop_emission_by_name(imhtml, "copy-clipboard");
 }
 
 static void cut_clipboard_cb(GtkIMHtml *imhtml, gpointer unused)
 {
 	GtkTextIter start, end;
-	GtkTextMark *sel = gtk_text_buffer_get_selection_bound(imhtml->text_buffer);
-	GtkTextMark *ins = gtk_text_buffer_get_insert(imhtml->text_buffer);
-
-	gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &start, sel);
-	gtk_text_buffer_get_iter_at_mark(imhtml->text_buffer, &end, ins);
-
-	gtk_clipboard_set_with_owner(gtk_widget_get_clipboard(GTK_WIDGET(imhtml), GDK_SELECTION_CLIPBOARD),
-				     selection_targets, sizeof(selection_targets) / sizeof(GtkTargetEntry),
-				     (GtkClipboardGetFunc)gtk_imhtml_clipboard_get,
-				     (GtkClipboardClearFunc)NULL, G_OBJECT(imhtml));
-
-	if (imhtml->clipboard_html_string) {
+	if (gtk_text_buffer_get_selection_bounds(imhtml->text_buffer, &start, &end)) {
+		gtk_clipboard_set_with_owner(gtk_widget_get_clipboard(GTK_WIDGET(imhtml), GDK_SELECTION_CLIPBOARD),
+						 selection_targets, sizeof(selection_targets) / sizeof(GtkTargetEntry),
+						 (GtkClipboardGetFunc)gtk_imhtml_clipboard_get,
+						 (GtkClipboardClearFunc)NULL, G_OBJECT(imhtml));
+
 		g_free(imhtml->clipboard_html_string);
 		g_free(imhtml->clipboard_text_string);
+
+		imhtml->clipboard_html_string = gtk_imhtml_get_markup_range(imhtml, &start, &end);
+		imhtml->clipboard_text_string = gtk_imhtml_get_text(imhtml, &start, &end);
+
+		if (imhtml->editable)
+			gtk_text_buffer_delete_selection(imhtml->text_buffer, FALSE, FALSE);
 	}
 
-	imhtml->clipboard_html_string = gtk_imhtml_get_markup_range(imhtml, &start, &end);
-	imhtml->clipboard_text_string = gtk_imhtml_get_text(imhtml, &start, &end);
-
-	if (imhtml->editable)
-		gtk_text_buffer_delete_selection(imhtml->text_buffer, FALSE, FALSE);
 	g_signal_stop_emission_by_name(imhtml, "cut-clipboard");
 }