From b017ebf887b5b1b37817a050d1489858f3e04196 Mon Sep 17 00:00:00 2001 From: Andrew Belt Date: Wed, 4 Aug 2021 12:13:11 -0400 Subject: [PATCH] Move module selection key commands to Scene so they are handled regardless of mouse position. --- include/app/RackWidget.hpp | 1 + src/app/ModuleWidget.cpp | 43 ++++++++++++++++++++------------------ src/app/RackWidget.cpp | 10 +++++++++ src/app/Scene.cpp | 27 ++++++++++++++++++++++++ 4 files changed, 61 insertions(+), 20 deletions(-) diff --git a/include/app/RackWidget.hpp b/include/app/RackWidget.hpp index 8665e67d..bf3c3196 100644 --- a/include/app/RackWidget.hpp +++ b/include/app/RackWidget.hpp @@ -72,6 +72,7 @@ struct RackWidget : widget::OpaqueWidget { void updateModuleSelections(); void clearModuleSelections(); + bool hasSelectedModules(); int getNumSelectedModules(); std::list getSelectedModules(); void resetSelectedModulesAction(); diff --git a/src/app/ModuleWidget.cpp b/src/app/ModuleWidget.cpp index 3bba9709..30cd674b 100644 --- a/src/app/ModuleWidget.cpp +++ b/src/app/ModuleWidget.cpp @@ -316,18 +316,17 @@ void ModuleWidget::onHoverKey(const HoverKeyEvent& e) { if (e.action == GLFW_PRESS || e.action == GLFW_REPEAT) { if (e.keyName == "i" && (e.mods & RACK_MOD_MASK) == RACK_MOD_CTRL) { - if (internal->selected) - APP->scene->rack->resetSelectedModulesAction(); - else + // Don't handle key commands if modules are selected, since it will interfere with Scene's module selection key commands + if (!APP->scene->rack->hasSelectedModules()) { resetAction(); - e.consume(this); + e.consume(this); + } } if (e.keyName == "r" && (e.mods & RACK_MOD_MASK) == RACK_MOD_CTRL) { - if (internal->selected) - APP->scene->rack->randomizeSelectedModulesAction(); - else + if (!APP->scene->rack->hasSelectedModules()) { randomizeAction(); - e.consume(this); + e.consume(this); + } } if (e.keyName == "c" && (e.mods & RACK_MOD_MASK) == RACK_MOD_CTRL) { copyClipboard(); @@ -342,28 +341,32 @@ void ModuleWidget::onHoverKey(const HoverKeyEvent& e) { e.consume(this); } if (e.keyName == "u" && (e.mods & RACK_MOD_MASK) == RACK_MOD_CTRL) { - if (internal->selected) - APP->scene->rack->disconnectSelectedModulesAction(); - else + if (!APP->scene->rack->hasSelectedModules()) { disconnectAction(); - e.consume(this); + e.consume(this); + } } if (e.keyName == "e" && (e.mods & RACK_MOD_MASK) == RACK_MOD_CTRL) { - if (internal->selected) - APP->scene->rack->bypassSelectedModulesAction(!APP->scene->rack->areSelectedModulesBypassed()); - else + if (!APP->scene->rack->hasSelectedModules()) { bypassAction(!module->isBypassed()); - e.consume(this); + e.consume(this); + } + } + if ((e.key == GLFW_KEY_DELETE || e.key == GLFW_KEY_BACKSPACE) && (e.mods & RACK_MOD_MASK) == 0) { + if (!APP->scene->rack->hasSelectedModules()) { + removeAction(); + e.consume(this); + } } } if (e.action == RACK_HELD) { + // Also handle Delete/Backspace when holding the key while hovering if ((e.key == GLFW_KEY_DELETE || e.key == GLFW_KEY_BACKSPACE) && (e.mods & RACK_MOD_MASK) == 0) { - if (internal->selected) - APP->scene->rack->deleteSelectedModulesAction(); - else + if (!APP->scene->rack->hasSelectedModules()) { removeAction(); - e.consume(NULL); + e.consume(NULL); + } } } } diff --git a/src/app/RackWidget.cpp b/src/app/RackWidget.cpp index ad436a93..48b0542d 100644 --- a/src/app/RackWidget.cpp +++ b/src/app/RackWidget.cpp @@ -659,6 +659,16 @@ void RackWidget::clearModuleSelections() { } } +bool RackWidget::hasSelectedModules() { + for (widget::Widget* w : internal->moduleContainer->children) { + ModuleWidget* mw = dynamic_cast(w); + assert(mw); + if (mw->selected()) + return true; + } + return false; +} + int RackWidget::getNumSelectedModules() { int count = 0; for (widget::Widget* w : internal->moduleContainer->children) { diff --git a/src/app/Scene.cpp b/src/app/Scene.cpp index 00aa8c63..b5fb84b0 100644 --- a/src/app/Scene.cpp +++ b/src/app/Scene.cpp @@ -210,6 +210,33 @@ void Scene::onHoverKey(const HoverKeyEvent& e) { APP->window->setFullScreen(false); e.consume(this); } + + // Module selections + if (e.keyName == "i" && (e.mods & RACK_MOD_MASK) == RACK_MOD_CTRL) { + if (rack->hasSelectedModules()) + rack->resetSelectedModulesAction(); + e.consume(this); + } + if (e.keyName == "r" && (e.mods & RACK_MOD_MASK) == RACK_MOD_CTRL) { + if (rack->hasSelectedModules()) + rack->randomizeSelectedModulesAction(); + e.consume(this); + } + if (e.keyName == "u" && (e.mods & RACK_MOD_MASK) == RACK_MOD_CTRL) { + if (rack->hasSelectedModules()) + rack->disconnectSelectedModulesAction(); + e.consume(this); + } + if (e.keyName == "e" && (e.mods & RACK_MOD_MASK) == RACK_MOD_CTRL) { + if (rack->hasSelectedModules()) + rack->bypassSelectedModulesAction(!rack->areSelectedModulesBypassed()); + e.consume(this); + } + if ((e.key == GLFW_KEY_DELETE || e.key == GLFW_KEY_BACKSPACE) && (e.mods & RACK_MOD_MASK) == 0) { + if (rack->hasSelectedModules()) + rack->deleteSelectedModulesAction(); + e.consume(this); + } } }