OSDN Git Service

refactor
authorTakashi Sawanaka <sdottaka@users.sourceforge.net>
Sun, 24 Sep 2023 23:36:02 +0000 (08:36 +0900)
committerTakashi Sawanaka <sdottaka@users.sourceforge.net>
Sun, 24 Sep 2023 23:36:02 +0000 (08:36 +0900)
Src/HexMergeDoc.cpp
Src/HexMergeDoc.h
Src/ImgMergeFrm.cpp
Src/ImgMergeFrm.h
Src/WebPageDiffFrm.cpp
Src/WebPageDiffFrm.h

index 4551738..ee15192 100644 (file)
@@ -137,9 +137,9 @@ CHexMergeView * CHexMergeDoc::GetActiveMergeView() const
 }
 
 /**
- * @brief Update associated diff item
+ * @brief Update last compare result
  */
-int CHexMergeDoc::UpdateDiffItem(IDirDoc *pDirDoc)
+int CHexMergeDoc::UpdateLastCompareResult()
 {
        bool bDiff = false;
        size_t lengthFirst = m_pView[0]->GetLength();
@@ -157,10 +157,6 @@ int CHexMergeDoc::UpdateDiffItem(IDirDoc *pDirDoc)
                if (bDiff)
                        break;
        }
-       // If directory compare has results
-       if (pDirDoc != nullptr && pDirDoc->HasDiffs())
-               m_pDirDoc->UpdateChangedItem(m_filePaths,
-                       static_cast<unsigned>(-1), static_cast<unsigned>(-1), !bDiff);
        GetParentFrame()->SetLastCompareResult(bDiff);
        return bDiff ? 1 : 0;
 }
@@ -264,7 +260,14 @@ bool CHexMergeDoc::PromptAndSaveIfNeeded(bool bAllowCancel)
        // update status on dir view
        if (bLSaveSuccess || bMSaveSuccess || bRSaveSuccess)
        {
-               UpdateDiffItem(m_pDirDoc);
+               int compareResult = UpdateLastCompareResult();
+               // If directory compare has results
+               if (m_pDirDoc != nullptr && m_pDirDoc->HasDiffs())
+               {
+                       m_pDirDoc->UpdateChangedItem(m_filePaths,
+                               static_cast<unsigned>(-1), static_cast<unsigned>(-1),
+                                       compareResult != 0);
+               }
        }
 
        return result;
@@ -323,7 +326,7 @@ bool CHexMergeDoc::DoFileSave(int nBuffer)
                        {
                                m_filePaths[nBuffer] = strSavePath;
                                UpdateHeaderPath(nBuffer);
-                               UpdateDiffItem(m_pDirDoc);
+                               UpdateLastCompareResult();
                        }
                }
        }
@@ -356,7 +359,7 @@ bool CHexMergeDoc::DoFileSaveAs(int nBuffer, bool packing)
                }
 
                m_filePaths.SetPath(nBuffer, strPath);
-               UpdateDiffItem(m_pDirDoc);
+               UpdateLastCompareResult();
                UpdateHeaderPath(nBuffer);
                return true;
        }
@@ -532,7 +535,7 @@ bool CHexMergeDoc::OpenDocs(int nFiles, const FileLocation fileloc[], const bool
                if (nNormalBuffer > 0)
                        OnRefresh();
                else
-                       UpdateDiffItem(m_pDirDoc);
+                       UpdateLastCompareResult();
        }
        else
        {
@@ -938,7 +941,7 @@ void CHexMergeDoc::OnViewZoomNormal()
 
 void CHexMergeDoc::OnRefresh()
 {
-       if (UpdateDiffItem(m_pDirDoc) == 0)
+       if (UpdateLastCompareResult() == 0)
        {
                CMergeFrameCommon::ShowIdenticalMessage(m_filePaths, true,
                        [](const tchar_t* msg, UINT flags, UINT id) -> int { return AfxMessageBox(msg, flags, id); });
index fdf089e..66ab13b 100644 (file)
@@ -62,7 +62,7 @@ public:
 // Implementation
 public:
        ~CHexMergeDoc();
-       int UpdateDiffItem(IDirDoc * pDirDoc);
+       int UpdateLastCompareResult();
        bool PromptAndSaveIfNeeded(bool bAllowCancel);
        IDirDoc* GetDirDoc() const override { return m_pDirDoc; };
        void SetDirDoc(IDirDoc * pDirDoc) override;
index 2bba5a4..85b5358 100644 (file)
@@ -254,7 +254,7 @@ bool CImgMergeFrame::OpenDocs(int nFiles, const FileLocation fileloc[], const bo
        if (nNormalBuffer > 0)
                OnRefresh();
        else
-               UpdateDiffItem(m_pDirDoc);
+               UpdateLastCompareResult();
 
        if (GetOptionsMgr()->GetBool(OPT_SCROLL_TO_FIRST))
                m_pImgMergeWindow->FirstDiff();
@@ -748,7 +748,7 @@ bool CImgMergeFrame::DoFileSave(int pane)
                                }
                        }
                }
-               UpdateDiffItem(m_pDirDoc);
+               UpdateLastCompareResult();
                m_fileInfo[pane].Update(m_filePaths[pane]);
        }
        return true;
