OSDN Git Service

PATCH: [ 1154667 ] Make CDiffContext paths private members
authorKimmo Varis <kimmov@gmail.com>
Thu, 3 Mar 2005 18:22:47 +0000 (18:22 +0000)
committerKimmo Varis <kimmov@gmail.com>
Thu, 3 Mar 2005 18:22:47 +0000 (18:22 +0000)
Src/DiffContext.cpp
Src/DiffContext.h
Src/DirActions.cpp
Src/DirDoc.cpp
Src/DirScan.cpp
Src/DirView.cpp
Src/readme.txt

index 27a7a6c..4656336 100644 (file)
@@ -48,6 +48,12 @@ static char THIS_FILE[]=__FILE__;
 // Construction/Destruction
 //////////////////////////////////////////////////////////////////////
 
+/**
+ * @brief Construct CDiffContext.
+ *
+ * @param [in] pszLeft Initial left-side path.
+ * @param [in] pszRight Initial right-side path.
+ */
 CDiffContext::CDiffContext(LPCTSTR pszLeft /*=NULL*/, LPCTSTR pszRight /*=NULL*/)
 {
        m_bRecurse=FALSE;
@@ -61,8 +67,20 @@ CDiffContext::CDiffContext(LPCTSTR pszLeft /*=NULL*/, LPCTSTR pszRight /*=NULL*/
        m_piPluginInfos = 0;
        m_msgUpdateStatus = 0;
        m_hDirFrame = NULL;
+
+       m_strNormalizedLeft = pszLeft;
+       paths_normalize(m_strNormalizedLeft);
+       m_strNormalizedRight = pszRight;
+       paths_normalize(m_strNormalizedRight);
 }
 
+/**
+ * @brief Construct copy of existing CDiffContext.
+ *
+ * @param [in] pszLeft Initial left-side path.
+ * @param [in] pszRight Initial right-side path.
+ * @param [in] src Existing CDiffContext whose data is copied.
+ */
 CDiffContext::CDiffContext(LPCTSTR pszLeft, LPCTSTR pszRight, CDiffContext& src)
 {
        // This is used somehow in recursive comparisons
@@ -81,6 +99,11 @@ CDiffContext::CDiffContext(LPCTSTR pszLeft, LPCTSTR pszRight, CDiffContext& src)
 
        pNamesLeft = NULL;
        pNamesRight = NULL;
+
+       m_strNormalizedLeft = pszLeft;
+       paths_normalize(m_strNormalizedLeft);
+       m_strNormalizedRight = pszRight;
+       paths_normalize(m_strNormalizedRight);
 }
 
 CDiffContext::~CDiffContext()
@@ -101,7 +124,6 @@ static CString GetFixedFileVersion(const CString & path)
        return ver.GetFixedFileVersion();
 }
 
-
 /**
  * @brief Add new diffitem to CDiffContext array
  */
