Browse Source

Add Undo/Redo menu items. Clean up Toolbar.

tags/v1.0.0
Andrew Belt 6 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 push(Action *action);
void undo(); void undo();
void redo(); void redo();
bool canUndo();
bool canRedo();
}; };






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

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


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


ModuleDeleteItem *deleteItem = new ModuleDeleteItem; ModuleDeleteItem *deleteItem = new ModuleDeleteItem;


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

@@ -35,7 +35,7 @@ struct MenuButton : Button {
struct NewItem : MenuItem { struct NewItem : MenuItem {
NewItem() { NewItem() {
text = "New"; text = "New";
rightText = "(" WINDOW_MOD_CTRL_NAME "+N)";
rightText = WINDOW_MOD_CTRL_NAME "+N";
} }
void onAction(const event::Action &e) override { void onAction(const event::Action &e) override {
app()->patch->resetDialog(); app()->patch->resetDialog();
@@ -46,7 +46,7 @@ struct NewItem : MenuItem {
struct OpenItem : MenuItem { struct OpenItem : MenuItem {
OpenItem() { OpenItem() {
text = "Open"; text = "Open";
rightText = "(" WINDOW_MOD_CTRL_NAME "+O)";
rightText = WINDOW_MOD_CTRL_NAME "+O";
} }
void onAction(const event::Action &e) override { void onAction(const event::Action &e) override {
app()->patch->loadDialog(); app()->patch->loadDialog();
@@ -57,7 +57,7 @@ struct OpenItem : MenuItem {
struct SaveItem : MenuItem { struct SaveItem : MenuItem {
SaveItem() { SaveItem() {
text = "Save"; text = "Save";
rightText = "(" WINDOW_MOD_CTRL_NAME "+S)";
rightText = WINDOW_MOD_CTRL_NAME "+S";
} }
void onAction(const event::Action &e) override { void onAction(const event::Action &e) override {
app()->patch->saveDialog(); app()->patch->saveDialog();
@@ -68,7 +68,7 @@ struct SaveItem : MenuItem {
struct SaveAsItem : MenuItem { struct SaveAsItem : MenuItem {
SaveAsItem() { SaveAsItem() {
text = "Save as"; text = "Save as";
rightText = "(" WINDOW_MOD_CTRL_NAME "+Shift+S)";
rightText = WINDOW_MOD_CTRL_NAME "+Shift+S";
} }
void onAction(const event::Action &e) override { void onAction(const event::Action &e) override {
app()->patch->saveAsDialog(); app()->patch->saveAsDialog();
@@ -109,7 +109,7 @@ struct DisconnectCablesItem : MenuItem {
struct QuitItem : MenuItem { struct QuitItem : MenuItem {
QuitItem() { QuitItem() {
text = "Quit"; text = "Quit";
rightText = "(" WINDOW_MOD_CTRL_NAME "+Q)";
rightText = WINDOW_MOD_CTRL_NAME "+Q";
} }
void onAction(const event::Action &e) override { void onAction(const event::Action &e) override {
app()->window->close(); 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 { struct ZoomQuantity : Quantity {
void setValue(float value) override { void setValue(float value) override {
settings::zoom = math::clamp(value, getMinValue(), getMaxValue()); 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 { struct SettingsButton : MenuButton {
SettingsButton() { SettingsButton() {
text = "Settings"; text = "Settings";
@@ -273,6 +325,7 @@ struct SettingsButton : MenuButton {
menu->addChild(new PowerMeterItem); menu->addChild(new PowerMeterItem);
menu->addChild(new LockModulesItem); menu->addChild(new LockModulesItem);
menu->addChild(new SampleRateItem); menu->addChild(new SampleRateItem);
menu->addChild(new FullscreenItem);


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


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

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




+ 10
- 2
src/history.cpp View File

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


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


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


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

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



} // namespace history } // namespace history
} // namespace rack } // namespace rack

+ 3
- 2
src/patch.cpp View File

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


void PatchManager::disconnectDialog() { 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(); app()->scene->rackWidget->clearCablesAction();
} }


Loading…
Cancel
Save