From 750fbc844dafd82a403a0694b4bfa9f342948361 Mon Sep 17 00:00:00 2001 From: Yann Leboulanger Date: Wed, 18 Nov 2009 21:32:10 +0100 Subject: [PATCH] [Urcher] ability to copy emoticons when they are selected. Fixes #2570 --- src/conversation_textview.py | 6 ++++-- src/htmltextview.py | 40 ++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/src/conversation_textview.py b/src/conversation_textview.py index 837e2a0ce..fa5dcd25e 100644 --- a/src/conversation_textview.py +++ b/src/conversation_textview.py @@ -67,13 +67,15 @@ def has_focus(widget): class TextViewImage(gtk.Image): - def __init__(self, anchor): + def __init__(self, anchor, text): super(TextViewImage, self).__init__() self.anchor = anchor self._selected = False self._disconnect_funcs = [] self.connect('parent-set', self.on_parent_set) self.connect('expose-event', self.on_expose) + self.set_tooltip_text(text) + self.anchor.set_data('plaintext', text) def _get_selected(self): parent = self.get_parent() @@ -1043,7 +1045,7 @@ class ConversationTextview(gobject.GObject): emot_ascii = possible_emot_ascii_caps end_iter = buffer_.get_end_iter() anchor = buffer_.create_child_anchor(end_iter) - img = TextViewImage(anchor) + img = TextViewImage(anchor, special_text) animations = gajim.interface.emoticons_animations if not emot_ascii in animations: animations[emot_ascii] = gtk.gdk.PixbufAnimation( diff --git a/src/htmltextview.py b/src/htmltextview.py index 36f3ac131..5c12a049c 100644 --- a/src/htmltextview.py +++ b/src/htmltextview.py @@ -804,6 +804,10 @@ class HtmlTextView(gtk.TextView): self.connect('motion-notify-event', self.__motion_notify_event) self.connect('leave-notify-event', self.__leave_event) self.connect('enter-notify-event', self.__motion_notify_event) + self.connect('realize', self.on_html_text_view_realized) + self.connect('unrealize', self.on_html_text_view_unrealized) + self.connect('copy-clipboard', self.on_html_text_view_copy_clipboard) + self.get_buffer().connect_after('mark-set', self.on_text_buffer_mark_set) self.get_buffer().create_tag('eol', scale = pango.SCALE_XX_SMALL) self.tooltip = tooltips.BaseTooltip() self.config = gajim.config @@ -873,7 +877,43 @@ class HtmlTextView(gtk.TextView): #if not eob.starts_line(): # buffer_.insert(eob, '\n') + def on_html_text_view_copy_clipboard(self, unused_data): + clipboard = self.get_clipboard(gtk.gdk.SELECTION_CLIPBOARD) + clipboard.set_text(self.get_selected_text()) + self.emit_stop_by_name('copy-clipboard') + def on_html_text_view_realized(self, unused_data): + self.get_buffer().remove_selection_clipboard(self.get_clipboard(gtk.gdk.SELECTION_PRIMARY)) + + def on_html_text_view_unrealized(self, unused_data): + self.get_buffer().add_selection_clipboard(self.get_clipboard(gtk.gdk.SELECTION_PRIMARY)) + + def on_text_buffer_mark_set(self, location, mark, unused_data): + bounds = self.get_buffer().get_selection_bounds() + if bounds: + clipboard = self.get_clipboard(gtk.gdk.SELECTION_PRIMARY) + clipboard.set_text(self.get_selected_text()) + + def get_selected_text(self): + bounds = self.get_buffer().get_selection_bounds() + selection = '' + if bounds: + (search_iter, end) = bounds + + while (search_iter.compare(end)): + character = search_iter.get_char() + if character == u'\ufffc': + anchor = search_iter.get_child_anchor() + if anchor: + text = anchor.get_data('plaintext') + if text: + selection+=text + else: + selection+=character + else: + selection+=character + search_iter.forward_char() + return selection change_cursor = None