@@ -295,7 +317,7 @@ CString DIFFITEM::getLeftFilepath(const CDiffContext *pCtxt) const
        CString sPath;
        if (!isSideRight())
        {
-               sPath = pCtxt->m_strNormalizedLeft;
+               sPath = pCtxt->GetNormalizedLeft();
                if (sSubdir.GetLength())
                {
             sPath = paths_ConcatPath(sPath, sSubdir);
@@ -310,7 +332,7 @@ CString DIFFITEM::getRightFilepath(const CDiffContext *pCtxt) const
        CString sPath;
        if (!isSideLeft())
        {
-               sPath = pCtxt->m_strNormalizedRight;
+               sPath = pCtxt->GetNormalizedRight();
                if (sSubdir.GetLength())
                {
             sPath = paths_ConcatPath(sPath, sSubdir);
index 600b8a7..b2f87b0 100644 (file)
@@ -123,6 +123,21 @@ public:
        void RemoveAll();
        void UpdateVersion(DIFFITEM & di, DiffFileInfo & dfi) const;
 
+       //@{
+       /**
+        * @name Path accessor functions.
+        *
+        * These functions return left/right path associated to DiffContext.
+        * There is no setter fuctions and path can be set only via constructor.
+        * Normalized paths are preferred to use - short paths are expanded
+        * and trailing slashes removed (except from root path).
+        */
+       const CString & GetLeftPath() const { return m_strLeft; }
+       const CString & GetRightPath() const { return m_strRight; }
+       const CString & GetNormalizedLeft() const { return m_strNormalizedLeft; }
+       const CString & GetNormalizedRight() const { return m_strNormalizedRight; }
+       //@}
+
        // to iterate over all differences on list
        POSITION GetFirstDiffPosition();
        DIFFITEM GetNextDiffPosition(POSITION & diffpos);
@@ -141,10 +156,6 @@ public:
        void FetchPluginInfos(const CString& filteredFilenames, PackingInfo ** infoUnpacker, PrediffingInfo ** infoPrediffer);
 
        BOOL m_bRecurse;
-       CString m_strLeft;
-       CString m_strRight;
-       CString m_strNormalizedLeft;
-       CString m_strNormalizedRight;
        IDiffFilter * m_piFilterGlobal;
        IPluginInfos * m_piPluginInfos;
        UINT m_msgUpdateStatus;
@@ -157,6 +168,11 @@ public:
 
 private:
        CList<DIFFITEM,DIFFITEM> m_dirlist, *m_pList; // master list of differences
+
+       CString m_strLeft;
+       CString m_strRight;
+       CString m_strNormalizedLeft;
+       CString m_strNormalizedRight;
 };
 
 #endif // !defined(AFX_DIFFCONTEXT_H__D3CC86BE_F11E_11D2_826C_00A024706EDC__INCLUDED_)
index a94e794..1f79566 100644 (file)
@@ -927,9 +927,11 @@ void CDirView::GetItemFileNames(int sel, CString& strLeft, CString& strRight) co
        {
                const CDiffContext * ctxt = GetDiffContext();
                const DIFFITEM & di = ctxt->GetDiffAt(diffpos);
-               CString relpath = paths_ConcatPath(di.sSubdir, di.sfilename);
-               strLeft = paths_ConcatPath(ctxt->m_strLeft, relpath);
-               strRight = paths_ConcatPath(ctxt->m_strRight, relpath);
+               const CString relpath = paths_ConcatPath(di.sSubdir, di.sfilename);
+               const CString & leftpath = ctxt->GetLeftPath();
+               const CString & rightpath = ctxt->GetRightPath();
+               strLeft = paths_ConcatPath(leftpath, relpath);
+               strRight = paths_ConcatPath(rightpath, relpath);
        }
 }
 
index 3111896..64bd64b 100644 (file)
@@ -181,19 +181,14 @@ void CDirDoc::Rescan()
        m_statusCursor = new CustomStatusCursor(0, IDC_APPSTARTING, LoadResString(IDS_STATUS_RESCANNING));
 
        gLog.Write(LOGLEVEL::LNOTICE, _T("Starting directory scan:\n\tLeft: %s\n\tRight: %s\n"),
-                       m_pCtxt->m_strLeft, m_pCtxt->m_strRight);
+                       m_pCtxt->GetLeftPath(), m_pCtxt->GetRightPath());
        pf->clearStatus();
        pf->ShowProcessingBar(TRUE);
        m_pCtxt->RemoveAll();
 
-       // fix up for diff code (remove trailing slashes etc)
-       m_pCtxt->m_strNormalizedLeft = m_pCtxt->m_strLeft;
-       m_pCtxt->m_strNormalizedRight = m_pCtxt->m_strRight;
        m_pCtxt->m_hDirFrame = pf->GetSafeHwnd();
        m_pCtxt->m_msgUpdateStatus = MSG_STAT_UPDATE;
        m_pCtxt->m_bGuessEncoding = mf->m_options.GetBool(OPT_CP_DETECT);
-       paths_normalize(m_pCtxt->m_strNormalizedLeft);
-       paths_normalize(m_pCtxt->m_strNormalizedRight);
        UpdateHeaderPath(TRUE);
        UpdateHeaderPath(FALSE);
        // draw the headers as active ones
@@ -215,8 +210,8 @@ void CDirDoc::Rescan()
        m_diffThread.SetContext(m_pCtxt);
        m_diffThread.SetHwnd(m_pDirView->GetSafeHwnd());
        m_diffThread.SetMessageIDs(MSG_UI_UPDATE, MSG_STAT_UPDATE);
-       m_diffThread.CompareDirectories(m_pCtxt->m_strNormalizedLeft,
-                       m_pCtxt->m_strNormalizedRight, m_bRecursive);
+       m_diffThread.CompareDirectories(m_pCtxt->GetNormalizedLeft(),
+                       m_pCtxt->GetNormalizedRight(), m_bRecursive);
 }
 
 /**
@@ -297,8 +292,8 @@ void CDirDoc::Redisplay()
 
        CString s,s2;
        UINT cnt=0;
-       int llen = m_pCtxt->m_strNormalizedLeft.GetLength();
-       int rlen = m_pCtxt->m_strNormalizedRight.GetLength();
+       int llen = m_pCtxt->GetNormalizedLeft().GetLength();
+       int rlen = m_pCtxt->GetNormalizedRight().GetLength();
 
        m_pDirView->DeleteAllDisplayItems();
 
@@ -712,7 +707,7 @@ void CDirDoc::UpdateHeaderPath(BOOL bLeft)
                if (!m_strLeftDesc.IsEmpty())
                        sText = m_strLeftDesc;
                else
-                       sText = m_pCtxt->m_strLeft;
+                       sText = m_pCtxt->GetLeftPath();
                nPane = 0;
        }
        else
@@ -720,7 +715,7 @@ void CDirDoc::UpdateHeaderPath(BOOL bLeft)
                if (!m_strRightDesc.IsEmpty())
                        sText = m_strRightDesc;
                else
-                       sText = m_pCtxt->m_strRight;
+                       sText = m_pCtxt->GetRightPath();
                nPane = 1;
        }
 
@@ -809,8 +804,8 @@ void CDirDoc::SetTitle(LPCTSTR lpszTitle)
 
        if (lpszTitle)
                CDocument::SetTitle(lpszTitle);
-       else if (!m_pCtxt || m_pCtxt->m_strLeft.IsEmpty() ||
-               m_pCtxt->m_strRight.IsEmpty())
+       else if (!m_pCtxt || m_pCtxt->GetLeftPath().IsEmpty() ||
+               m_pCtxt->GetRightPath().IsEmpty())
        {
                CString title;
                VERIFY(title.LoadString(IDS_DIRECTORY_WINDOW_TITLE));
@@ -834,24 +829,24 @@ void CDirDoc::SetTitle(LPCTSTR lpszTitle)
                        m_pDirView->GetClientRect(&rcClient);
                        const DWORD width = rcClient.right / 3;
 
-                       sLeftFile = m_pCtxt->m_strLeft;
+                       sLeftFile = m_pCtxt->GetLeftPath();
                        pszLeftFile = sLeftFile.GetBuffer(MAX_PATH);
 
                        if (PathCompactPath(lDC.GetSafeHdc(), pszLeftFile, width))
                                strTitle = pszLeftFile;
                        else
-                               strTitle = m_pCtxt->m_strLeft;
+                               strTitle = m_pCtxt->GetLeftPath();
 
                        sLeftFile.ReleaseBuffer();
                        strTitle += strSeparator;
 
-                       sRightFile = m_pCtxt->m_strRight;
+                       sRightFile = m_pCtxt->GetRightPath();
                        pszRightFile = sRightFile.GetBuffer(MAX_PATH);
 
                        if (PathCompactPath(lDC.GetSafeHdc(), pszRightFile, width))
                                strTitle += pszRightFile;
                        else
-                               strTitle += m_pCtxt->m_strRight;
+                               strTitle += m_pCtxt->GetRightPath();
                        sRightFile.ReleaseBuffer();
 
                        CDocument::SetTitle(strTitle);
index 4be0837..a7bdb7f 100644 (file)
@@ -69,8 +69,8 @@ int DirScan(const CString & subdir, CDiffContext * pCtxt, bool casesensitive,
 {
        //int (WINAPI *collstr)(LPCTSTR, LPCTSTR) = casesensitive ? lstrcmp : lstrcmpi;
        static const TCHAR backslash[] = _T("\\");
-       CString sLeftDir = pCtxt->m_strNormalizedLeft;
-       CString sRightDir = pCtxt->m_strNormalizedRight;
+       CString sLeftDir = pCtxt->GetNormalizedLeft();
+       CString sRightDir = pCtxt->GetNormalizedRight();
        CString subprefix;
        if (!subdir.IsEmpty())
        {
index 90611cc..7b4921f 100644 (file)
@@ -805,8 +805,8 @@ void CDirView::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
  */
 void CDirView::OpenParentDirectory()
 {
-       CString left = GetDocument()->m_pCtxt->m_strNormalizedLeft;
-       CString right = GetDocument()->m_pCtxt->m_strNormalizedRight;
+       const CString & left = GetDocument()->m_pCtxt->GetNormalizedLeft();
+       const CString & right = GetDocument()->m_pCtxt->GetNormalizedRight();
        CString leftParent = paths_GetParentPath(left);
        CString rightParent = paths_GetParentPath(right);
 
@@ -1972,7 +1972,7 @@ void CDirView::OnUpdateCtxtOpenWithUnpacker(CCmdUI* pCmdUI)
  */
 void CDirView::OnEditCopy() 
 {
-       PutToClipboard(GenerateReport(), this->m_hWnd);
+       PutToClipboard(GenerateReport(), GetSafeHwnd());
 }
 
 /**
@@ -1992,7 +1992,10 @@ CString CDirView::GenerateReport()
        
        // Report:Title
        if (GetDiffContext() != NULL)
-               AfxFormatString2(report, IDS_DIRECTORY_REPORT_TITLE, GetDiffContext()->m_strLeft, GetDiffContext()->m_strRight);
+       {
+               AfxFormatString2(report, IDS_DIRECTORY_REPORT_TITLE,
+                       GetDiffContext()->GetLeftPath(), GetDiffContext()->GetRightPath());
+       }
        report += _T("\r\n"); // Use DOS-EOL style for reports
 
        // Report:Header
@@ -2075,8 +2078,8 @@ int CDirView::AddSpecialItems()
 {
        CDirDoc *pDoc = GetDocument();
        int retVal = 0;
-       CString leftPath = pDoc->m_pCtxt->m_strNormalizedLeft;
-       CString rightPath = pDoc->m_pCtxt->m_strNormalizedRight;
+       const CString & leftPath = pDoc->m_pCtxt->GetNormalizedLeft();
+       const CString & rightPath = pDoc->m_pCtxt->GetNormalizedRight();
        CString leftParent = paths_GetParentPath(leftPath);
        CString rightParent = paths_GetParentPath(rightPath);
 
index bef570e..1d9a948 100644 (file)
@@ -2,6 +2,8 @@
  PATCH: [ 1155319 ] Select font for dir compare view
   Src: DirView.cpp DirView.h MainFrm.cpp MainFrm.h Merge.rc OptionsDef.h
   Languages: *.rc
+ PATCH: [ 1154667 ] Make CDiffContext paths private members
+  Src: DiffContext.cpp DiffContext.h DirActions.cpp DirDoc.cpp DirScan.cpp DirView.cpp
 
 2005-03-02 Perry
  PATCH: [ 1154259 ] Non blurred 'error.bmp'