bool UndoStack::redo(uint steps, int objectId) { for (uint i = 0; i < steps && !redoActions_.empty(); ++i) { UndoState *tmpRedoState = 0; if (objectId == Um::GLOBAL_UNDO_MODE) { tmpRedoState = redoActions_[0]; redoActions_.erase(redoActions_.begin()); } else { // object specific mode (search the correct state) StateList::iterator it; for (it = redoActions_.begin(); it != redoActions_.end(); ++it) { UndoObject *tmp = (*it)->undoObject(); if (tmp && tmp->getUId() == static_cast<ulong>(objectId)) { tmpRedoState = *it; redoActions_.erase(it); break; } } } undoActions_.insert(undoActions_.begin(), tmpRedoState); // push to the undo actions tmpRedoState->redo(); } return true; }
bool UndoStack::undo(uint steps, int objectId) { for (uint i = 0; i < steps && !undoActions_.empty(); ++i) { UndoState *tmpUndoState = 0; if (objectId == Um::GLOBAL_UNDO_MODE) { tmpUndoState = undoActions_[0]; undoActions_.erase(undoActions_.begin()); } else { // object specific mode (search the correct state) StateList::iterator it; for (it = undoActions_.begin(); it != undoActions_.end(); ++it) { UndoObject *tmp = (*it)->undoObject(); if (tmp && tmp->getUId() == static_cast<ulong>(objectId)) { tmpUndoState = *it; undoActions_.erase(it); break; } else if((*it)->isTransaction()) { TransactionState *ts = dynamic_cast<TransactionState*>(*it); if(ts->containsOnly(objectId)) { tmpUndoState = *it; undoActions_.erase(it); break; } } } } redoActions_.insert(redoActions_.begin(), tmpUndoState); // push to the redo actions tmpUndoState->undo(); } return true; }
void UndoManager::setState(UndoGui* gui, int uid) { gui->clear(); if ( stacks_[currentDoc_].size() == 0 ) return; UndoStack& currentStack = stacks_[currentDoc_]; StateList::iterator itstartU = currentStack.undoActions_.begin(); // undo actions StateList::iterator itendU = currentStack.undoActions_.end(); StateList::iterator itstartR = currentStack.redoActions_.begin(); // redo actions StateList::iterator itendR = currentStack.redoActions_.end(); if (uid > -1) { // find the range from where actions are added when in obj. spec. mode StateList::iterator it2; for (it2 = currentStack.undoActions_.begin(); it2 != currentStack.undoActions_.end(); ++it2) { UndoState* tmp = *it2; TransactionState *ts = dynamic_cast<TransactionState*>(tmp); if (ts && !ts->containsOnly(uid)) { if (it2 != currentStack.undoActions_.begin()) itendU = --it2; break; } } StateList::iterator it3; for (it3 = currentStack.redoActions_.begin(); it3 != currentStack.redoActions_.end(); ++it3) { UndoState* tmp = *it3; TransactionState *ts = dynamic_cast<TransactionState*>(tmp); if (ts && !ts->containsOnly(uid)) { itendR = it3; break; } } } if (currentStack.undoItems() > 0) { if (itendU == currentStack.undoActions_.end()) --itendU; for (; itendU >= itstartU; --itendU) // insert undo actions { UndoState* state = *itendU; UndoObject* target = state->undoObject(); if (target && (uid == -1 || target->getUId() == static_cast<uint>(uid))) gui->insertUndoItem(target, state); if (itendU == itstartU) break; } } if (currentStack.redoItems() > 0) { if (itendR > itstartR) --itendR; for (; itstartR <= itendR; ++itstartR) // insert redo actions { UndoState* state = *itstartR; UndoObject* target = state->undoObject(); if (target && (uid == -1 || target->getUId() == static_cast<uint>(uid))) gui->insertRedoItem(target, state); if (itendR == itstartR) break; } } }