{
m_pMergeDoc->m_strLeftFile = szLeft;
m_pMergeDoc->m_strRightFile = szRight;
+ m_pMergeDoc->m_ltBuf.FreeAll();
+ m_pMergeDoc->m_rtBuf.FreeAll();
+ m_pMergeDoc->m_ltBuf.LoadFromFile(szLeft);
+ m_pMergeDoc->m_rtBuf.LoadFromFile(szRight);
+
if (m_pMergeDoc->Rescan())
{
if (docNull)
ES_AUTOHSCROLL | ES_WANTRETURN
END
+
#ifndef _MAC
/////////////////////////////////////////////////////////////////////////////
//
BUTTON ID_FILE_OPEN
BUTTON ID_FILE_SAVE
SEPARATOR
- BUTTON ID_UNDO
+ BUTTON ID_EDIT_UNDO
SEPARATOR
BUTTON ID_NEXTDIFF
BUTTON ID_PREVDIFF
BOOL CMergeDoc::Rescan()
{
+ // store modified status
BOOL ltMod = m_ltBuf.IsModified();
BOOL rtMod = m_rtBuf.IsModified();
+
+ // remove blank lines and clear winmerge flags
+ int ct;
+ for(ct=m_ltBuf.GetLineCount()-1; ct>=0; --ct)
+ {
+ if(m_ltBuf.GetLineFlags(ct) & LF_RIGHT_ONLY)
+ {
+ m_ltBuf.InternalDeleteText(NULL, ct, 0, ct+1, 0);
+ }
+ m_ltBuf.SetLineFlag(ct, LF_WINMERGE_FLAGS, FALSE, FALSE, FALSE);
+ }
+ for(ct=m_rtBuf.GetLineCount()-1; ct>=0; --ct)
+ {
+ if(m_rtBuf.GetLineFlags(ct) & LF_LEFT_ONLY)
+ {
+ m_rtBuf.InternalDeleteText(NULL, ct, 0, ct+1, 0);
+ }
+ m_rtBuf.SetLineFlag(ct, LF_WINMERGE_FLAGS, FALSE, FALSE, FALSE);
+ }
+
+ // restore modified status
+ m_ltBuf.SetModified(ltMod);
+ m_rtBuf.SetModified(rtMod);
+
+ // output to temp file
+ m_ltBuf.SaveToFile(m_strTempLeftFile, CRLF_STYLE_AUTOMATIC, FALSE);
+ m_rtBuf.SaveToFile(m_strTempRightFile, CRLF_STYLE_AUTOMATIC, FALSE);
+
+ // perform rescan
struct file_data inf[2];
char *free0=NULL,*free1=NULL;
char dir0[MAX_PATH],dir1[MAX_PATH], name0[MAX_PATH], name1[MAX_PATH];
mf->m_pLeft->GoToLine(nResumeTopLine, FALSE);
mf->m_pRight->GoToLine(nResumeTopLine, FALSE);
}
- m_ltBuf.SetModified(ltMod);
- m_rtBuf.SetModified(rtMod);
return bResult;
}
void CMergeDoc::FlushAndRescan()
{
- if (m_ltBuf.IsModified())
- m_ltBuf.SaveToFile(m_strTempLeftFile, CRLF_STYLE_AUTOMATIC, FALSE);
- if (m_rtBuf.IsModified())
- m_rtBuf.SaveToFile(m_strTempRightFile, CRLF_STYLE_AUTOMATIC, FALSE);
-
CMDIFrameWnd* mainWnd = dynamic_cast<CMDIFrameWnd*>(AfxGetMainWnd());
CMDIChildWnd* diffWnd = dynamic_cast<CMDIChildWnd*>(mainWnd->MDIGetActive());
CCrystalEditView* curView = dynamic_cast<CCrystalEditView*>(diffWnd->GetActiveView());
#include "afxtempl.h"
#include "CCrystalTextBuffer.h"
+#include <stack>
#define OP_NONE 0
#define OP_LEFTONLY 1
public :
class CDiffTextBuffer : public CCrystalTextBuffer
{
+friend class CMergeDoc;
private :
CMergeDoc * m_pOwnerDoc;
BOOL m_bIsLeft;
// Implementation
public:
+ std::stack<CMergeEditView*> undoTgt;
void FlushAndRescan();
BOOL TempFilesExist();
void CleanupTempFiles();
ON_COMMAND(ID_EDIT_PASTE, OnEditPaste)
ON_UPDATE_COMMAND_UI(ID_EDIT_PASTE, OnUpdateEditPaste)
ON_COMMAND(ID_EDIT_UNDO, OnEditUndo)
- ON_UPDATE_COMMAND_UI(ID_EDIT_UNDO, OnUpdateEditUndo)
ON_COMMAND(ID_FIRSTDIFF, OnFirstdiff)
ON_UPDATE_COMMAND_UI(ID_FIRSTDIFF, OnUpdateFirstdiff)
ON_COMMAND(ID_LASTDIFF, OnLastdiff)
ON_UPDATE_COMMAND_UI(ID_L2R, OnUpdateL2r)
ON_COMMAND(ID_R2L, OnR2l)
ON_UPDATE_COMMAND_UI(ID_R2L, OnUpdateR2l)
+ ON_UPDATE_COMMAND_UI(ID_EDIT_UNDO, OnUpdateEditUndo)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
// get the text buffer for the current view and initialize it
CMergeDoc::CDiffTextBuffer *pBuf = static_cast<CMergeDoc::CDiffTextBuffer*>(LocateTextBuffer());
- pBuf->FreeAll();
- // load the raw file data into the buffer
- if (!pBuf->LoadFromFile(szFilename))
- {
- return FALSE;
- }
CString blankline(_T(""));
int blanklen=blankline.GetLength();
void CMergeEditView::OnEditUndo()
{
- // TODO: Add your command handler code here
-
+ CMergeDoc* pDoc = GetDocument();
+ CMergeEditView *tgt = pDoc->undoTgt.top();
+ if(tgt==this)
+ {
+ CCrystalEditViewEx::OnEditUndo();
+ pDoc->undoTgt.pop();
+ pDoc->FlushAndRescan();
+ }
+ else
+ {
+ tgt->SendMessage(WM_COMMAND, ID_EDIT_UNDO);
+ }
+
}
-void CMergeEditView::OnUpdateEditUndo(CCmdUI* /*pCmdUI*/)
+void CMergeEditView::OnUpdateEditUndo(CCmdUI* pCmdUI)
{
- // TODO: Add your command update UI handler code here
-
+ pCmdUI->Enable(GetDocument()->undoTgt.empty()==false);
}
void CMergeEditView::OnFirstdiff()
void CMergeEditView::OnEditOperation(int nAction, LPCTSTR pszText)
{
+ // perform original function
CCrystalEditViewEx::OnEditOperation(nAction, pszText);
+
+ // augment with additional operations
+
+ // clear left only or right only flags
+ // editing in 'blank' areas should be considered
+ CPoint ptCursorPos = GetCursorPos ();
+ m_pTextBuffer->SetLineFlag(ptCursorPos.y, LF_WINMERGE_FLAGS, FALSE, FALSE, FALSE);
+
+ // keep document up to date
GetDocument()->FlushAndRescan();
+ GetDocument()->undoTgt.push(this);
}
+
afx_msg void OnEditPaste();
afx_msg void OnUpdateEditPaste(CCmdUI* pCmdUI);
afx_msg void OnEditUndo();
- afx_msg void OnUpdateEditUndo(CCmdUI* pCmdUI);
afx_msg void OnFirstdiff();
afx_msg void OnUpdateFirstdiff(CCmdUI* pCmdUI);
afx_msg void OnLastdiff();
afx_msg void OnUpdateL2r(CCmdUI* pCmdUI);
afx_msg void OnR2l();
afx_msg void OnUpdateR2l(CCmdUI* pCmdUI);
+ afx_msg void OnUpdateEditUndo(CCmdUI* pCmdUI);
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};