OSDN Git Service

Applied patch [ 672554 ] Update DirView after individual merge
authorChristian List <list1974@hotmail.com>
Mon, 27 Jan 2003 20:12:00 +0000 (20:12 +0000)
committerChristian List <list1974@hotmail.com>
Mon, 27 Jan 2003 20:12:00 +0000 (20:12 +0000)
Fixed [ 225571 ] After individual merge, dirView not updated

Src/DiffContext.cpp
Src/DiffContext.h
Src/DirDoc.cpp
Src/DirDoc.h
Src/DirView.cpp
Src/DirView.h
Src/MainFrm.cpp
Src/MainFrm.h
Src/MergeDoc.cpp
Src/readme.txt

index 0c67787..d25d985 100644 (file)
@@ -148,6 +148,10 @@ BYTE CDiffContext::GetDiffStatus(POSITION diffpos)
        return m_pList->GetAt(diffpos).code;
 }
 
+int CDiffContext::GetDiffCount()
+{
+       return m_pList->GetCount();
+}
 
 void CDiffContext::UpdateStatusCode(POSITION diffpos, BYTE status)
 {
index f1e4a7f..0098066 100644 (file)
@@ -60,6 +60,7 @@ public:
        DIFFITEM GetNextDiffPosition(POSITION & diffpos);
        DIFFITEM GetDiffAt(POSITION diffpos);
        BYTE GetDiffStatus(POSITION diffpos);
+       int GetDiffCount();
 
        // change an existing difference
        void UpdateStatusCode(POSITION diffpos, BYTE status);
index db77954..6239178 100644 (file)
@@ -126,10 +126,10 @@ diff_dirs2 (filevec, handle_file, depth)
      int depth;
 {
   struct dirdata dirdata[2];
-  int val = 0;         
+  int val = 0;
   int i;
 
-  // Get sorted contents of both dirs.  
+  // Get sorted contents of both dirs.
   for (i = 0; i < 2; i++)
     if (dir_sort (&filevec[i], &dirdata[i]) != 0)
       {
@@ -145,7 +145,7 @@ diff_dirs2 (filevec, handle_file, depth)
       char const *name1 = filevec[1].name;
 
       // If `-S name' was given, and this is the topmost level of comparison,
-        //ignore all file names less than the specified starting name. 
+        //ignore all file names less than the specified starting name.
 
       if (dir_start_file && depth == 0)
        {
@@ -155,12 +155,12 @@ diff_dirs2 (filevec, handle_file, depth)
            names1++;
        }
 
-      // Loop while files remain in one or both dirs. 
+      // Loop while files remain in one or both dirs.
       while (*names0 || *names1)
        {
          // Compare next name in dir 0 with next name in dir 1.
             At the end of a dir,
-            pretend the "next name" in that dir is very large.  
+            pretend the "next name" in that dir is very large.
          int nameorder = (!*names0 ? 1 : !*names1 ? -1
                           : stricmp (*names0, *names1));
          int v1 = (*handle_file) (name0, 0 < nameorder ? 0 : *names0++,
@@ -192,9 +192,9 @@ void CDirDoc::Rescan()
                        m_pCtxt->m_strLeft, m_pCtxt->m_strRight);
        m_pCtxt->RemoveAll();
 
-       compare_files (0, (char const *)(LPCTSTR)m_pCtxt->m_strLeft, 
+       compare_files (0, (char const *)(LPCTSTR)m_pCtxt->m_strLeft,
                               0, (char const *)(LPCTSTR)m_pCtxt->m_strRight, m_pCtxt, 0);
-       
+
        if (gWriteLog) gLog.Write(_T("Directory scan complete\r\n"));
 
        CString s;
@@ -224,7 +224,7 @@ void CDirDoc::Redisplay()
                DIFFITEM di = m_pCtxt->GetNextDiffPosition(diffpos);
 
                LPCTSTR p=NULL;
-               
+
                BOOL leftside = (di.code==FILE_LUNIQUE || di.code==FILE_LDIRUNIQUE);
                BOOL rightside = (di.code==FILE_RUNIQUE || di.code==FILE_RDIRUNIQUE);
                switch (di.code)
@@ -281,19 +281,19 @@ void CDirDoc::Redisplay()
                        cnt++;
                }
        }
-       
+
 }
 
 CDirView * CDirDoc::GetMainView()
 {
        POSITION pos = GetFirstViewPosition(), ps2=pos;
-       
+
        while (pos != NULL)
        {
                CDirView* pView = (CDirView*)GetNextView(pos);
                if (pView->IsKindOf( RUNTIME_CLASS(CDirView)))
                        return pView;
-       }   
+       }
        return (CDirView*)GetNextView(ps2);
 }
 
@@ -319,9 +319,10 @@ static void UpdateTimes(DIFFITEM * pdi)
 void CDirDoc::UpdateItemStatus(UINT nIdx)
 {
        CString s,s2;
-       UINT cnt=0;
-       int llen = m_pCtxt->m_strLeft.GetLength();
-       int rlen = m_pCtxt->m_strRight.GetLength();
+//     These are not used currently
+//     UINT cnt=0;
+//     int llen = m_pCtxt->m_strLeft.GetLength();
+//     int rlen = m_pCtxt->m_strRight.GetLength();
        POSITION diffpos = m_pView->GetItemKey(nIdx);
        DIFFITEM di = m_pCtxt->GetDiffAt(diffpos);
        TCHAR sTime[80];
@@ -395,7 +396,7 @@ void CDirDoc::UpdateItemStatus(UINT nIdx)
 
 void CDirDoc::InitStatusStrings()
 {
-       
+
 }
 
 void CDirDoc::UpdateResources()
@@ -416,3 +417,74 @@ void CDirDoc::SetDiffContext(CDiffContext *pCtxt)
 
        m_pCtxt = pCtxt;
 }
+
+BOOL CDirDoc::UpdateItemStatus( LPCTSTR pathLeft, LPCTSTR pathRight,
+                                                          UINT status )
+{
+       TCHAR path1[_MAX_PATH] = {0};
+       TCHAR path2[_MAX_PATH] = {0};
+       TCHAR file1[_MAX_PATH] = {0};
+       TCHAR file2[_MAX_PATH] = {0};
+       TCHAR ext1[_MAX_PATH] = {0};
+       TCHAR ext2[_MAX_PATH] = {0};
+       POSITION pos = m_pCtxt->GetFirstDiffPosition();
+       POSITION currentPos;
+       DIFFITEM current;
+       int count = m_pCtxt->GetDiffCount();
+       int i = 0;
+       BOOL found = FALSE;
+
+       split_filename(pathLeft, path1, file1, ext1);
+       split_filename(pathRight, path2, file2, ext2);
+
+       // Path can contain (because of difftools?) '/' and '\'
+       // so for comparing purposes, convert whole path to use '/'
+       mf->ConvertPathToSlashes(path1);
+       mf->ConvertPathToSlashes(path2);
+
+       // Add extensions back
+       if (ext1 != NULL)
+       {
+               _tcscat(file1, ".");
+               _tcscat(file1, ext1);
+       }
+       if (ext2 != NULL)
+       {
+               _tcscat(file2, ".");
+               _tcscat(file2, ext2);
+       }
+
+       // Filenames must be identical
+       if (_tcsicmp( file1, file2) != 0)
+               return FALSE;
+
+       // Get first item
+       current = m_pCtxt->GetDiffAt(pos);
+
+       while (i < count && found == FALSE)
+       {
+               // Save our current pos before getting next
+               currentPos = pos;
+               current = m_pCtxt->GetNextDiffPosition(pos);
+
+               // Path can contain (because of difftools?) '/' and '\'
+               // so for comparing purposes, convert whole path to use '/'
+               mf->ConvertPathToSlashes(current.rpath);
+               mf->ConvertPathToSlashes(current.lpath);
+
+               if ( (_tcsicmp(current.lpath, path1) == 0) &&
+                       (_tcsicmp(current.rpath, path2) == 0) &&
+                       (_tcsicmp(current.filename, file1) == 0) )
+               {
+                       // Right item found!
+                       // Get index at view, update status to context
+                       // and tell view to update found item
+                       int ind = m_pView->GetItemIndex((DWORD)currentPos);
+                       m_pCtxt->UpdateStatusCode(currentPos, (BYTE)status);
+                       UpdateItemStatus(ind);
+                       found = TRUE;
+               }
+               i++;
+       }
+       return found;
+}
index a12ac11..6055805 100644 (file)
@@ -56,6 +56,7 @@ public:
 
 // Implementation
 public:
+       BOOL UpdateItemStatus( LPCTSTR pathLeft, LPCTSTR pathRight, UINT status );
        void SetDiffContext(CDiffContext *pCtxt);
        void UpdateResources();
        void InitStatusStrings();
index a84040f..97b1f09 100644 (file)
@@ -652,6 +652,16 @@ void CDirView::DeleteAllDisplayItems()
        m_pList->DeleteAllItems();
 }
 
