OSDN Git Service

[ 783507 ] normalize replaceSelection and ListCopy
authorLaurent Ganier <laoran@users.sourceforge.net>
Mon, 25 Aug 2003 09:18:37 +0000 (09:18 +0000)
committerLaurent Ganier <laoran@users.sourceforge.net>
Mon, 25 Aug 2003 09:18:37 +0000 (09:18 +0000)
Src/GhostTextBuffer.cpp
Src/GhostTextBuffer.h
Src/MergeDoc.cpp
Src/MergeDoc.h
Src/editlib/ccrystaleditview.cpp
Src/editlib/ccrystaltextbuffer.cpp
Src/editlib/ccrystaltextbuffer.h
Src/readme.txt

index 62aa4e6..ae811b1 100644 (file)
@@ -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)
index 86983df..7bade8e 100644 (file)
@@ -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
index f1a3f85..8ae841e 100644 (file)
@@ -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
index b208c70..af66930 100644 (file)
 #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,
index d16a032..cdc51cc 100644 (file)
@@ -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);
index 8e9bb18..18d7b37 100644 (file)
@@ -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)
index e71d8bd..d03b0c2 100644 (file)
@@ -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 ();
index 4d70169..a1da646 100644 (file)
@@ -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