From ea12df5f2fedc574c3254353830bf3f8b9e43090 Mon Sep 17 00:00:00 2001 From: Laurent Ganier Date: Mon, 25 Aug 2003 09:18:37 +0000 Subject: [PATCH] [ 783507 ] normalize replaceSelection and ListCopy --- Src/GhostTextBuffer.cpp | 20 ++++++++++---------- Src/GhostTextBuffer.h | 4 ++-- Src/MergeDoc.cpp | 22 +++++++++++----------- Src/MergeDoc.h | 13 +++++++++++-- Src/editlib/ccrystaleditview.cpp | 12 ++++++++---- Src/editlib/ccrystaltextbuffer.cpp | 12 ++++++------ Src/editlib/ccrystaltextbuffer.h | 4 ++-- Src/readme.txt | 5 +++++ 8 files changed, 55 insertions(+), 37 deletions(-) diff --git a/Src/GhostTextBuffer.cpp b/Src/GhostTextBuffer.cpp index 62aa4e641..ae811b1d8 100644 --- a/Src/GhostTextBuffer.cpp +++ b/Src/GhostTextBuffer.cpp @@ -245,7 +245,7 @@ Undo (CCrystalTextView * pSource, CPoint & ptCursorPos) { VERIFY (CCrystalTextBuffer::DeleteText (pSource, apparent_ptStartPos.y, apparent_ptStartPos.x, apparent_ptEndPos.y, apparent_ptEndPos.x, - 0, TRUE, FALSE)); + 0, FALSE)); ptCursorPos = apparent_ptStartPos; } else @@ -284,7 +284,7 @@ Undo (CCrystalTextView * pSource, CPoint & ptCursorPos) int nEndLine, nEndChar; VERIFY(CCrystalTextBuffer::InsertText (pSource, apparent_ptStartPos.y, apparent_ptStartPos.x, ur.GetText (), nEndLine, nEndChar, - 0, TRUE, FALSE)); + 0, FALSE)); ptCursorPos = m_ptLastChange; // for the flags, the logic is nearly the same as in insertText @@ -401,7 +401,7 @@ Redo (CCrystalTextView * pSource, CPoint & ptCursorPos) { int nEndLine, nEndChar; VERIFY(InsertText (pSource, apparent_ptStartPos.y, apparent_ptStartPos.x, - ur.GetText(), nEndLine, nEndChar, 0, TRUE, FALSE)); + ur.GetText(), nEndLine, nEndChar, 0, FALSE)); ptCursorPos = m_ptLastChange; } else @@ -412,7 +412,7 @@ Redo (CCrystalTextView * pSource, CPoint & ptCursorPos) ASSERT (lstrcmp (text, ur.GetText ()) == 0); #endif VERIFY(DeleteText(pSource, apparent_ptStartPos.y, apparent_ptStartPos.x, - apparent_ptEndPos.y, apparent_ptEndPos.x, 0, TRUE, FALSE)); + apparent_ptEndPos.y, apparent_ptEndPos.x, 0, FALSE)); ptCursorPos = apparent_ptStartPos; } m_nUndoPosition++; @@ -543,7 +543,7 @@ AddUndoRecord (BOOL bInsert, const CPoint & ptStartPos, const CPoint & ptEndPos, BOOL CGhostTextBuffer:: InsertText (CCrystalTextView * pSource, int nLine, int nPos, LPCTSTR pszText, - int &nEndLine, int &nEndChar, int nAction, BOOL bUpdate /*=TRUE*/, BOOL bHistory /*=TRUE*/) + int &nEndLine, int &nEndChar, int nAction, BOOL bHistory /*=TRUE*/) { BOOL bGroupFlag = FALSE; if (bHistory) @@ -555,7 +555,7 @@ InsertText (CCrystalTextView * pSource, int nLine, int nPos, LPCTSTR pszText, } } - if (!CCrystalTextBuffer::InsertText (pSource, nLine, nPos, pszText, nEndLine, nEndChar, nAction, bUpdate, bHistory)) + if (!CCrystalTextBuffer::InsertText (pSource, nLine, nPos, pszText, nEndLine, nEndChar, nAction, bHistory)) return FALSE; // set WinMerge flags @@ -603,7 +603,7 @@ InsertText (CCrystalTextView * pSource, int nLine, int nPos, LPCTSTR pszText, RecomputeRealityMapping(); } - RecomputeEOL (bUpdate? pSource:NULL, nLine, nEndLine); + RecomputeEOL (pSource, nLine, nEndLine); if (bHistory == false) @@ -623,7 +623,7 @@ InsertText (CCrystalTextView * pSource, int nLine, int nPos, LPCTSTR pszText, BOOL CGhostTextBuffer:: DeleteText (CCrystalTextView * pSource, int nStartLine, int nStartChar, - int nEndLine, int nEndChar, int nAction, BOOL bUpdate /*=TRUE*/, BOOL bHistory /*=TRUE*/) + int nEndLine, int nEndChar, int nAction, BOOL bHistory /*=TRUE*/) { BOOL bGroupFlag = FALSE; if (bHistory) @@ -642,7 +642,7 @@ DeleteText (CCrystalTextView * pSource, int nStartLine, int nStartChar, CString sTextToDelete; GetTextWithoutEmptys (nStartLine, nStartChar, nEndLine, nEndChar, sTextToDelete); - if (!CCrystalTextBuffer::DeleteText (pSource, nStartLine, nStartChar, nEndLine, nEndChar, nAction, bUpdate, bHistory)) + if (!CCrystalTextBuffer::DeleteText (pSource, nStartLine, nStartChar, nEndLine, nEndChar, nAction, bHistory)) return FALSE; OnNotifyLineHasBeenEdited(nStartLine); @@ -665,7 +665,7 @@ DeleteText (CCrystalTextView * pSource, int nStartLine, int nStartChar, RecomputeRealityMapping(); } - RecomputeEOL (bUpdate? pSource:NULL, nStartLine, nStartLine); + RecomputeEOL (pSource, nStartLine, nStartLine); if (bHistory == false) diff --git a/Src/GhostTextBuffer.h b/Src/GhostTextBuffer.h index 86983df87..7bade8e9a 100644 --- a/Src/GhostTextBuffer.h +++ b/Src/GhostTextBuffer.h @@ -212,8 +212,8 @@ public : // Text modification functions - virtual BOOL InsertText (CCrystalTextView * pSource, int nLine, int nPos, LPCTSTR pszText, int &nEndLine, int &nEndChar, int nAction = CE_ACTION_UNKNOWN, BOOL bUpdate =TRUE, BOOL bHistory =TRUE); - virtual BOOL DeleteText (CCrystalTextView * pSource, int nStartLine, int nStartPos, int nEndLine, int nEndPos, int nAction = CE_ACTION_UNKNOWN, BOOL bUpdate =TRUE, BOOL bHistory =TRUE); + virtual BOOL InsertText (CCrystalTextView * pSource, int nLine, int nPos, LPCTSTR pszText, int &nEndLine, int &nEndChar, int nAction = CE_ACTION_UNKNOWN, BOOL bHistory =TRUE); + virtual BOOL DeleteText (CCrystalTextView * pSource, int nStartLine, int nStartPos, int nEndLine, int nEndPos, int nAction = CE_ACTION_UNKNOWN, BOOL bHistory =TRUE); BOOL InsertGhostLine (CCrystalTextView * pSource, int nLine); // Undo/Redo diff --git a/Src/MergeDoc.cpp b/Src/MergeDoc.cpp index f1a3f85d2..8ae841eac 100644 --- a/Src/MergeDoc.cpp +++ b/Src/MergeDoc.cpp @@ -536,11 +536,11 @@ void CMergeDoc::ListCopy(bool bSrcLeft) // delete only on destination side since rescan will clear the other side if(cd_blank==0) { - dbuf.DeleteText(curView, cd_blank, 0, cd_dend+1, 0, CE_ACTION_DELETE); + dbuf.DeleteText(curView, cd_blank, 0, cd_dend+1, 0, CE_ACTION_MERGE); } else { - dbuf.DeleteText(curView, cd_blank-1, dbuf.GetLineLength(cd_blank-1), cd_dend, dbuf.GetLineLength(cd_dend), CE_ACTION_DELETE); + dbuf.DeleteText(curView, cd_blank-1, dbuf.GetLineLength(cd_blank-1), cd_dend, dbuf.GetLineLength(cd_dend), CE_ACTION_MERGE); } deleted_lines=cd_dend-cd_blank+1; @@ -557,7 +557,7 @@ void CMergeDoc::ListCopy(bool bSrcLeft) // text exists on left side, so just replace strLine = _T(""); sbuf.GetFullLine(i, strLine); - dbuf.ReplaceFullLine(curView, i, strLine); + dbuf.ReplaceFullLine(curView, i, strLine, CE_ACTION_MERGE); dbuf.FlushUndoGroup(curView); dbuf.BeginUndoGroup(TRUE); } @@ -1146,13 +1146,13 @@ BOOL CMergeDoc::CDiffTextBuffer::SaveToFile (LPCTSTR pszFileName, } /// Replace text of line (no change to eol) -void CMergeDoc::CDiffTextBuffer::ReplaceLine(CCrystalTextView * pSource, int nLine, const CString &strText) +void CMergeDoc::CDiffTextBuffer::ReplaceLine(CCrystalTextView * pSource, int nLine, const CString &strText, int nAction /*=CE_ACTION_UNKNOWN*/) { if (GetLineLength(nLine)>0) - DeleteText(pSource, nLine, 0, nLine, GetLineLength(nLine)); + DeleteText(pSource, nLine, 0, nLine, GetLineLength(nLine), nAction); int endl,endc; if (! strText.IsEmpty()) - InsertText(pSource, nLine, 0, strText, endl,endc); + InsertText(pSource, nLine, 0, strText, endl,endc, nAction); } /// Return pointer to the eol chars of this string, or pointer to empty string if none @@ -1166,7 +1166,7 @@ LPCTSTR getEol(const CString &str) } /// Replace line (removing any eol, and only including one if in strText) -void CMergeDoc::CDiffTextBuffer::ReplaceFullLine(CCrystalTextView * pSource, int nLine, const CString &strText) +void CMergeDoc::CDiffTextBuffer::ReplaceFullLine(CCrystalTextView * pSource, int nLine, const CString &strText, int nAction /*=CE_ACTION_UNKNOWN*/) { if (_tcscmp(GetLineEol(nLine), getEol(strText)) == 0) { @@ -1174,19 +1174,19 @@ void CMergeDoc::CDiffTextBuffer::ReplaceFullLine(CCrystalTextView * pSource, int // we must clean strText from its eol... CString strTextWithoutEol = strText; strTextWithoutEol.Delete(strTextWithoutEol.GetLength() - _tcslen(getEol(strTextWithoutEol)), 2); - ReplaceLine(pSource, nLine, strTextWithoutEol); + ReplaceLine(pSource, nLine, strTextWithoutEol, nAction); return; } - // we may need a last line to delete + // we may need a last line as the DeleteText end is (x=0,y=line+1) if (nLine+1 == GetLineCount()) InsertGhostLine (pSource, GetLineCount()); if (GetFullLineLength(nLine)) - DeleteText(pSource, nLine, 0, nLine+1, 0); + DeleteText(pSource, nLine, 0, nLine+1, 0, nAction); int endl,endc; if (! strText.IsEmpty()) - InsertText(pSource, nLine, 0, strText, endl,endc); + InsertText(pSource, nLine, 0, strText, endl,endc, nAction); } /// Determine path for temporary files and init those files diff --git a/Src/MergeDoc.h b/Src/MergeDoc.h index b208c7053..af6693019 100644 --- a/Src/MergeDoc.h +++ b/Src/MergeDoc.h @@ -37,9 +37,18 @@ #include "afxtempl.h" #include "DiffWrapper.h" + +/** + * @brief additionnal action code for WinMerge (reserve 100 first codes for CrystalEdit) + */enum +{ + CE_ACTION_MERGE = 100, +}; + /** * @brief Return statuses of file rescan */ + enum { RESCAN_OK = 0, @@ -88,8 +97,8 @@ public : virtual void AddUndoRecord (BOOL bInsert, const CPoint & ptStartPos, const CPoint & ptEndPos, LPCTSTR pszText, int flags, int nActionType = CE_ACTION_UNKNOWN); bool curUndoGroup(); - void ReplaceLine(CCrystalTextView * pSource, int nLine, const CString& strText); - void ReplaceFullLine(CCrystalTextView * pSource, int nLine, const CString& strText); + void ReplaceLine(CCrystalTextView * pSource, int nLine, const CString& strText, int nAction =CE_ACTION_UNKNOWN); + void ReplaceFullLine(CCrystalTextView * pSource, int nLine, const CString& strText, int nAction =CE_ACTION_UNKNOWN); BOOL LoadFromFile(LPCTSTR pszFileName, int nCrlfStyle = CRLF_STYLE_AUTOMATIC); BOOL SaveToFile (LPCTSTR pszFileName, BOOL bTempFile, diff --git a/Src/editlib/ccrystaleditview.cpp b/Src/editlib/ccrystaleditview.cpp index d16a032c0..cdc51ccef 100644 --- a/Src/editlib/ccrystaleditview.cpp +++ b/Src/editlib/ccrystaleditview.cpp @@ -1328,6 +1328,8 @@ ReplaceSelection (LPCTSTR pszNewText, DWORD dwFlags) if (!IsSelection ()) return FALSE;*/ + m_pTextBuffer->BeginUndoGroup(); + CPoint ptCursorPos; if (IsSelection ()) { @@ -1340,8 +1342,7 @@ ReplaceSelection (LPCTSTR pszNewText, DWORD dwFlags) SetCursorPos (ptCursorPos); EnsureVisible (ptCursorPos);*/ - // [JRT]: - m_pTextBuffer->DeleteText (this, ptSelStart.y, ptSelStart.x, ptSelEnd.y, ptSelEnd.x, CE_ACTION_REPLACE, FALSE); + m_pTextBuffer->DeleteText (this, ptSelStart.y, ptSelStart.x, ptSelEnd.y, ptSelEnd.x, CE_ACTION_REPLACE); } else ptCursorPos = GetCursorPos (); @@ -1363,16 +1364,19 @@ ReplaceSelection (LPCTSTR pszNewText, DWORD dwFlags) } else text.Empty (); - m_pTextBuffer->InsertText (this, ptCursorPos.y, ptCursorPos.x, text, y, x, CE_ACTION_REPLACE, FALSE); // [JRT+FRD] + m_pTextBuffer->InsertText (this, ptCursorPos.y, ptCursorPos.x, text, y, x, CE_ACTION_REPLACE); // [JRT+FRD] if (lpszNewStr) free(lpszNewStr); } } else { - m_pTextBuffer->InsertText (this, ptCursorPos.y, ptCursorPos.x, pszNewText, y, x, CE_ACTION_REPLACE, FALSE); // [JRT] + m_pTextBuffer->InsertText (this, ptCursorPos.y, ptCursorPos.x, pszNewText, y, x, CE_ACTION_REPLACE); // [JRT] m_nLastReplaceLen = _tcslen (pszNewText); } + + m_pTextBuffer->FlushUndoGroup(this); + CPoint ptEndOfBlock = CPoint (x, y); ASSERT_VALIDTEXTPOS (ptCursorPos); ASSERT_VALIDTEXTPOS (ptEndOfBlock); diff --git a/Src/editlib/ccrystaltextbuffer.cpp b/Src/editlib/ccrystaltextbuffer.cpp index 8e9bb1821..18d7b37ce 100644 --- a/Src/editlib/ccrystaltextbuffer.cpp +++ b/Src/editlib/ccrystaltextbuffer.cpp @@ -1375,7 +1375,7 @@ Redo (CCrystalTextView * pSource, CPoint & ptCursorPos) { int nEndLine, nEndChar; VERIFY(InsertText (pSource, apparent_ptStartPos.y, apparent_ptStartPos.x, - ur.GetText(), nEndLine, nEndChar, 0, TRUE, FALSE)); + ur.GetText(), nEndLine, nEndChar, 0, FALSE)); ptCursorPos = m_ptLastChange; } else @@ -1386,7 +1386,7 @@ Redo (CCrystalTextView * pSource, CPoint & ptCursorPos) ASSERT (lstrcmp (text, ur.GetText ()) == 0); #endif VERIFY(DeleteText(pSource, apparent_ptStartPos.y, apparent_ptStartPos.x, - apparent_ptEndPos.y, apparent_ptEndPos.x, 0, TRUE, FALSE)); + apparent_ptEndPos.y, apparent_ptEndPos.x, 0, FALSE)); ptCursorPos = apparent_ptStartPos; } m_nUndoPosition++; @@ -1506,9 +1506,9 @@ LPCTSTR CCrystalTextBuffer::GetDefaultEol() const BOOL CCrystalTextBuffer:: InsertText (CCrystalTextView * pSource, int nLine, int nPos, LPCTSTR pszText, - int &nEndLine, int &nEndChar, int nAction, BOOL bUpdate /*=TRUE*/, BOOL bHistory /*=TRUE*/) + int &nEndLine, int &nEndChar, int nAction, BOOL bHistory /*=TRUE*/) { - if (!InternalInsertText (bUpdate? pSource:NULL, nLine, nPos, pszText, nEndLine, nEndChar)) + if (!InternalInsertText (pSource, nLine, nPos, pszText, nEndLine, nEndChar)) return FALSE; if (bHistory == false) @@ -1531,12 +1531,12 @@ InsertText (CCrystalTextView * pSource, int nLine, int nPos, LPCTSTR pszText, BOOL CCrystalTextBuffer:: DeleteText (CCrystalTextView * pSource, int nStartLine, int nStartChar, - int nEndLine, int nEndChar, int nAction, BOOL bUpdate /*=TRUE*/, BOOL bHistory /*=TRUE*/) + int nEndLine, int nEndChar, int nAction, BOOL bHistory /*=TRUE*/) { CString sTextToDelete; GetTextWithoutEmptys (nStartLine, nStartChar, nEndLine, nEndChar, sTextToDelete); - if (!InternalDeleteText (bUpdate? pSource:NULL, nStartLine, nStartChar, nEndLine, nEndChar)) + if (!InternalDeleteText (pSource, nStartLine, nStartChar, nEndLine, nEndChar)) return FALSE; if (bHistory == false) diff --git a/Src/editlib/ccrystaltextbuffer.h b/Src/editlib/ccrystaltextbuffer.h index e71d8bdec..d03b0c2d2 100644 --- a/Src/editlib/ccrystaltextbuffer.h +++ b/Src/editlib/ccrystaltextbuffer.h @@ -304,8 +304,8 @@ public : void SetEolSensitivity(BOOL EolSensitive) { m_EolSensitive = EolSensitive; } // Text modification functions - virtual BOOL InsertText (CCrystalTextView * pSource, int nLine, int nPos, LPCTSTR pszText, int &nEndLine, int &nEndChar, int nAction = CE_ACTION_UNKNOWN, BOOL bUpdate =TRUE, BOOL bHistory =TRUE); - virtual BOOL DeleteText (CCrystalTextView * pSource, int nStartLine, int nStartPos, int nEndLine, int nEndPos, int nAction = CE_ACTION_UNKNOWN, BOOL bUpdate =TRUE, BOOL bHistory =TRUE); + virtual BOOL InsertText (CCrystalTextView * pSource, int nLine, int nPos, LPCTSTR pszText, int &nEndLine, int &nEndChar, int nAction = CE_ACTION_UNKNOWN, BOOL bHistory =TRUE); + virtual BOOL DeleteText (CCrystalTextView * pSource, int nStartLine, int nStartPos, int nEndLine, int nEndPos, int nAction = CE_ACTION_UNKNOWN, BOOL bHistory =TRUE); // Undo/Redo BOOL CanUndo (); diff --git a/Src/readme.txt b/Src/readme.txt index 4d7016957..a1da646ce 100644 --- a/Src/readme.txt +++ b/Src/readme.txt @@ -1,4 +1,9 @@ 2003-08-25 Laoran + [ 783507 ] normalize replaceSelection and ListCopy + WinMerge: GhostTextBuffer.cpp GhostTextBuffer.h MergeDoc.cpp MergeDoc.h + editlib : ccrystaleditview.cpp ccrystaltextbuffer.cpp ccrystaltextbuffer.h + +2003-08-25 Laoran [ 794081 ] Error when dropping a column out of WinMerge WinMerge: DirView.cpp -- 2.11.0