+// given key, get index of item which has it stored
+int CDirView::GetItemIndex(DWORD key)
+{
+       LVFINDINFO findInfo;
+
+       findInfo.flags = LVFI_PARAM;  // Search for itemdata
+       findInfo.lParam = key;
+       return m_pList->FindItem( &findInfo );
+}
+
 // User chose (context menu) open left
 void CDirView::OnCtxtDirOpenLeft()
 {
index d8e048b..dc933e5 100644 (file)
@@ -69,6 +69,7 @@ public:
        POSITION GetItemKey(int idx);
        void SetItemKey(int idx, POSITION diffpos);
        void DeleteAllDisplayItems();
+       int GetItemIndex(DWORD key);
 
 
 // Implementation types
index 4b9133c..6798be2 100644 (file)
@@ -1311,3 +1311,21 @@ void CMainFrame::addToMru(LPCSTR szItem, LPCSTR szRegSubKey, UINT nMaxItems)
        // update count
        AfxGetApp()->WriteProfileInt(szRegSubKey, "Count", cnt);
 }
+
+void CMainFrame::ConvertPathToSlashes(LPTSTR path)
+{
+       TCHAR *ptr = path;
+       TCHAR *ptr2 = NULL;
+
+       do
+       {
+               ptr2 = _tcschr(ptr, '\\');
+               if (ptr2 != NULL)
+               {
+                       *ptr2 = _T('/');
+               }
+               ptr = ptr2;
+       }
+       while (ptr != NULL);
+}
+
index 8b73603..676b392 100644 (file)
@@ -57,6 +57,7 @@ public:
 
 // Operations
 public:
