[Urcher] ability to copy emoticons when they are selected. Fixes #2570

This commit is contained in:
Yann Leboulanger 2009-11-18 21:32:10 +01:00
parent c9c5f72ff9
commit 750fbc844d
2 changed files with 44 additions and 2 deletions

View File

@ -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(

View File

@ -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