Add shortcuts action to show keyboard shortcuts dialog

Create app.shortcuts action with Ctrl+? shortcut that loads and
displays the shortcuts window from GResources.
This commit is contained in:
vesp 2025-12-22 23:50:41 +01:00
parent 7fd77b7ba3
commit 01943ecb1a

View File

@ -37,6 +37,7 @@ class RosterApplication(Adw.Application):
self.create_action('quit', lambda *_: self.quit(), ['<control>q'])
self.create_action('about', self.on_about_action)
self.create_action('preferences', self.on_preferences_action)
self.create_action('shortcuts', self.on_shortcuts_action, ['<control>question'])
def do_activate(self):
"""Called when the application is activated.
@ -68,6 +69,13 @@ class RosterApplication(Adw.Application):
"""Callback for the app.preferences action."""
print('app.preferences action activated')
def on_shortcuts_action(self, widget, _):
"""Callback for the app.shortcuts action."""
builder = Gtk.Builder.new_from_resource('/cz/vesp/roster/shortcuts-dialog.ui')
shortcuts_window = builder.get_object('shortcuts_dialog')
shortcuts_window.set_transient_for(self.props.active_window)
shortcuts_window.present()
def create_action(self, name, callback, shortcuts=None):
"""Add an application action.