Commit c08f752d authored by Philipp Hörist's avatar Philipp Hörist

Refactor "Save as" menu

parent 2c6b2e0b
......@@ -568,8 +568,6 @@ class ChatControl(ChatControlBase):
If right-clicked, show popup
"""
if event.button == 3: # right click
menu = Gtk.Menu()
menuitem = Gtk.MenuItem.new_with_mnemonic(_('Save _As'))
if self.TYPE_ID == message_control.TYPE_CHAT:
sha = app.contacts.get_avatar_sha(
self.account, self.contact.jid)
......@@ -577,16 +575,7 @@ class ChatControl(ChatControlBase):
else:
sha = self.gc_contact.avatar_sha
name = self.gc_contact.get_shown_name()
id_ = menuitem.connect('activate',
gtkgui_helpers.on_avatar_save_as_menuitem_activate, sha, name)
self.handlers[id_] = menuitem
menu.append(menuitem)
menu.show_all()
menu.connect('selection-done', lambda w: w.destroy())
# show the menu
menu.show_all()
menu.attach_to_widget(widget, None)
menu.popup(None, None, None, None, event.button, event.time)
gui_menu_builder.show_save_as_menu(sha, name)
return True
def on_location_eventbox_button_release_event(self, widget, event):
......
......@@ -31,6 +31,7 @@ from gajim.common.i18n import _
from gajim.common.const import AvatarSize
from gajim import gtkgui_helpers
from gajim.gui_menu_builder import show_save_as_menu
from gajim.gtk.dialogs import ErrorDialog
from gajim.gtk.dialogs import InformationDialog
......@@ -154,25 +155,13 @@ class ProfileWindow(Gtk.ApplicationWindow):
"""
If right-clicked, show popup
"""
if event.button == 3:
# right click
menu = Gtk.Menu()
nick = app.config.get_per('accounts', self.account, 'name')
if self.avatar_sha is None:
return
menuitem = Gtk.MenuItem.new_with_mnemonic(_('Save _As'))
menuitem.connect(
'activate',
gtkgui_helpers.on_avatar_save_as_menuitem_activate,
self.avatar_sha, nick)
menu.append(menuitem)
menu.connect('selection-done', lambda w: w.destroy())
# show the menu
menu.show_all()
menu.attach_to_widget(widget, None)
menu.popup(None, None, None, None, event.button, event.time)
show_save_as_menu(self.avatar_sha, nick)
elif event.button == 1: # left click
self.on_set_avatar_button_clicked(widget)
......
......@@ -596,6 +596,18 @@ def get_transport_menu(contact, account):
return menu
def show_save_as_menu(sha, name):
menu = Gtk.Menu()
menuitem = Gtk.MenuItem.new_with_mnemonic(_('Save _As'))
menuitem.connect(
'activate',
gtkgui_helpers.on_avatar_save_as_menuitem_activate, sha, name)
menu.append(menuitem)
menu.connect('selection-done', lambda w: w.destroy())
menu.show_all()
menu.popup_at_pointer()
def get_singlechat_menu(control_id):
singlechat_menu = [
(_('Send File…'), [
......
......@@ -34,6 +34,7 @@ from gi.repository import GLib
from gi.repository import Gdk
from gajim import gtkgui_helpers
from gajim.gui_menu_builder import show_save_as_menu
from gajim.common import helpers
from gajim.common import app
from gajim.common import ged
......@@ -160,8 +161,6 @@ class VcardWindow:
If right-clicked, show popup
"""
if event.button == 3: # right click
menu = Gtk.Menu()
menuitem = Gtk.MenuItem.new_with_mnemonic(_('Save _As'))
if self.gc_contact:
sha = self.gc_contact.avatar_sha
name = self.gc_contact.get_shown_name()
......@@ -171,14 +170,7 @@ class VcardWindow:
name = self.contact.get_shown_name()
if sha is None:
sha = self.avatar
menuitem.connect('activate',
gtkgui_helpers.on_avatar_save_as_menuitem_activate, sha, name)
menu.append(menuitem)
menu.connect('selection-done', lambda w: w.destroy())
# show the menu
menu.show_all()
menu.attach_to_widget(widget, None)
menu.popup(None, None, None, None, event.button, event.time)
show_save_as_menu(sha, name)
def set_value(self, entry_name, value):
try:
......@@ -512,17 +504,8 @@ class ZeroconfVcardWindow:
If right-clicked, show popup
"""
if event.button == 3: # right click
menu = Gtk.Menu()
menuitem = Gtk.MenuItem.new_with_mnemonic(_('Save _As'))
menuitem.connect('activate',
gtkgui_helpers.on_avatar_save_as_menuitem_activate,
self.contact.avatar_sha, self.contact.get_shown_name())
menu.append(menuitem)
menu.connect('selection-done', lambda w: w.destroy())
# show the menu
menu.show_all()
menu.attach_to_widget(widget, None)
menu.popup(None, None, None, None, event.button, event.time)
show_save_as_menu(self.contact.avatar_sha,
self.contact.get_shown_name())
def set_value(self, entry_name, value):
try:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment