#include "afxtempl.h"
#include "CCrystalTextBuffer.h"
-#include <stack>
+#include <vector>
#define OP_NONE 0
#define OP_LEFTONLY 1
CMergeDoc * m_pOwnerDoc;
BOOL m_bIsLeft;
public :
+ bool lastUndoGroup();
void DeleteLine(int nLine);
void ReplaceLine(int nLine, const CString& strText);
BOOL SaveToFile (LPCTSTR pszFileName,
// Implementation
public:
- std::stack<CMergeEditView*> undoTgt;
+ std::vector<CMergeEditView*> undoTgt;
+ std::vector<CMergeEditView*>::iterator curUndo;
void FlushAndRescan();
BOOL TempFilesExist();
void CleanupTempFiles();
ON_COMMAND(ID_R2L, OnR2l)
ON_UPDATE_COMMAND_UI(ID_R2L, OnUpdateR2l)
ON_UPDATE_COMMAND_UI(ID_EDIT_UNDO, OnUpdateEditUndo)
+ ON_COMMAND(ID_EDIT_REDO, OnEditRedo)
+ ON_UPDATE_COMMAND_UI(ID_EDIT_REDO, OnUpdateEditRedo)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
void CMergeEditView::OnEditUndo()
{
CMergeDoc* pDoc = GetDocument();
- CMergeEditView *tgt = pDoc->undoTgt.top();
+ CMergeEditView *tgt = *(pDoc->curUndo-1);
if(tgt==this)
{
CCrystalEditViewEx::OnEditUndo();
- pDoc->undoTgt.pop();
+ --pDoc->curUndo;
pDoc->FlushAndRescan();
}
else
void CMergeEditView::OnUpdateEditUndo(CCmdUI* pCmdUI)
{
- pCmdUI->Enable(GetDocument()->undoTgt.empty()==false);
+ CMergeDoc* pDoc = GetDocument();
+ pCmdUI->Enable(pDoc->curUndo!=pDoc->undoTgt.begin());
}
void CMergeEditView::OnFirstdiff()
void CMergeEditView::OnEditOperation(int nAction, LPCTSTR pszText)
{
+ CMergeDoc* pDoc = GetDocument();
+
+ // simple hook for multiplex undo operations
+ if(dynamic_cast<CMergeDoc::CDiffTextBuffer*>(m_pTextBuffer)->lastUndoGroup())
+ {
+ pDoc->undoTgt.erase(pDoc->curUndo, pDoc->undoTgt.end());
+ pDoc->undoTgt.push_back(this);
+ pDoc->curUndo = pDoc->undoTgt.end();
+ }
+
// perform original function
CCrystalEditViewEx::OnEditOperation(nAction, pszText);
m_pTextBuffer->SetLineFlag(ptCursorPos.y, LF_WINMERGE_FLAGS, FALSE, FALSE, FALSE);
// keep document up to date
- GetDocument()->FlushAndRescan();
- GetDocument()->undoTgt.push(this);
+ pDoc->FlushAndRescan();
+}
+
+
+void CMergeEditView::OnEditRedo()
+{
+ CMergeDoc* pDoc = GetDocument();
+ CMergeEditView *tgt = *(pDoc->curUndo);
+ if(tgt==this)
+ {
+ CCrystalEditViewEx::OnEditRedo();
+ ++pDoc->curUndo;
+ pDoc->FlushAndRescan();
+ }
+ else
+ {
+ tgt->SendMessage(WM_COMMAND, ID_EDIT_REDO);
+ }
}
+void CMergeEditView::OnUpdateEditRedo(CCmdUI* pCmdUI)
+{
+ CMergeDoc* pDoc = GetDocument();
+ pCmdUI->Enable(pDoc->curUndo!=pDoc->undoTgt.end());
+}