+36
-6
lines changedFilter options
+36
-6
lines changed Original file line number Diff line number Diff line change
@@ -791,8 +791,14 @@ def do_startup(self): # pylint: disable=arguments-differ
791
791
quit_action.connect("activate", self._on_quit)
792
792
self.add_action(quit_action)
793
793
794
+
_shortcuts = {}
795
+
794
796
def set_accels_for_action(action, accels, action_id=None):
795
797
action_id = action_id or action.get_id()
798
+
for accel in accels:
799
+
if accel in _shortcuts:
800
+
raise Exception(f'Shortcut "{accel}" is already set.')
801
+
_shortcuts[accel] = action_id
796
802
self.set_accels_for_action(action_id, accels)
797
803
798
804
set_accels_for_action(AppActions.quit, ["<Primary>Q"])
@@ -807,18 +813,42 @@ def set_accels_for_action(action, accels, action_id=None):
807
813
set_accels_for_action(WindowActions.export_menu, ["<Primary>O"])
808
814
set_accels_for_action(WindowActions.menu, ["F10"])
809
815
set_accels_for_action(WindowActions.show_help, ["<Primary>question"])
816
+
_plugin_shortcuts = {}
810
817
for plugin_list, plugin_action_template in (
811
818
(IMPORT_PLUGINS, "import_plugin_{}"),
812
819
(EXPORT_PLUGINS, "export_plugin_{}"),
813
820
):
814
821
for plugin_name, plugin in plugin_list.items():
815
-
if plugin.shortcut:
816
-
action_name = plugin_action_template.format(plugin_name)
817
-
set_accels_for_action(
818
-
action_name,
819
-
[plugin.shortcut],
820
-
"win.{}".format(action_name)
822
+
if not plugin.shortcut:
823
+
continue
824
+
if plugin.shortcut in _shortcuts:
825
+
_is_plugin_shortcut = plugin.shortcut in _plugin_shortcuts
826
+
error_dialog = Gtk.MessageDialog(
827
+
text=_('Error while loading plugin "{plugin_name}"').format(
828
+
plugin_name=plugin_name
829
+
),
830
+
secondary_text='\n'.join((
831
+
_('Shortcut "{shortcut}" already assigned to {action_type} "{name}".').format(
832
+
shortcut=plugin.shortcut,
833
+
action_type=_('plugin') if _is_plugin_shortcut else _('action'),
834
+
name=_plugin_shortcuts[plugin.shortcut] if _is_plugin_shortcut else _shortcuts[plugin.shortcut]
835
+
),
836
+
_('Shortcut will be disabled for "{plugin_name}" plugin.').format(
837
+
plugin_name=plugin_name
838
+
)
839
+
)),
840
+
buttons=Gtk.ButtonsType.CLOSE
821
841
)
842
+
error_dialog.run()
843
+
error_dialog.destroy()
844
+
continue
845
+
action_name = plugin_action_template.format(plugin_name)
846
+
set_accels_for_action(
847
+
action_name,
848
+
[plugin.shortcut],
849
+
f"win.{action_name}"
850
+
)
851
+
_plugin_shortcuts[plugin.shortcut] = plugin_name
822
852
823
853
def do_activate(self): # pylint: disable=arguments-differ
824
854
if not self.window:
You can’t perform that action at this time.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4