@@ -70,7 +70,7 @@ struct RackWidget : widget::OpaqueWidget { | |||||
std::vector<ModuleWidget*> getModules(); | std::vector<ModuleWidget*> getModules(); | ||||
bool hasModules(); | bool hasModules(); | ||||
void updateModuleOldPositions(); | void updateModuleOldPositions(); | ||||
history::ComplexAction* getModuleDragAction(); | |||||
history::ComplexAction* getModuleMoveAction(); | |||||
// Module selection methods | // Module selection methods | ||||
@@ -82,6 +82,9 @@ static ModuleWidget* chooseModel(plugin::Model* model) { | |||||
mi.added++; | mi.added++; | ||||
mi.lastAdded = system::getUnixTime(); | mi.lastAdded = system::getUnixTime(); | ||||
history::ComplexAction* h = new history::ComplexAction; | |||||
h->name = "add module"; | |||||
// Create Module and ModuleWidget | // Create Module and ModuleWidget | ||||
INFO("Creating module %s", model->getFullName().c_str()); | INFO("Creating module %s", model->getFullName().c_str()); | ||||
engine::Module* module = model->createModule(); | engine::Module* module = model->createModule(); | ||||
@@ -89,16 +92,20 @@ static ModuleWidget* chooseModel(plugin::Model* model) { | |||||
INFO("Creating module widget %s", model->getFullName().c_str()); | INFO("Creating module widget %s", model->getFullName().c_str()); | ||||
ModuleWidget* moduleWidget = model->createModuleWidget(module); | ModuleWidget* moduleWidget = model->createModuleWidget(module); | ||||
APP->scene->rack->updateModuleOldPositions(); | |||||
APP->scene->rack->addModuleAtMouse(moduleWidget); | APP->scene->rack->addModuleAtMouse(moduleWidget); | ||||
h->push(APP->scene->rack->getModuleMoveAction()); | |||||
// Load template preset | // Load template preset | ||||
moduleWidget->loadTemplate(); | moduleWidget->loadTemplate(); | ||||
// history::ModuleAdd | // 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. | // This serializes the module so redoing returns to the current state. | ||||
h->setModule(moduleWidget); | |||||
ha->setModule(moduleWidget); | |||||
h->push(ha); | |||||
APP->history->push(h); | APP->history->push(h); | ||||
// Hide Module Browser | // Hide Module Browser | ||||
@@ -402,12 +402,12 @@ void ModuleWidget::onButton(const ButtonEvent& e) { | |||||
// Toggle selection on Shift-click | // Toggle selection on Shift-click | ||||
if ((e.mods & RACK_MOD_MASK) == GLFW_MOD_SHIFT) { | if ((e.mods & RACK_MOD_MASK) == GLFW_MOD_SHIFT) { | ||||
APP->scene->rack->select(this, true); | 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; | 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 | // The next time the module is dragged, it should always move immediately | ||||
internal->dragEnabled = true; | internal->dragEnabled = true; | ||||
history::ComplexAction* h = APP->scene->rack->getModuleDragAction(); | |||||
history::ComplexAction* h = APP->scene->rack->getModuleMoveAction(); | |||||
if (!h->isEmpty()) | if (!h->isEmpty()) | ||||
APP->history->push(h); | APP->history->push(h); | ||||
else | else | ||||
@@ -816,7 +816,9 @@ void ModuleWidget::cloneAction(bool cloneCables) { | |||||
// Clone ModuleWidget | // Clone ModuleWidget | ||||
INFO("Creating module widget %s", model->getFullName().c_str()); | INFO("Creating module widget %s", model->getFullName().c_str()); | ||||
ModuleWidget* clonedModuleWidget = model->createModuleWidget(clonedModule); | ModuleWidget* clonedModuleWidget = model->createModuleWidget(clonedModule); | ||||
APP->scene->rack->updateModuleOldPositions(); | |||||
APP->scene->rack->addModuleAtMouse(clonedModuleWidget); | APP->scene->rack->addModuleAtMouse(clonedModuleWidget); | ||||
h->push(APP->scene->rack->getModuleMoveAction()); | |||||
// history::ModuleAdd | // history::ModuleAdd | ||||
history::ModuleAdd* hma = new history::ModuleAdd; | history::ModuleAdd* hma = new history::ModuleAdd; | ||||
@@ -871,7 +873,7 @@ void ModuleWidget::bypassAction(bool bypassed) { | |||||
void ModuleWidget::removeAction() { | void ModuleWidget::removeAction() { | ||||
history::ComplexAction* complexAction = new history::ComplexAction; | history::ComplexAction* complexAction = new history::ComplexAction; | ||||
complexAction->name = "remove module"; | |||||
complexAction->name = "delete module"; | |||||
appendDisconnectActions(complexAction); | appendDisconnectActions(complexAction); | ||||
// history::ModuleRemove | // history::ModuleRemove | ||||
@@ -536,13 +536,20 @@ void RackWidget::pasteModuleJsonAction(json_t* moduleJ) { | |||||
assert(mw); | assert(mw); | ||||
assert(mw->module); | assert(mw->module); | ||||
history::ComplexAction* h = new history::ComplexAction; | |||||
h->name = "paste module"; | |||||
APP->engine->addModule(mw->module); | APP->engine->addModule(mw->module); | ||||
updateModuleOldPositions(); | |||||
addModuleAtMouse(mw); | addModuleAtMouse(mw); | ||||
h->push(getModuleMoveAction()); | |||||
// history::ModuleAdd | // 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); | APP->history->push(h); | ||||
} | } | ||||
@@ -591,7 +598,7 @@ void RackWidget::addModuleAtMouse(ModuleWidget* mw) { | |||||
assert(mw); | assert(mw); | ||||
// Move module nearest to the mouse position | // Move module nearest to the mouse position | ||||
math::Vec pos = internal->mousePos.minus(mw->box.size.div(2)); | math::Vec pos = internal->mousePos.minus(mw->box.size.div(2)); | ||||
setModulePosNearest(mw, pos); | |||||
setModulePosForce(mw, pos); | |||||
addModule(mw); | addModule(mw); | ||||
} | } | ||||
@@ -783,7 +790,7 @@ void RackWidget::updateModuleOldPositions() { | |||||
} | } | ||||
} | } | ||||
history::ComplexAction* RackWidget::getModuleDragAction() { | |||||
history::ComplexAction* RackWidget::getModuleMoveAction() { | |||||
history::ComplexAction* h = new history::ComplexAction; | history::ComplexAction* h = new history::ComplexAction; | ||||
h->name = "move modules"; | h->name = "move modules"; | ||||
@@ -1130,7 +1137,7 @@ bool RackWidget::isSelectionBypassed() { | |||||
void RackWidget::deleteSelectionAction() { | void RackWidget::deleteSelectionAction() { | ||||
history::ComplexAction* complexAction = new history::ComplexAction; | history::ComplexAction* complexAction = new history::ComplexAction; | ||||
complexAction->name = "remove modules"; | |||||
complexAction->name = "delete modules"; | |||||
// Copy selected set since removing ModuleWidgets modifies it. | // Copy selected set since removing ModuleWidgets modifies it. | ||||
std::set<ModuleWidget*> selectedModules = getSelected(); | std::set<ModuleWidget*> selectedModules = getSelected(); | ||||