fix: quick fix for the GTK accelerators

This commit is contained in:
Romain Failliot 2023-04-07 12:58:23 -04:00
parent 390df241de
commit 0fbc2e5e82
2 changed files with 13 additions and 8 deletions

View File

@ -15,6 +15,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
`logError` logs on stderr (@MightyCreak) `logError` logs on stderr (@MightyCreak)
- Change Git default branch from `master` to `main` (@MightyCreak) - Change Git default branch from `master` to `main` (@MightyCreak)
### Fixed
- Shortcuts were not working since the move to Gtk.Application
(issue [#188](https://github.com/MightyCreak/diffuse/issues/188)) (@MightyCreak)
## 0.8.0 - 2023-04-03 ## 0.8.0 - 2023-04-03
### Added ### Added

View File

@ -973,20 +973,20 @@ class DiffuseWindow(Gtk.ApplicationWindow):
else: else:
if cb_data is not None: if cb_data is not None:
cb_data = GLib.Variant.new_string(cb_data) cb_data = GLib.Variant.new_string(cb_data)
accel = accel.replace('_', '-') gtk_compliant_accel = accel.replace('_', '-')
if cb is not None: if cb is not None:
action = Gio.SimpleAction.new(accel, cb_data and cb_data.get_type()) cb_data_type = cb_data and cb_data.get_type()
action = Gio.SimpleAction.new(gtk_compliant_accel, cb_data_type)
action.connect('activate', cb) action.connect('activate', cb)
self.add_action(action) self.add_action(action)
item = Gio.MenuItem.new(label) item = Gio.MenuItem.new(label)
item.set_action_and_target_value('win.' + accel, cb_data) item.set_action_and_target_value('win.' + gtk_compliant_accel, cb_data)
key_binding = theResources.getKeyBindings('menu', accel) key_binding = theResources.getKeyBindings('menu', accel)
if len(key_binding) > 0: if len(key_binding) > 0:
key, modifier = key_binding[0] action_name = 'win.' + gtk_compliant_accel
self.get_application().set_accels_for_action( detailed_action_name = Gio.Action.print_detailed_name(action_name, cb_data)
Gio.Action.print_detailed_name('win.' + accel, cb_data), accels = [Gtk.accelerator_name(*key_binding[0])]
[Gtk.accelerator_name(key, modifier)], self.get_application().set_accels_for_action(detailed_action_name, accels)
)
section_menu.append_item(item) section_menu.append_item(item)
menu.append_section(None, section_menu) menu.append_section(None, section_menu)
return menu return menu