+       void ConvertPathToSlashes( LPTSTR path );
        BOOL DeleteFileOrError(LPCTSTR szFile);
        void rptStatus(BYTE code);
        void clearStatus();
index dfd5c04..6cd02ef 100644 (file)
@@ -28,6 +28,7 @@
 #include "MainFrm.h"
 
 #include "diff.h"
+#include "diffcontext.h"       // FILE_SAME
 #include "getopt.h"
 #include "fnmatch.h"
 #include "coretools.h"
@@ -35,6 +36,7 @@
 #include "MergeEditView.h"
 #include "cs2cs.h"
 #include "childFrm.h"
+#include "dirdoc.h"
 
 #ifdef _DEBUG
 #define new DEBUG_NEW
@@ -1067,17 +1069,31 @@ void CMergeDoc::FlushAndRescan()
 
 void CMergeDoc::OnFileSave() 
 {
+       int lSave = 1;
+       int rSave = 1;
+
        if (m_ltBuf.IsModified())
        {
-               DoSave(m_strLeftFile, TRUE);
+               lSave = DoSave(m_strLeftFile, TRUE);
        }
 
        if (m_rtBuf.IsModified())
        {
-               DoSave(m_strRightFile, FALSE);
+               rSave = DoSave(m_strRightFile, FALSE);
        }
-}
 
+       // IF saving did not fail and files became identical,
+       // update status on dir view
+       if (lSave && rSave)
+       {
+               if (m_nDiffs == 0)
+               {
+                       mf->m_pDirDoc->UpdateItemStatus(m_strLeftFile,
+                                       m_strRightFile, FILE_SAME);
+               }
+       }
+
+}
 void CMergeDoc::OnUpdateStatusNum(CCmdUI* pCmdUI) 
 {
        CString sIdx,sCnt,s;
@@ -1275,6 +1291,14 @@ BOOL CMergeDoc::SaveHelper()
                        break;
                }
        }
+
+       // If files became identical, update status on
+       // dir view
+       if (result && m_nDiffs == 0)
+       {
+               mf->m_pDirDoc->UpdateItemStatus(m_strLeftFile,
+                               m_strRightFile, FILE_SAME);
+       }
        return result;
 }
 
index 7964f09..98e3164 100644 (file)
@@ -1,5 +1,7 @@
 2003-01-27
  [ 668654 ] Tabtype selection feature
+ [ 672554 ] Update DirView after individual merge
+ Fixed [ 225571 ] After individual merge, dirView not updated
 
 2003-01-21
  [ 671037 ] Changes for MSVC.NET