From 8e5e6d1642c2959a2d57282552af4ca29b882fa2 Mon Sep 17 00:00:00 2001 From: Vishweshwar Saran Singh Deo Date: Wed, 23 Nov 2022 15:34:22 +0530 Subject: [PATCH] [bug 681] Plugin Submission + Generic Plugin Utility Functions & KeyBinding Feature: Mouseless / Mousefree / Keyboard URL opening or yanking #681 - renamed api interfacted for better clarity - removed double checking of short-cut binding for plugins in keybindings --- terminatorlib/config.py | 2 +- terminatorlib/plugin.py | 18 ++++++++++++++++-- terminatorlib/prefseditor.py | 24 +++++++++++------------- 3 files changed, 28 insertions(+), 16 deletions(-) diff --git a/terminatorlib/config.py b/terminatorlib/config.py index 7129512c..04b08c8e 100644 --- a/terminatorlib/config.py +++ b/terminatorlib/config.py @@ -723,7 +723,7 @@ class ConfigBase(Borg): from terminatorlib.plugin import KeyBindUtil # for plugin KeyBindUtil assist in plugin_util keybindutil = KeyBindUtil(); - keyb_keys = keybindutil.get_act_to_keys() + keyb_keys = keybindutil.get_all_act_to_keys() # we only need keys as a reference so to match them # against new values keyb_keys = dict.fromkeys(keyb_keys, "") diff --git a/terminatorlib/plugin.py b/terminatorlib/plugin.py index db18835b..8ab8ddf8 100644 --- a/terminatorlib/plugin.py +++ b/terminatorlib/plugin.py @@ -303,8 +303,22 @@ class KeyBindUtil: dbg("keyaction: (%s)" % str(ret)) return self.map_key_to_act.get(ret, None) - def get_act_to_keys(self): + def get_act_to_keys(self, key): + return self.map_act_to_keys.get(key) + + def get_all_act_to_keys(self): return self.map_act_to_keys - def get_act_to_desc(self): + def get_all_act_to_desc(self): return self.map_act_to_desc + + def get_act_to_desc(self, act): + return self.map_act_to_desc.get(act) + + #get action to key binding from config + def get_act_to_keys_config(self, act): + if not self.config: + raise Warning("get_keyvalmask_for_act called without config init") + + keybindings = self.config["keybindings"] + return keybindings.get(act) diff --git a/terminatorlib/prefseditor.py b/terminatorlib/prefseditor.py index f34a0fac..055b8b0a 100755 --- a/terminatorlib/prefseditor.py +++ b/terminatorlib/prefseditor.py @@ -464,8 +464,8 @@ class PrefsEditor: keybindings = self.config['keybindings'] keybindutil = KeyBindUtil() - plugin_keyb_act = keybindutil.get_act_to_keys() - plugin_keyb_desc = keybindutil.get_act_to_desc() + plugin_keyb_act = keybindutil.get_all_act_to_keys() + plugin_keyb_desc = keybindutil.get_all_act_to_desc() #merge give preference to main bindings over plugin keybindings = {**plugin_keyb_act, **keybindings} self.keybindingnames = {**plugin_keyb_desc, **self.keybindingnames} @@ -1817,7 +1817,7 @@ class PrefsEditor: keybindutil = KeyBindUtil() keybindings = self.config["keybindings"] #merge give preference to main bindings over plugin - plugin_keyb_act = keybindutil.get_act_to_keys() + plugin_keyb_act = keybindutil.get_all_act_to_keys() keybindings = {**plugin_keyb_act, **keybindings} duplicate_bindings = [] @@ -1865,16 +1865,14 @@ class PrefsEditor: accel = Gtk.accelerator_name(key, mods) self.config['keybindings'][binding] = accel - plugin_keyb_desc = keybindutil.get_act_to_desc() - - if binding in plugin_keyb_desc: - if binding in plugin_keyb_desc: - desc = plugin_keyb_desc[binding] - dbg("modifying plugin binding: %s, %s, %s" % (desc, binding, accel)) - keybindutil.bindkey([desc, binding, accel]) - else: - dbg("skipping: %s" % binding) - pass + plugin_keyb_desc = keybindutil.get_act_to_desc(binding) + if plugin_keyb_desc: + dbg("modifying plugin binding: %s, %s, %s" % + (plugin_keyb_desc, binding, accel)) + keybindutil.bindkey([plugin_keyb_desc, binding, accel]) + else: + dbg("skipping: %s" % binding) + pass self.config.save()