@@ -806,7 +806,7 @@ RETRY:
                }
 
                m_filePaths.SetPath(pane, strPath);
-               UpdateDiffItem(m_pDirDoc);
+               UpdateLastCompareResult();
                m_fileInfo[pane].Update(m_filePaths[pane]);
                UpdateHeaderPath(pane);
        }
@@ -1120,9 +1120,11 @@ void CImgMergeFrame::SetTitle(LPCTSTR lpszTitle)
                SetWindowText(sTitle.c_str());
 }
 
-void CImgMergeFrame::UpdateLastCompareResult()
+int CImgMergeFrame::UpdateLastCompareResult()
 {
-       SetLastCompareResult(m_pImgMergeWindow->GetDiffCount() > 0 ? 1 : 0);
+       int result = m_pImgMergeWindow->GetDiffCount() > 0 ? 1 : 0;
+       SetLastCompareResult(result != 0);
+       return result;
 }
 
 void CImgMergeFrame::UpdateAutoPaneResize()
@@ -1154,29 +1156,6 @@ bool CImgMergeFrame::OpenImages()
 }
 
 /**
- * @brief Update associated diff item
- */
-int CImgMergeFrame::UpdateDiffItem(IDirDoc *pDirDoc)
-{
-       // If directory compare has results
-       if (pDirDoc && pDirDoc->HasDiffs())
-       {
-// FIXME:
-//             const String &pathLeft = m_filePaths.GetLeft();
-//             const String &pathRight = m_filePaths.GetRight();
-//             CDiffContext &ctxt = const_cast<CDiffContext &>(pDirDoc->GetDiffContext());
-//             if (UINT_PTR pos = pDirDoc->FindItemFromPaths(pathLeft, pathRight))
-//             {
-//                     DIFFITEM &di = pDirDoc->GetDiffRefByKey(pos);
-//                     ::UpdateDiffItem(m_nBuffers, di, &ctxt);
-//             }
-       }
-       int result = m_pImgMergeWindow->GetDiffCount() > 0 ? 1 : 0;
-       SetLastCompareResult(result != 0);
-       return result;
-}
-
-/**
  * @brief Asks and then saves modified files.
  *
  * This function saves modified files. Dialog is shown for user to select
@@ -1266,12 +1245,13 @@ bool CImgMergeFrame::PromptAndSaveIfNeeded(bool bAllowCancel)
             (bMModified && bMSaveSuccess) ||
                 (bRModified && bRSaveSuccess))
        {
+               int compareResult = UpdateLastCompareResult();
                // If directory compare has results
                if (m_pDirDoc && m_pDirDoc->HasDiffs())
                {
                        m_pDirDoc->UpdateChangedItem(m_filePaths,
                                static_cast<unsigned>(-1), static_cast<unsigned>(-1),
-                               m_pImgMergeWindow->GetDiffCount() == 0);
+                               compareResult != 0);
                }
        }
 
@@ -2363,7 +2343,7 @@ void CImgMergeFrame::OnToolsGenerateReport()
 
 void CImgMergeFrame::OnRefresh()
 {
-       if (UpdateDiffItem(m_pDirDoc) == 0)
+       if (UpdateLastCompareResult() == 0)
        {
                CMergeFrameCommon::ShowIdenticalMessage(m_filePaths, true,
                        [](const tchar_t* msg, UINT flags, UINT id) -> int { return AfxMessageBox(msg, flags, id); });
index be23870..3b67dba 100644 (file)
@@ -55,7 +55,7 @@ public:
        void RefreshOptions();
        bool CloseNow() override;
        void DirDocClosing(IDirDoc * pDirDoc) override { m_pDirDoc = nullptr; }
-       void UpdateLastCompareResult();
+       int UpdateLastCompareResult();
        void UpdateAutoPaneResize();
        void UpdateSplitter();
        bool GenerateReport(const String& sFileName) const override;
@@ -104,7 +104,6 @@ private:
        void CreateImgWndStatusBar(CStatusBar &, CWnd *);
 private:
        bool OpenImages();
-       int UpdateDiffItem(IDirDoc * pDirDoc);
        void UpdateHeaderSizes();
        void UpdateHeaderPath(int pane);
        void SetTitle(LPCTSTR lpszTitle);
index e817e27..2e9b3b6 100644 (file)
@@ -431,7 +431,7 @@ BOOL CWebPageDiffFrame::OnCreateClient(LPCREATESTRUCT /*lpcs*/,
                                        ++nNormalBuffer;
                        }
                        if (nNormalBuffer == 0)
