diff --git a/gajim/app_actions.py b/gajim/app_actions.py index bf0e9494d..27de3fb2a 100644 --- a/gajim/app_actions.py +++ b/gajim/app_actions.py @@ -355,7 +355,7 @@ def open_link(_action, param): helpers.launch_browser_mailer(kind, link) -def copy_link(_action, param): +def copy_text(_action, param): text = param.get_string() clip = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD) clip.set_text(text, -1) diff --git a/gajim/application.py b/gajim/application.py index 0da3d6ee7..2235e4074 100644 --- a/gajim/application.py +++ b/gajim/application.py @@ -416,8 +416,8 @@ class GajimApplication(Gtk.Application): act.connect("activate", app_actions.on_add_contact_jid) self.add_action(act) - act = Gio.SimpleAction.new('copy-link', GLib.VariantType.new('s')) - act.connect("activate", app_actions.copy_link) + act = Gio.SimpleAction.new('copy-text', GLib.VariantType.new('s')) + act.connect("activate", app_actions.copy_text) self.add_action(act) act = Gio.SimpleAction.new('open-link', GLib.VariantType.new('as')) diff --git a/gajim/gtk/search.py b/gajim/gtk/search.py index c88dce355..a7cbf74cf 100644 --- a/gajim/gtk/search.py +++ b/gajim/gtk/search.py @@ -26,6 +26,8 @@ from gajim.common.i18n import _ from gajim.common.modules import dataforms +from gajim.gui_menu_builder import SearchMenu + from gajim.gtk.dataform import DataFormWidget from gajim.gtk.util import ensure_not_destroyed from gajim.gtk.util import find_widget @@ -259,6 +261,7 @@ class Completed(Gtk.Box): self._scrolled.get_style_context().add_class('search-scrolled') self._scrolled.set_no_show_all(True) self._treeview = None + self._menu = None self.add(self._label) self.add(self._scrolled) self.show_all() @@ -268,6 +271,7 @@ class Completed(Gtk.Box): self._scrolled.remove(self._treeview) self._treeview.destroy() self._treeview = None + self._menu = None self._label.hide() self._scrolled.hide() @@ -303,6 +307,8 @@ class Completed(Gtk.Box): self._treeview.set_hexpand(True) self._treeview.set_vexpand(True) self._treeview.get_style_context().add_class('search-treeview') + self._treeview.connect('button-press-event', self._on_button_press) + self._menu = SearchMenu(self._treeview) for field, counter in zip(form.reported.iter_fields(), itertools.count()): @@ -316,6 +322,19 @@ class Completed(Gtk.Box): self._scrolled.add(self._treeview) self._scrolled.show() + def _on_button_press(self, treeview, event): + if event.button != 3: + return + path, _column, _x, _y = treeview.get_path_at_pos(event.x, event.y) + if path is None: + return + store = treeview.get_model() + iter_ = store.get_iter(path) + column_values = store[iter_] + text = ' '.join(column_values) + self._menu.set_copy_text(text) + self._menu.popup_at_pointer() + class Error(Gtk.Box): diff --git a/gajim/gui_menu_builder.py b/gajim/gui_menu_builder.py index 013284a27..9dddc824d 100644 --- a/gajim/gui_menu_builder.py +++ b/gajim/gui_menu_builder.py @@ -905,31 +905,31 @@ def get_conv_context_menu(account, kind, text): if kind == 'xmpp': if '?join' in text: context_menu = [ - ('copy-link', _('Copy JID')), + ('copy-text', _('Copy JID')), ('-join-groupchat', _('Join Groupchat')), ] else: context_menu = [ - ('copy-link', _('Copy JID')), + ('copy-text', _('Copy JID')), ('-start-chat', _('Start Chat')), ('-add-contact', _('Add to Roster…')), ] elif kind == 'url': context_menu = [ - ('copy-link', _('Copy Link Location')), + ('copy-text', _('Copy Link Location')), ('open-link', _('Open Link in Browser')), ] elif kind == 'mail': context_menu = [ - ('copy-link', _('Copy Email Address')), + ('copy-text', _('Copy Email Address')), ('open-link', _('Open Email Composer')), ] elif kind == 'sth_at_sth': context_menu = [ - ('copy-link', _('Copy JID/Email')), + ('copy-text', _('Copy JID/Email')), ('open-link', _('Open Email Composer')), ('-start-chat', _('Start Chat')), ('-join-groupchat', _('Join Groupchat')), @@ -954,7 +954,7 @@ def get_conv_context_menu(account, kind, text): if action == 'app.open-link': value = GLib.Variant.new_strv([kind, text]) - elif action == 'app.copy-link': + elif action == 'app.copy-text': value = GLib.Variant.new_string(text) else: value = GLib.Variant.new_strv([account, text]) @@ -964,6 +964,20 @@ def get_conv_context_menu(account, kind, text): return menu +class SearchMenu(Gtk.Menu): + def __init__(self, treeview): + Gtk.Menu.__init__(self) + self._copy_item = Gtk.MenuItem(label=_('Copy')) + self._copy_item.set_action_name('app.copy-text') + self.set_copy_text('') + self._copy_item.show() + self.append(self._copy_item) + self.attach_to_widget(treeview, None) + + def set_copy_text(self, text): + self._copy_item.set_action_target_value(GLib.Variant('s', text)) + + def escape_mnemonic(label): if label is None: return