diff --git a/include/history.hpp b/include/history.hpp index ecfbd5ea..2cfc39ad 100644 --- a/include/history.hpp +++ b/include/history.hpp @@ -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 {}; +struct ModuleRemove : InverseAction { + 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 {}; +struct CableRemove : InverseAction { + CableRemove() { + name = "remove cable"; + } +}; struct State { @@ -130,6 +158,8 @@ struct State { void redo(); bool canUndo(); bool canRedo(); + std::string getUndoName(); + std::string getRedoName(); }; diff --git a/src/app/Knob.cpp b/src/app/Knob.cpp index a0476e15..f4fed595 100644 --- a/src/app/Knob.cpp +++ b/src/app/Knob.cpp @@ -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; diff --git a/src/app/ModuleBrowser.cpp b/src/app/ModuleBrowser.cpp index 80793449..ccc782b8 100644 --- a/src/app/ModuleBrowser.cpp +++ b/src/app/ModuleBrowser.cpp @@ -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); } diff --git a/src/app/ModuleWidget.cpp b/src/app/ModuleWidget.cpp index fc9d4829..6677a0b3 100644 --- a/src/app/ModuleWidget.cpp +++ b/src/app/ModuleWidget.cpp @@ -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 diff --git a/src/app/ParamWidget.cpp b/src/app/ParamWidget.cpp index cde34c6e..b83438e4 100644 --- a/src/app/ParamWidget.cpp +++ b/src/app/ParamWidget.cpp @@ -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; diff --git a/src/app/RackWidget.cpp b/src/app/RackWidget.cpp index 3986c150..1347dd16 100644 --- a/src/app/RackWidget.cpp +++ b/src/app/RackWidget.cpp @@ -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(w); diff --git a/src/app/Switch.cpp b/src/app/Switch.cpp index e33812e4..86689fd4 100644 --- a/src/app/Switch.cpp +++ b/src/app/Switch.cpp @@ -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; diff --git a/src/app/Toolbar.cpp b/src/app/Toolbar.cpp index 921b1c90..46c191b6 100644 --- a/src/app/Toolbar.cpp +++ b/src/app/Toolbar.cpp @@ -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(); } diff --git a/src/history.cpp b/src/history.cpp index 910b3de7..2cb7ffad 100644 --- a/src/history.cpp +++ b/src/history.cpp @@ -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