diff --git a/include/app/RackWidget.hpp b/include/app/RackWidget.hpp index a28998dc..a602731d 100644 --- a/include/app/RackWidget.hpp +++ b/include/app/RackWidget.hpp @@ -53,6 +53,7 @@ struct RackWidget : OpaqueWidget { // Cable methods void clearCables(); + void clearCablesAction(); /** Removes all complete cables connected to the port */ void clearCablesOnPort(PortWidget *port); /** Adds a complete cable and adds it to the Engine. diff --git a/src/app/RackWidget.cpp b/src/app/RackWidget.cpp index 9008ccbc..860cae7a 100644 --- a/src/app/RackWidget.cpp +++ b/src/app/RackWidget.cpp @@ -408,6 +408,26 @@ void RackWidget::clearCables() { cableContainer->clearChildren(); } +void RackWidget::clearCablesAction() { + // Add CableRemove for every cable to a ComplexAction + history::ComplexAction *complexAction = new history::ComplexAction; + + for (Widget *w : cableContainer->children) { + CableWidget *cw = dynamic_cast(w); + assert(cw); + if (cw == incompleteCable) + continue; + + // history::CableRemove + history::CableRemove *h = new history::CableRemove; + h->setCable(cw); + complexAction->push(h); + } + + app()->history->push(complexAction); + clearCables(); +} + void RackWidget::clearCablesOnPort(PortWidget *port) { assert(port); std::list childrenCopy = cableContainer->children; diff --git a/src/patch.cpp b/src/patch.cpp index 0976c8e8..071c19cc 100644 --- a/src/patch.cpp +++ b/src/patch.cpp @@ -4,6 +4,7 @@ #include "app.hpp" #include "app/Scene.hpp" #include "app/RackWidget.hpp" +#include "history.hpp" #include "osdialog.h" @@ -14,6 +15,7 @@ static const std::string PATCH_FILTERS = "VCV Rack patch (.vcv):vcv"; void PatchManager::reset() { + app()->history->clear(); app()->scene->rackWidget->clear(); app()->scene->scrollWidget->offset = math::Vec(0, 0); // Fails silently if file does not exist @@ -122,6 +124,7 @@ void PatchManager::load(std::string path) { json_decref(rootJ); }); + app()->history->clear(); app()->scene->rackWidget->clear(); app()->scene->scrollWidget->offset = math::Vec(0, 0); fromJson(rootJ); @@ -167,7 +170,7 @@ void PatchManager::disconnectDialog() { if (!osdialog_message(OSDIALOG_WARNING, OSDIALOG_OK_CANCEL, "Remove all patch cables?")) return; - app()->scene->rackWidget->clear(); + app()->scene->rackWidget->clearCablesAction(); } json_t *PatchManager::toJson() {