bool pt_PieceTable::undoCmd(void) { // do a user-atomic undo. // return false if we can't. PX_ChangeRecord * pcr; if (!m_history.getUndo(&pcr)) return false; UT_return_val_if_fail (pcr,false); // the first undo record tells us whether it is // a simple change or a glob. there are two kinds // of globs: a multi-step change (display atomic) // like deleting a selection that spans a paragraph // break; and a user-atomic glob like doing a search // and replace over the whole document. // // for a simple change, we just do it and return. // for a glob, we loop until we do the // corresponding other end. m_history.setScanningUndoGLOB(false); UT_Byte flagsFirst = GETGLOBFLAGS(pcr); if(m_fragments.areFragsDirty()) { m_fragments.cleanFrags(); } do { PX_ChangeRecord * pcrRev = pcr->reverse(); // we must delete this. pcrRev->setAdjustment(pcr->getAdjustment()); pcrRev->setDocument(getDocument()); pcrRev->setCRNumber(); UT_return_val_if_fail (pcrRev,false); UT_Byte flagsRev = GETGLOBFLAGS(pcrRev); bool bResult = _doTheDo(pcrRev, true); delete pcrRev; if (!bResult) return false; if (flagsRev == flagsFirst) // stop when we have a matching end break; } while (m_history.getUndo(&pcr)); m_history.setScanningUndoGLOB(false); m_pDocument->updateFields(); return true; }
bool pt_PieceTable::redoCmd(void) { // do a user-atomic redo. // return false if we can't. m_history.setScanningUndoGLOB(false); PX_ChangeRecord * pcr; if (!m_history.getRedo(&pcr)) return false; UT_return_val_if_fail (pcr,false); // the first undo record tells us whether it is // a simple change or a glob. there are two kinds // of globs: a multi-step change (display atomic) // like deleting a selection that spans a paragraph // break; and a user-atomic glob like doing a search // and replace over the whole document. // // for a simple change, we just do it and return. // for a glob, we loop until we do the // corresponding other end. UT_Byte flagsRevFirst = GETREVGLOBFLAGS(pcr); if(m_fragments.areFragsDirty()) { m_fragments.cleanFrags(); } while (m_history.getRedo(&pcr)) { pcr->setCRNumber(); // update the CRNumber if (!_doTheDo(pcr, false)) return false; if (flagsRevFirst == GETGLOBFLAGS(pcr)) // stop when we have a matching end break; } m_history.setScanningUndoGLOB(false); return true; }