-                               UpdateDiffItem(m_pDirDoc);
+                               UpdateLastCompareResult();
 
                        if (GetOptionsMgr()->GetBool(OPT_SCROLL_TO_FIRST))
                                m_pWebDiffWindow->FirstDiff();
@@ -855,10 +855,15 @@ void CWebPageDiffFrame::SetTitle(LPCTSTR lpszTitle)
        }
 }
 
-void CWebPageDiffFrame::UpdateLastCompareResult()
+int CWebPageDiffFrame::UpdateLastCompareResult()
 {
+       int result = -1;
        if (m_bCompareCompleted)
-               SetLastCompareResult(m_pWebDiffWindow->GetDiffCount() > 0 ? 1 : 0);
+       {
+               result = m_pWebDiffWindow->GetDiffCount() > 0 ? 1 : 0;
+               SetLastCompareResult(result);
+       }
+       return result;
 }
 
 void CWebPageDiffFrame::UpdateAutoPaneResize()
@@ -890,16 +895,6 @@ bool CWebPageDiffFrame::OpenUrls(IWebDiffCallback* callback)
        return bResult;
 }
 
-/**
- * @brief Update associated diff item
- */
-int CWebPageDiffFrame::UpdateDiffItem(IDirDoc *pDirDoc)
-{
-       int result = m_pWebDiffWindow->GetDiffCount() > 0 ? 1 : 0;
-       SetLastCompareResult(result != 0);
-       return result;
-}
-
 /// Document commanding us to close
 bool CWebPageDiffFrame::CloseNow()
 {
@@ -1692,7 +1687,7 @@ void CWebPageDiffFrame::OnRefresh()
                Callback<IWebDiffCallback>([this](const WebDiffCallbackResult& result) -> HRESULT
                        {
                                m_bCompareCompleted = true;
-                               if (UpdateDiffItem(m_pDirDoc) == 0 &&
+                               if (UpdateLastCompareResult() == 0 &&
                                    std::count(m_filePaths.begin(), m_filePaths.end(), L"about:blank") != m_filePaths.GetSize())
                                {
                                        CMergeFrameCommon::ShowIdenticalMessage(m_filePaths, true,
index 4515afc..9b01815 100644 (file)
@@ -53,7 +53,7 @@ public:
        void RefreshOptions();
        bool CloseNow() override;
        void DirDocClosing(IDirDoc * pDirDoc) override { m_pDirDoc = nullptr; }
-       void UpdateLastCompareResult();
+       int UpdateLastCompareResult();
        void UpdateAutoPaneResize();
        void UpdateSplitter();
        bool GenerateReport(const String& sFileName) const;
@@ -99,7 +99,6 @@ private:
        void CreateWebWndStatusBar(CStatusBar &, CWnd *);
        void OnWebDiffEvent(const WebDiffEvent& event);
        bool OpenUrls(IWebDiffCallback* callback);
-       int UpdateDiffItem(IDirDoc * pDirDoc);
        void UpdateHeaderSizes();
        void UpdateHeaderPath(int pane);
        void SetTitle(LPCTSTR lpszTitle);