From e19347d6daf3d2dc4d869becb27478ffd1c31e1a Mon Sep 17 00:00:00 2001 From: Andrew Belt Date: Mon, 14 Feb 2022 18:39:00 -0500 Subject: [PATCH] Use setModulePosForce() in RackWidget::addModuleAtMouse(). Push ModuleMove action when calling addModuleAtMouse(). --- include/app/RackWidget.hpp | 2 +- src/app/Browser.cpp | 13 ++++++++++--- src/app/ModuleWidget.cpp | 16 +++++++++------- src/app/RackWidget.cpp | 19 +++++++++++++------ 4 files changed, 33 insertions(+), 17 deletions(-) diff --git a/include/app/RackWidget.hpp b/include/app/RackWidget.hpp index 75f064f1..945d2c2b 100644 --- a/include/app/RackWidget.hpp +++ b/include/app/RackWidget.hpp @@ -70,7 +70,7 @@ struct RackWidget : widget::OpaqueWidget { std::vector getModules(); bool hasModules(); void updateModuleOldPositions(); - history::ComplexAction* getModuleDragAction(); + history::ComplexAction* getModuleMoveAction(); // Module selection methods diff --git a/src/app/Browser.cpp b/src/app/Browser.cpp index 083af19a..29c2d95a 100644 --- a/src/app/Browser.cpp +++ b/src/app/Browser.cpp @@ -82,6 +82,9 @@ static ModuleWidget* chooseModel(plugin::Model* model) { mi.added++; mi.lastAdded = system::getUnixTime(); + history::ComplexAction* h = new history::ComplexAction; + h->name = "add module"; + // Create Module and ModuleWidget INFO("Creating module %s", model->getFullName().c_str()); engine::Module* module = model->createModule(); @@ -89,16 +92,20 @@ static ModuleWidget* chooseModel(plugin::Model* model) { INFO("Creating module widget %s", model->getFullName().c_str()); ModuleWidget* moduleWidget = model->createModuleWidget(module); + + APP->scene->rack->updateModuleOldPositions(); APP->scene->rack->addModuleAtMouse(moduleWidget); + h->push(APP->scene->rack->getModuleMoveAction()); // Load template preset moduleWidget->loadTemplate(); // history::ModuleAdd - history::ModuleAdd* h = new history::ModuleAdd; - h->name = "create module"; + history::ModuleAdd* ha = new history::ModuleAdd; // This serializes the module so redoing returns to the current state. - h->setModule(moduleWidget); + ha->setModule(moduleWidget); + h->push(ha); + APP->history->push(h); // Hide Module Browser diff --git a/src/app/ModuleWidget.cpp b/src/app/ModuleWidget.cpp index 6a46b2b7..1874403a 100644 --- a/src/app/ModuleWidget.cpp +++ b/src/app/ModuleWidget.cpp @@ -402,12 +402,12 @@ void ModuleWidget::onButton(const ButtonEvent& e) { // Toggle selection on Shift-click if ((e.mods & RACK_MOD_MASK) == GLFW_MOD_SHIFT) { APP->scene->rack->select(this, true); + return; } - if ((e.mods & RACK_MOD_MASK) == 0) { - // If module positions are locked, don't consume left-click - if (settings::lockModules) { - return; - } + + // If module positions are locked, don't consume left-click + if (settings::lockModules) { + return; } internal->dragOffset = e.pos; @@ -442,7 +442,7 @@ void ModuleWidget::onDragEnd(const DragEndEvent& e) { // The next time the module is dragged, it should always move immediately internal->dragEnabled = true; - history::ComplexAction* h = APP->scene->rack->getModuleDragAction(); + history::ComplexAction* h = APP->scene->rack->getModuleMoveAction(); if (!h->isEmpty()) APP->history->push(h); else @@ -816,7 +816,9 @@ void ModuleWidget::cloneAction(bool cloneCables) { // Clone ModuleWidget INFO("Creating module widget %s", model->getFullName().c_str()); ModuleWidget* clonedModuleWidget = model->createModuleWidget(clonedModule); + APP->scene->rack->updateModuleOldPositions(); APP->scene->rack->addModuleAtMouse(clonedModuleWidget); + h->push(APP->scene->rack->getModuleMoveAction()); // history::ModuleAdd history::ModuleAdd* hma = new history::ModuleAdd; @@ -871,7 +873,7 @@ void ModuleWidget::bypassAction(bool bypassed) { void ModuleWidget::removeAction() { history::ComplexAction* complexAction = new history::ComplexAction; - complexAction->name = "remove module"; + complexAction->name = "delete module"; appendDisconnectActions(complexAction); // history::ModuleRemove diff --git a/src/app/RackWidget.cpp b/src/app/RackWidget.cpp index ea7bd7cf..af86a28d 100644 --- a/src/app/RackWidget.cpp +++ b/src/app/RackWidget.cpp @@ -536,13 +536,20 @@ void RackWidget::pasteModuleJsonAction(json_t* moduleJ) { assert(mw); assert(mw->module); + history::ComplexAction* h = new history::ComplexAction; + h->name = "paste module"; + APP->engine->addModule(mw->module); + + updateModuleOldPositions(); addModuleAtMouse(mw); + h->push(getModuleMoveAction()); // history::ModuleAdd - history::ModuleAdd* h = new history::ModuleAdd; - h->name = "paste module"; - h->setModule(mw); + history::ModuleAdd* ha = new history::ModuleAdd; + ha->setModule(mw); + h->push(ha); + APP->history->push(h); } @@ -591,7 +598,7 @@ void RackWidget::addModuleAtMouse(ModuleWidget* mw) { assert(mw); // Move module nearest to the mouse position math::Vec pos = internal->mousePos.minus(mw->box.size.div(2)); - setModulePosNearest(mw, pos); + setModulePosForce(mw, pos); addModule(mw); } @@ -783,7 +790,7 @@ void RackWidget::updateModuleOldPositions() { } } -history::ComplexAction* RackWidget::getModuleDragAction() { +history::ComplexAction* RackWidget::getModuleMoveAction() { history::ComplexAction* h = new history::ComplexAction; h->name = "move modules"; @@ -1130,7 +1137,7 @@ bool RackWidget::isSelectionBypassed() { void RackWidget::deleteSelectionAction() { history::ComplexAction* complexAction = new history::ComplexAction; - complexAction->name = "remove modules"; + complexAction->name = "delete modules"; // Copy selected set since removing ModuleWidgets modifies it. std::set selectedModules = getSelected();