Add copy menu to Search dialog
This commit is contained in:
parent
6e7f53df48
commit
cc3750711d
4 changed files with 42 additions and 9 deletions
|
@ -355,7 +355,7 @@ def open_link(_action, param):
|
||||||
helpers.launch_browser_mailer(kind, link)
|
helpers.launch_browser_mailer(kind, link)
|
||||||
|
|
||||||
|
|
||||||
def copy_link(_action, param):
|
def copy_text(_action, param):
|
||||||
text = param.get_string()
|
text = param.get_string()
|
||||||
clip = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD)
|
clip = Gtk.Clipboard.get(Gdk.SELECTION_CLIPBOARD)
|
||||||
clip.set_text(text, -1)
|
clip.set_text(text, -1)
|
||||||
|
|
|
@ -416,8 +416,8 @@ class GajimApplication(Gtk.Application):
|
||||||
act.connect("activate", app_actions.on_add_contact_jid)
|
act.connect("activate", app_actions.on_add_contact_jid)
|
||||||
self.add_action(act)
|
self.add_action(act)
|
||||||
|
|
||||||
act = Gio.SimpleAction.new('copy-link', GLib.VariantType.new('s'))
|
act = Gio.SimpleAction.new('copy-text', GLib.VariantType.new('s'))
|
||||||
act.connect("activate", app_actions.copy_link)
|
act.connect("activate", app_actions.copy_text)
|
||||||
self.add_action(act)
|
self.add_action(act)
|
||||||
|
|
||||||
act = Gio.SimpleAction.new('open-link', GLib.VariantType.new('as'))
|
act = Gio.SimpleAction.new('open-link', GLib.VariantType.new('as'))
|
||||||
|
|
|
@ -26,6 +26,8 @@ from gajim.common.i18n import _
|
||||||
|
|
||||||
from gajim.common.modules import dataforms
|
from gajim.common.modules import dataforms
|
||||||
|
|
||||||
|
from gajim.gui_menu_builder import SearchMenu
|
||||||
|
|
||||||
from gajim.gtk.dataform import DataFormWidget
|
from gajim.gtk.dataform import DataFormWidget
|
||||||
from gajim.gtk.util import ensure_not_destroyed
|
from gajim.gtk.util import ensure_not_destroyed
|
||||||
from gajim.gtk.util import find_widget
|
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.get_style_context().add_class('search-scrolled')
|
||||||
self._scrolled.set_no_show_all(True)
|
self._scrolled.set_no_show_all(True)
|
||||||
self._treeview = None
|
self._treeview = None
|
||||||
|
self._menu = None
|
||||||
self.add(self._label)
|
self.add(self._label)
|
||||||
self.add(self._scrolled)
|
self.add(self._scrolled)
|
||||||
self.show_all()
|
self.show_all()
|
||||||
|
@ -268,6 +271,7 @@ class Completed(Gtk.Box):
|
||||||
self._scrolled.remove(self._treeview)
|
self._scrolled.remove(self._treeview)
|
||||||
self._treeview.destroy()
|
self._treeview.destroy()
|
||||||
self._treeview = None
|
self._treeview = None
|
||||||
|
self._menu = None
|
||||||
self._label.hide()
|
self._label.hide()
|
||||||
self._scrolled.hide()
|
self._scrolled.hide()
|
||||||
|
|
||||||
|
@ -303,6 +307,8 @@ class Completed(Gtk.Box):
|
||||||
self._treeview.set_hexpand(True)
|
self._treeview.set_hexpand(True)
|
||||||
self._treeview.set_vexpand(True)
|
self._treeview.set_vexpand(True)
|
||||||
self._treeview.get_style_context().add_class('search-treeview')
|
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(),
|
for field, counter in zip(form.reported.iter_fields(),
|
||||||
itertools.count()):
|
itertools.count()):
|
||||||
|
@ -316,6 +322,19 @@ class Completed(Gtk.Box):
|
||||||
self._scrolled.add(self._treeview)
|
self._scrolled.add(self._treeview)
|
||||||
self._scrolled.show()
|
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):
|
class Error(Gtk.Box):
|
||||||
|
|
||||||
|
|
|
@ -905,31 +905,31 @@ def get_conv_context_menu(account, kind, text):
|
||||||
if kind == 'xmpp':
|
if kind == 'xmpp':
|
||||||
if '?join' in text:
|
if '?join' in text:
|
||||||
context_menu = [
|
context_menu = [
|
||||||
('copy-link', _('Copy JID')),
|
('copy-text', _('Copy JID')),
|
||||||
('-join-groupchat', _('Join Groupchat')),
|
('-join-groupchat', _('Join Groupchat')),
|
||||||
]
|
]
|
||||||
else:
|
else:
|
||||||
context_menu = [
|
context_menu = [
|
||||||
('copy-link', _('Copy JID')),
|
('copy-text', _('Copy JID')),
|
||||||
('-start-chat', _('Start Chat')),
|
('-start-chat', _('Start Chat')),
|
||||||
('-add-contact', _('Add to Roster…')),
|
('-add-contact', _('Add to Roster…')),
|
||||||
]
|
]
|
||||||
|
|
||||||
elif kind == 'url':
|
elif kind == 'url':
|
||||||
context_menu = [
|
context_menu = [
|
||||||
('copy-link', _('Copy Link Location')),
|
('copy-text', _('Copy Link Location')),
|
||||||
('open-link', _('Open Link in Browser')),
|
('open-link', _('Open Link in Browser')),
|
||||||
]
|
]
|
||||||
|
|
||||||
elif kind == 'mail':
|
elif kind == 'mail':
|
||||||
context_menu = [
|
context_menu = [
|
||||||
('copy-link', _('Copy Email Address')),
|
('copy-text', _('Copy Email Address')),
|
||||||
('open-link', _('Open Email Composer')),
|
('open-link', _('Open Email Composer')),
|
||||||
]
|
]
|
||||||
|
|
||||||
elif kind == 'sth_at_sth':
|
elif kind == 'sth_at_sth':
|
||||||
context_menu = [
|
context_menu = [
|
||||||
('copy-link', _('Copy JID/Email')),
|
('copy-text', _('Copy JID/Email')),
|
||||||
('open-link', _('Open Email Composer')),
|
('open-link', _('Open Email Composer')),
|
||||||
('-start-chat', _('Start Chat')),
|
('-start-chat', _('Start Chat')),
|
||||||
('-join-groupchat', _('Join Groupchat')),
|
('-join-groupchat', _('Join Groupchat')),
|
||||||
|
@ -954,7 +954,7 @@ def get_conv_context_menu(account, kind, text):
|
||||||
|
|
||||||
if action == 'app.open-link':
|
if action == 'app.open-link':
|
||||||
value = GLib.Variant.new_strv([kind, text])
|
value = GLib.Variant.new_strv([kind, text])
|
||||||
elif action == 'app.copy-link':
|
elif action == 'app.copy-text':
|
||||||
value = GLib.Variant.new_string(text)
|
value = GLib.Variant.new_string(text)
|
||||||
else:
|
else:
|
||||||
value = GLib.Variant.new_strv([account, text])
|
value = GLib.Variant.new_strv([account, text])
|
||||||
|
@ -964,6 +964,20 @@ def get_conv_context_menu(account, kind, text):
|
||||||
return menu
|
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):
|
def escape_mnemonic(label):
|
||||||
if label is None:
|
if label is None:
|
||||||
return
|
return
|
||||||
|
|
Loading…
Add table
Reference in a new issue