From e2364a154aa81e390fdea6e8989582a64949cbac Mon Sep 17 00:00:00 2001 From: Storm Dragon Date: Thu, 5 Jun 2025 13:40:44 -0400 Subject: [PATCH] Another try to get keybindings working. --- src/cthulhu/cthulhu.py | 3 +++ src/cthulhu/plugin_system_manager.py | 16 ++++++++++++++++ src/cthulhu/scripts/default.py | 2 ++ 3 files changed, 21 insertions(+) diff --git a/src/cthulhu/cthulhu.py b/src/cthulhu/cthulhu.py index e9507fd..b177a31 100644 --- a/src/cthulhu/cthulhu.py +++ b/src/cthulhu/cthulhu.py @@ -663,6 +663,9 @@ def loadUserSettings(script=None, inputEvent=None, skipReloadMessage=False): _scriptManager.activate() _eventManager.activate() + + # Refresh keybindings to include plugin bindings (after script manager is active) + cthulhuApp.getPluginSystemManager().refresh_active_script_keybindings() cthulhuApp.getSignalManager().emitSignal('load-setting-begin') # cthulhuApp.getPluginSystemManager().register_plugin_keybindings_with_active_script() diff --git a/src/cthulhu/plugin_system_manager.py b/src/cthulhu/plugin_system_manager.py index 053fa15..623cafd 100644 --- a/src/cthulhu/plugin_system_manager.py +++ b/src/cthulhu/plugin_system_manager.py @@ -156,6 +156,22 @@ class PluginSystemManager: import traceback logger.error(traceback.format_exc()) + def refresh_active_script_keybindings(self): + """Force active script to refresh its keybindings to include plugin bindings.""" + from . import cthulhu_state + if cthulhu_state.activeScript: + active_script = cthulhu_state.activeScript + with open('/tmp/plugin_registration.log', 'a') as f: + f.write(f"=== refresh_active_script_keybindings() CALLED ===\n") + f.write(f"Active script: {active_script.name}\n") + + # Force the script to recreate its keybindings to include plugin bindings + old_keybindings = active_script.keyBindings + active_script.keyBindings = active_script.getKeyBindings() + + with open('/tmp/plugin_registration.log', 'a') as f: + f.write(f"Keybindings refreshed: old={len(old_keybindings.keyBindings) if old_keybindings else 0}, new={len(active_script.keyBindings.keyBindings)}\n") + def register_plugin_keybindings_with_active_script(self): """Register all plugin keybindings with the active script.""" diff --git a/src/cthulhu/scripts/default.py b/src/cthulhu/scripts/default.py index a0cca9a..5ea8e31 100644 --- a/src/cthulhu/scripts/default.py +++ b/src/cthulhu/scripts/default.py @@ -363,6 +363,8 @@ class Script(script.Script): return keyBindings def getExtensionBindings(self): + with open('/tmp/extension_bindings_debug.log', 'a') as f: + f.write(f"=== getExtensionBindings() called ===\n") keyBindings = keybindings.KeyBindings() bindings = self.notificationPresenter.get_bindings()