Browse Source

Add names to history::Actions.

tags/v1.0.0
Andrew Belt 5 years ago
parent
commit
b40fbf7f0e
9 changed files with 58 additions and 4 deletions
  1. +32
    -2
      include/history.hpp
  2. +1
    -0
      src/app/Knob.cpp
  3. +1
    -0
      src/app/ModuleBrowser.cpp
  4. +7
    -0
      src/app/ModuleWidget.cpp
  5. +1
    -0
      src/app/ParamWidget.cpp
  6. +1
    -0
      src/app/RackWidget.cpp
  7. +1
    -0
      src/app/Switch.cpp
  8. +2
    -2
      src/app/Toolbar.cpp
  9. +12
    -0
      src/history.cpp

+ 32
- 2
include/history.hpp View File

@@ -20,6 +20,8 @@ namespace history {


struct Action {
/** Name of the action, lowercase. Used in the phrase "Undo ..." */
std::string name;
virtual ~Action() {}
virtual void undo() {}
virtual void redo() {}
@@ -60,6 +62,9 @@ struct ModuleAdd : ModuleAction {
plugin::Model *model;
math::Vec pos;
json_t *moduleJ;
ModuleAdd() {
name = "add module";
}
~ModuleAdd();
void setModule(app::ModuleWidget *mw);
void undo() override;
@@ -67,7 +72,11 @@ struct ModuleAdd : ModuleAction {
};


struct ModuleRemove : InverseAction<ModuleAdd> {};
struct ModuleRemove : InverseAction<ModuleAdd> {
ModuleRemove() {
name = "remove module";
}
};


struct ModuleMove : ModuleAction {
@@ -75,6 +84,9 @@ struct ModuleMove : ModuleAction {
math::Vec newPos;
void undo() override;
void redo() override;
ModuleMove() {
name = "move module";
}
};


@@ -82,12 +94,18 @@ struct ModuleBypass : ModuleAction {
bool bypass;
void undo() override;
void redo() override;
ModuleBypass() {
name = "bypass module";
}
};


struct ModuleChange : ModuleAction {
json_t *oldModuleJ;
json_t *newModuleJ;
ModuleChange() {
name = "change module";
}
~ModuleChange();
void undo() override;
void redo() override;
@@ -100,6 +118,9 @@ struct ParamChange : ModuleAction {
float newValue;
void undo() override;
void redo() override;
ParamChange() {
name = "change parameter";
}
};


@@ -113,10 +134,17 @@ struct CableAdd : Action {
void setCable(app::CableWidget *cw);
void undo() override;
void redo() override;
CableAdd() {
name = "add cable";
}
};


struct CableRemove : InverseAction<CableAdd> {};
struct CableRemove : InverseAction<CableAdd> {
CableRemove() {
name = "remove cable";
}
};


struct State {
@@ -130,6 +158,8 @@ struct State {
void redo();
bool canUndo();
bool canRedo();
std::string getUndoName();
std::string getRedoName();
};




+ 1
- 0
src/app/Knob.cpp View File

@@ -47,6 +47,7 @@ void Knob::onDragEnd(const event::DragEnd &e) {
if (oldValue != newValue) {
// Push ParamChange history action
history::ParamChange *h = new history::ParamChange;
h->name = "move knob";
h->moduleId = paramQuantity->module->id;
h->paramId = paramQuantity->paramId;
h->oldValue = oldValue;


+ 1
- 0
src/app/ModuleBrowser.cpp View File

@@ -232,6 +232,7 @@ void ModuleBox::onButton(const event::Button &e) {

// Push ModuleAdd history action
history::ModuleAdd *h = new history::ModuleAdd;
h->name = "create module";
h->setModule(moduleWidget);
APP->history->push(h);
}


+ 7
- 0
src/app/ModuleWidget.cpp View File

@@ -439,6 +439,7 @@ void ModuleWidget::pasteClipboardAction() {

// history::ModuleChange
history::ModuleChange *h = new history::ModuleChange;
h->name = "paste module preset";
h->moduleId = module->id;
h->oldModuleJ = toJson();

@@ -473,6 +474,7 @@ void ModuleWidget::loadAction(std::string filename) {

// history::ModuleChange
history::ModuleChange *h = new history::ModuleChange;
h->name = "load module preset";
h->moduleId = module->id;
h->oldModuleJ = toJson();

@@ -564,6 +566,7 @@ void ModuleWidget::resetAction() {

// history::ModuleChange
history::ModuleChange *h = new history::ModuleChange;
h->name = "reset module";
h->moduleId = module->id;
h->oldModuleJ = toJson();

@@ -578,6 +581,7 @@ void ModuleWidget::randomizeAction() {

// history::ModuleChange
history::ModuleChange *h = new history::ModuleChange;
h->name = "randomize module";
h->moduleId = module->id;
h->oldModuleJ = toJson();

@@ -617,6 +621,7 @@ static void disconnectActions(ModuleWidget *mw, history::ComplexAction *complexA

void ModuleWidget::disconnectAction() {
history::ComplexAction *complexAction = new history::ComplexAction;
complexAction->name = "disconnect cables";
disconnectActions(this, complexAction);
APP->history->push(complexAction);

@@ -635,6 +640,7 @@ void ModuleWidget::cloneAction() {

// history::ModuleAdd
history::ModuleAdd *h = new history::ModuleAdd;
h->name = "clone modules";
h->setModule(clonedModuleWidget);
APP->history->push(h);
}
@@ -651,6 +657,7 @@ void ModuleWidget::bypassAction() {

void ModuleWidget::removeAction() {
history::ComplexAction *complexAction = new history::ComplexAction;
complexAction->name = "remove module";
disconnectActions(this, complexAction);

// history::ModuleRemove


+ 1
- 0
src/app/ParamWidget.cpp View File

@@ -212,6 +212,7 @@ void ParamWidget::resetAction() {
if (oldValue != newValue) {
// Push ParamChange history action
history::ParamChange *h = new history::ParamChange;
h->name = "reset parameter";
h->moduleId = paramQuantity->module->id;
h->paramId = paramQuantity->paramId;
h->oldValue = oldValue;


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

@@ -437,6 +437,7 @@ void RackWidget::clearCables() {
void RackWidget::clearCablesAction() {
// Add CableRemove for every cable to a ComplexAction
history::ComplexAction *complexAction = new history::ComplexAction;
complexAction->name = "clear cables";

for (widget::Widget *w : cableContainer->children) {
CableWidget *cw = dynamic_cast<CableWidget*>(w);


+ 1
- 0
src/app/Switch.cpp View File

@@ -51,6 +51,7 @@ void Switch::onDragStart(const event::DragStart &e) {
if (oldValue != newValue) {
// Push ParamChange history action
history::ParamChange *h = new history::ParamChange;
h->name = "move switch";
h->moduleId = paramQuantity->module->id;
h->paramId = paramQuantity->paramId;
h->oldValue = oldValue;


+ 2
- 2
src/app/Toolbar.cpp View File

@@ -141,7 +141,7 @@ struct FileButton : MenuButton {

struct UndoItem : ui::MenuItem {
UndoItem() {
text = "Undo";
text = "Undo " + APP->history->getUndoName();
rightText = WINDOW_MOD_CTRL_NAME "+Z";
disabled = !APP->history->canUndo();
}
@@ -153,7 +153,7 @@ struct UndoItem : ui::MenuItem {

struct RedoItem : ui::MenuItem {
RedoItem() {
text = "Redo";
text = "Redo " + APP->history->getRedoName();
rightText = WINDOW_MOD_CTRL_NAME "+" WINDOW_MOD_SHIFT_NAME "+Z";
disabled = !APP->history->canRedo();
}


+ 12
- 0
src/history.cpp View File

@@ -206,6 +206,18 @@ bool State::canRedo() {
return actionIndex < (int) actions.size();
}

std::string State::getUndoName() {
if (!canUndo())
return "";
return actions[actionIndex - 1]->name;
}

std::string State::getRedoName() {
if (!canRedo())
return "";
return actions[actionIndex]->name;
}


} // namespace history
} // namespace rack

Loading…
Cancel
Save