Something went wrong. Try again.
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354#include "HistoryManager.h"
void HistoryManager::Clear() { for (int i = 0; i < (int)history.size(); i++) { delete history[i].release(); } history.clear(); cursor = -1;}
json HistoryManager::GetEvents() { json events = json::array(); for (int i = 0; i <= cursor; i++) { json event = history[i]->Serialize(); events.push_back(event); } return events;}
void HistoryManager::Execute(std::unique_ptr<Command> command) { if (history.size() && cursor < (int)history.size() - 1) { for (int i = cursor + 1; i < (int)history.size(); i++) { delete history[i].release(); } history.erase(history.begin() + cursor + 1, history.end()); } command->Execute(); history.push_back(std::move(command)); cursor++;}
void HistoryManager::Undo() { if (CanUndo()) { //NotifyAppLayer::SetMessage("Undo: " + history[cursor]->GetTitle()); history[cursor]->Undo(); cursor--; }}
void HistoryManager::Redo() { if (CanRedo()) { cursor++; //NotifyAppLayer::SetMessage("Redo: " + history[cursor]->GetTitle()); history[cursor]->Execute(); }}
bool HistoryManager::CanUndo() { return cursor >= 0;}
bool HistoryManager::CanRedo() { return cursor < (int)history.size() - 1;}