diff --git a/terminatorlib/prefseditor.py b/terminatorlib/prefseditor.py index cce7e8dc..9e441dd3 100755 --- a/terminatorlib/prefseditor.py +++ b/terminatorlib/prefseditor.py @@ -1687,6 +1687,42 @@ class PrefsEditor: if key_with_shift.level != 0 and keyval_lower == keyval_upper: mods = Gdk.ModifierType(mods & ~Gdk.ModifierType.SHIFT_MASK) + accel = Gtk.accelerator_name(key, mods) + current_binding = liststore.get_value(liststore.get_iter(path), 0) + + duplicate_bindings = [] + for conf_binding, conf_accel in self.config["keybindings"].items(): + parsed_accel = Gtk.accelerator_parse(accel) + parsed_conf_accel = Gtk.accelerator_parse(conf_accel) + + if ( + parsed_accel == parsed_conf_accel + and current_binding != conf_binding + ): + duplicate_bindings.append((conf_binding, conf_accel)) + + if duplicate_bindings: + dialog = Gtk.MessageDialog( + transient_for=self.window, + flags=Gtk.DialogFlags.MODAL, + message_type=Gtk.MessageType.ERROR, + buttons=Gtk.ButtonsType.CLOSE, + text="Duplicate Key Bindings Are Not Allowed", + ) + + accel_label = Gtk.accelerator_get_label(key, mods) + # get the first found duplicate + duplicate_keybinding_name = duplicate_bindings[0][0] + + message = ( + "Key binding `{0}` is already in use to trigger the `{1}` action." + ).format(accel_label, self.keybindingnames[duplicate_keybinding_name]) + dialog.format_secondary_text(message) + + dialog.run() + dialog.destroy() + return + celliter = liststore.get_iter_from_string(path) liststore.set(celliter, 2, key, 3, mods)