Browse Source

Add RackWidget::clearCablesAction

tags/v1.0.0
Andrew Belt 6 years ago
parent
commit
5659faba2e
3 changed files with 25 additions and 1 deletions
  1. +1
    -0
      include/app/RackWidget.hpp
  2. +20
    -0
      src/app/RackWidget.cpp
  3. +4
    -1
      src/patch.cpp

+ 1
- 0
include/app/RackWidget.hpp View File

@@ -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.


+ 20
- 0
src/app/RackWidget.cpp View File

@@ -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<CableWidget*>(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<Widget*> childrenCopy = cableContainer->children;


+ 4
- 1
src/patch.cpp View File

@@ -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() {


Loading…
Cancel
Save