Browse Source

Add Undo/Redo menu items. Clean up Toolbar.

tags/v1.0.0
Andrew Belt 5 years ago
parent
commit
f6010e61a3
5 changed files with 81 additions and 14 deletions
  1. +2
    -0
      include/history.hpp
  2. +4
    -5
      src/app/ModuleWidget.cpp
  3. +62
    -5
      src/app/Toolbar.cpp
  4. +10
    -2
      src/history.cpp
  5. +3
    -2
      src/patch.cpp

+ 2
- 0
include/history.hpp View File

@@ -117,6 +117,8 @@ struct State {
void push(Action *action);
void undo();
void redo();
bool canUndo();
bool canRedo();
};




+ 4
- 5
src/app/ModuleWidget.cpp View File

@@ -106,11 +106,10 @@ struct ModuleBypassItem : MenuItem {
ModuleBypassItem() {
text = "Bypass";
}
void step() override {
void setModule(ModuleWidget *moduleWidget) {
this->moduleWidget = moduleWidget;
rightText = WINDOW_MOD_CTRL_NAME "+E";
if (!moduleWidget->module)
return;
if (moduleWidget->module->bypass)
if (moduleWidget->module && moduleWidget->module->bypass)
rightText = CHECKMARK_STRING " " + rightText;
}
void onAction(const event::Action &e) override {
@@ -628,7 +627,7 @@ void ModuleWidget::createContextMenu() {
menu->addChild(saveItem);

ModuleBypassItem *bypassItem = new ModuleBypassItem;
bypassItem->moduleWidget = this;
bypassItem->setModule(this);
menu->addChild(bypassItem);

ModuleDeleteItem *deleteItem = new ModuleDeleteItem;


+ 62
- 5
src/app/Toolbar.cpp View File

@@ -35,7 +35,7 @@ struct MenuButton : Button {
struct NewItem : MenuItem {
NewItem() {
text = "New";
rightText = "(" WINDOW_MOD_CTRL_NAME "+N)";
rightText = WINDOW_MOD_CTRL_NAME "+N";
}
void onAction(const event::Action &e) override {
app()->patch->resetDialog();
@@ -46,7 +46,7 @@ struct NewItem : MenuItem {
struct OpenItem : MenuItem {
OpenItem() {
text = "Open";
rightText = "(" WINDOW_MOD_CTRL_NAME "+O)";
rightText = WINDOW_MOD_CTRL_NAME "+O";
}
void onAction(const event::Action &e) override {
app()->patch->loadDialog();
@@ -57,7 +57,7 @@ struct OpenItem : MenuItem {
struct SaveItem : MenuItem {
SaveItem() {
text = "Save";
rightText = "(" WINDOW_MOD_CTRL_NAME "+S)";
rightText = WINDOW_MOD_CTRL_NAME "+S";
}
void onAction(const event::Action &e) override {
app()->patch->saveDialog();
@@ -68,7 +68,7 @@ struct SaveItem : MenuItem {
struct SaveAsItem : MenuItem {
SaveAsItem() {
text = "Save as";
rightText = "(" WINDOW_MOD_CTRL_NAME "+Shift+S)";
rightText = WINDOW_MOD_CTRL_NAME "+Shift+S";
}
void onAction(const event::Action &e) override {
app()->patch->saveAsDialog();
@@ -109,7 +109,7 @@ struct DisconnectCablesItem : MenuItem {
struct QuitItem : MenuItem {
QuitItem() {
text = "Quit";
rightText = "(" WINDOW_MOD_CTRL_NAME "+Q)";
rightText = WINDOW_MOD_CTRL_NAME "+Q";
}
void onAction(const event::Action &e) override {
app()->window->close();
@@ -138,6 +138,45 @@ struct FileButton : MenuButton {
};


struct UndoItem : MenuItem {
UndoItem() {
text = "Undo";
rightText = WINDOW_MOD_CTRL_NAME "+Z";
disabled = !app()->history->canUndo();
}
void onAction(const event::Action &e) override {
app()->history->undo();
}
};


struct RedoItem : MenuItem {
RedoItem() {
text = "Redo";
rightText = WINDOW_MOD_CTRL_NAME "+" WINDOW_MOD_SHIFT_NAME "+Z";
disabled = !app()->history->canRedo();
}
void onAction(const event::Action &e) override {
app()->history->redo();
}
};


struct EditButton : MenuButton {
EditButton() {
text = "Edit";
}
void onAction(const event::Action &e) override {
Menu *menu = createMenu();
menu->box.pos = getAbsoluteOffset(math::Vec(0, box.size.y));
menu->box.size.x = box.size.x;

menu->addChild(new UndoItem);
menu->addChild(new RedoItem);
}
};


struct ZoomQuantity : Quantity {
void setValue(float value) override {
settings::zoom = math::clamp(value, getMinValue(), getMaxValue());
@@ -260,6 +299,19 @@ struct SampleRateItem : MenuItem {
};


struct FullscreenItem : MenuItem {
FullscreenItem() {
text = "Fullscreen";
rightText = "F11";
if (app()->window->isFullScreen())
rightText = CHECKMARK_STRING " " + rightText;
}
void onAction(const event::Action &e) override {
app()->window->setFullScreen(!app()->window->isFullScreen());
}
};


struct SettingsButton : MenuButton {
SettingsButton() {
text = "Settings";
@@ -273,6 +325,7 @@ struct SettingsButton : MenuButton {
menu->addChild(new PowerMeterItem);
menu->addChild(new LockModulesItem);
menu->addChild(new SampleRateItem);
menu->addChild(new FullscreenItem);

Slider *zoomSlider = new Slider;
zoomSlider->box.size.x = 200.0;
@@ -497,6 +550,7 @@ struct PluginsButton : MenuButton {
struct ManualItem : MenuItem {
ManualItem() {
text = "Manual";
rightText = "F1";
}
void onAction(const event::Action &e) override {
std::thread t([&]() {
@@ -559,6 +613,9 @@ Toolbar::Toolbar() {
FileButton *fileButton = new FileButton;
layout->addChild(fileButton);

EditButton *editButton = new EditButton;
layout->addChild(editButton);

SettingsButton *settingsButton = new SettingsButton;
layout->addChild(settingsButton);



+ 10
- 2
src/history.cpp View File

@@ -166,19 +166,27 @@ void State::push(Action *action) {
}

void State::undo() {
if (actionIndex > 0) {
if (canUndo()) {
actionIndex--;
actions[actionIndex]->undo();
}
}

void State::redo() {
if ((int) actions.size() > actionIndex) {
if (canRedo()) {
actions[actionIndex]->redo();
actionIndex++;
}
}

bool State::canUndo() {
return actionIndex > 0;
}

bool State::canRedo() {
return actionIndex < (int) actions.size();
}


} // namespace history
} // namespace rack

+ 3
- 2
src/patch.cpp View File

@@ -167,8 +167,9 @@ void PatchManager::revertDialog() {
}

void PatchManager::disconnectDialog() {
if (!osdialog_message(OSDIALOG_WARNING, OSDIALOG_OK_CANCEL, "Remove all patch cables?"))
return;
// Since we have undo history, no need for a warning.
// if (!osdialog_message(OSDIALOG_WARNING, OSDIALOG_OK_CANCEL, "Remove all patch cables?"))
// return;

app()->scene->rackWidget->clearCablesAction();
}


Loading…
Cancel
Save