Commit 1411c02a authored by Philipp Hörist's avatar Philipp Hörist

MessageWindow: Refactor shortcut handling

AccelGroup/AccelMap is phased out in GTK3.

Use actions instead because they can also have shortcuts. This makes
the code much easier to read because we dont have to deal with keyval and key modifiers.

Handle all actions that are not control specific inside the MessageWindow and
delegate all control specific actions to the controls.
parent 358eab4a
......@@ -33,6 +33,7 @@ from gi.repository import Gtk
from gi.repository import Gio
from gi.repository import Pango
from gi.repository import GLib
from gi.repository import Gdk
from nbxmpp.protocol import NS_XHTML, NS_XHTML_IM, NS_FILE, NS_MUC
from nbxmpp.protocol import NS_JINGLE_RTP_AUDIO, NS_JINGLE_RTP_VIDEO
from nbxmpp.protocol import NS_JINGLE_ICE_UDP, NS_JINGLE_FILE_TRANSFER_5
......@@ -358,6 +359,28 @@ class ChatControl(ChatControlBase):
win.lookup_action(
'information-' + self.control_id).set_enabled(online)
def delegate_action(self, action):
res = super().delegate_action(action)
if res == Gdk.EVENT_STOP:
return res
if action == 'show-contact-info':
self.parent_win.window.lookup_action(
'information-%s' % self.control_id).activate()
return Gdk.EVENT_STOP
if action == 'send-file':
if app.interface.msg_win_mgr.mode == \
app.interface.msg_win_mgr.ONE_MSG_WINDOW_ALWAYS_WITH_ROSTER:
app.interface.roster.tree.grab_focus()
return Gdk.EVENT_PROPAGATE
self.parent_win.window.lookup_action(
'send-file-%s' % self.control_id).activate()
return Gdk.EVENT_STOP
return Gdk.EVENT_PROPAGATE
def _on_add_to_roster(self, action, param):
AddNewContactWindow(self.account, self.contact.jid)
......
......@@ -390,6 +390,28 @@ class ChatControlBase(MessageControl, ChatCommandProcessor, CommandTools):
# to properly use the super, because of the old code.
CommandTools.__init__(self)
def delegate_action(self, action):
if action == 'browse-history':
dict_ = {'jid': GLib.Variant('s', self.contact.jid),
'account': GLib.Variant('s', self.account)}
variant = GLib.Variant('a{sv}', dict_)
app.app.activate_action('browse-history', variant)
return Gdk.EVENT_STOP
if action == 'clear-chat':
self.conv_textview.clear()
return Gdk.EVENT_STOP
if action == 'delete-line':
self.clear(self.msg_textview)
return Gdk.EVENT_STOP
if action == 'show-emoji-chooser':
self.emoticons_button.get_popover().show()
return Gdk.EVENT_STOP
return Gdk.EVENT_PROPAGATE
def add_actions(self):
action = Gio.SimpleAction.new_stateful(
"set-encryption-%s" % self.control_id,
......
......@@ -519,6 +519,7 @@
<property name="width_request">200</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="activates_default">True</property>
<property name="caps_lock_warning">False</property>
<property name="show_emoji_icon">True</property>
<signal name="notify::text" handler="_on_nickname_text_changed" swapped="no"/>
......@@ -556,6 +557,7 @@
<property name="visible">True</property>
<property name="sensitive">False</property>
<property name="can_focus">True</property>
<property name="can_default">True</property>
<property name="receives_default">True</property>
<property name="halign">end</property>
<property name="valign">start</property>
......
......@@ -109,7 +109,7 @@
<child>
<object class="GtkShortcutsShortcut">
<property name="visible">1</property>
<property name="accelerator">&lt;alt&gt;Left &lt;ctrl&gt;Page_Up</property>
<property name="accelerator">&lt;alt&gt;Left &lt;ctrl&gt;Page_Up</property>
<property name="title" translatable="yes">Switch to the previous tab</property>
</object>
</child>
......@@ -121,13 +121,6 @@
</object>
</child>
<child>
<object class="GtkShortcutsShortcut">
<property name="visible">1</property>
<property name="accelerator">&lt;Alt&gt;1...9</property>
<property name="title" translatable="yes">Switch to the first - ninth tab</property>
</object>
</child>
<child>
<object class="GtkShortcutsShortcut">
<property name="visible">1</property>
<property name="accelerator">&lt;ctrl&gt;&lt;shift&gt;Tab</property>
......@@ -158,7 +151,7 @@
<child>
<object class="GtkShortcutsShortcut">
<property name="visible">1</property>
<property name="accelerator">Escape &lt;ctrl&gt;w &lt;ctrl&gt;F4</property>
<property name="accelerator">Escape &lt;ctrl&gt;w</property>
<property name="title" translatable="yes">Close chat</property>
</object>
</child>
......
......@@ -367,7 +367,7 @@ class GroupchatControl(ChatControlBase):
super().add_actions()
actions = [
('change-subject-', self._on_change_subject),
('change-nick-', self._on_change_nick),
('change-nickname-', self._on_change_nick),
('disconnect-', self._on_disconnect),
('destroy-', self._on_destroy_room),
('configure-', self._on_configure_room),
......@@ -492,7 +492,7 @@ class GroupchatControl(ChatControlBase):
subject)
# Change Nick
self._get_action('change-nick-').set_enabled(self.is_connected)
self._get_action('change-nickname-').set_enabled(self.is_connected)
# Execute command
self._get_action('execute-command-').set_enabled(self.is_connected)
......@@ -549,6 +549,9 @@ class GroupchatControl(ChatControlBase):
transition = Gtk.StackTransitionType.SLIDE_UP
self.xml.stack.set_visible_child_full(name, transition)
def _get_current_page(self):
return self.xml.stack.get_visible_child_name()
def _cell_data_func(self, column, renderer, model, iter_, user_data):
# Background color has to be rendered for all cells
theme = app.config.get('roster_theme')
......@@ -2502,6 +2505,29 @@ class GroupchatControl(ChatControlBase):
widget.get_selection().unselect_all()
return True
def delegate_action(self, action):
res = super().delegate_action(action)
if res == Gdk.EVENT_STOP:
return res
if action == 'change-nickname':
control_action = '%s-%s' % (action, self.control_id)
self.parent_win.window.lookup_action(control_action).activate()
return Gdk.EVENT_STOP
if action == 'escape':
if self._get_current_page() == 'groupchat':
return Gdk.EVENT_PROPAGATE
self._show_page('groupchat')
return Gdk.EVENT_STOP
if action == 'change-subject':
control_action = '%s-%s' % (action, self.control_id)
self.parent_win.window.lookup_action(control_action).activate()
return Gdk.EVENT_STOP
return Gdk.EVENT_PROPAGATE
def on_list_treeview_row_expanded(self, widget, iter_, path):
"""
When a row is expanded: change the icon of the arrow
......@@ -2946,6 +2972,7 @@ class GroupchatControl(ChatControlBase):
def _on_change_nick(self, _action, _param):
self.xml.nickname_entry.set_text(self.nick)
self.xml.nickname_entry.grab_focus()
self.xml.nickname_change_button.grab_default()
self._show_page('nickname')
def _on_nickname_text_changed(self, entry, _param):
......
......@@ -594,7 +594,7 @@ def get_groupchat_menu(control_id, account, jid):
(_('Send Chatstate'), ['chatstate']),
]),
(_('Sync Threshold'), ['sync']),
('win.change-nick-', _('Change Nick')),
('win.change-nickname-', _('Change Nick')),
('win.request-voice-', _('Request Voice')),
('win.execute-command-', _('Execute command')),
('app.browse-history', _('History')),
......
This diff is collapsed.
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