From 50a6bc9d326c76445759f1d2705491f669b98a2f Mon Sep 17 00:00:00 2001 From: Takashi Sawanaka Date: Mon, 25 Sep 2023 08:36:02 +0900 Subject: [PATCH] refactor --- Src/HexMergeDoc.cpp | 25 ++++++++++++++----------- Src/HexMergeDoc.h | 2 +- Src/ImgMergeFrm.cpp | 40 ++++++++++------------------------------ Src/ImgMergeFrm.h | 3 +-- Src/WebPageDiffFrm.cpp | 23 +++++++++-------------- Src/WebPageDiffFrm.h | 3 +-- 6 files changed, 36 insertions(+), 60 deletions(-) diff --git a/Src/HexMergeDoc.cpp b/Src/HexMergeDoc.cpp index 45517387816..ee151925664 100644 --- a/Src/HexMergeDoc.cpp +++ b/Src/HexMergeDoc.cpp @@ -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(-1), static_cast(-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(-1), static_cast(-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); }); diff --git a/Src/HexMergeDoc.h b/Src/HexMergeDoc.h index fdf089e1192..66ab13b5c63 100644 --- a/Src/HexMergeDoc.h +++ b/Src/HexMergeDoc.h @@ -62,7 +62,7 @@ class CHexMergeDoc : public CDocument, public IMergeDoc // 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; diff --git a/Src/ImgMergeFrm.cpp b/Src/ImgMergeFrm.cpp index 2bba5a47567..85b53585a92 100644 --- a/Src/ImgMergeFrm.cpp +++ b/Src/ImgMergeFrm.cpp @@ -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 @@ bool CImgMergeFrame::DoFileSaveAs(int pane, bool packing) } 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() @@ -1153,29 +1155,6 @@ bool CImgMergeFrame::OpenImages() return bResult; } -/** - * @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(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. * @@ -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(-1), static_cast(-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); }); diff --git a/Src/ImgMergeFrm.h b/Src/ImgMergeFrm.h index be238701746..3b67dba4cba 100644 --- a/Src/ImgMergeFrm.h +++ b/Src/ImgMergeFrm.h @@ -55,7 +55,7 @@ class CImgMergeFrame : public CMergeFrameCommon,public IMergeDoc 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 @@ class CImgMergeFrame : public CMergeFrameCommon,public IMergeDoc void CreateImgWndStatusBar(CStatusBar &, CWnd *); private: bool OpenImages(); - int UpdateDiffItem(IDirDoc * pDirDoc); void UpdateHeaderSizes(); void UpdateHeaderPath(int pane); void SetTitle(LPCTSTR lpszTitle); diff --git a/Src/WebPageDiffFrm.cpp b/Src/WebPageDiffFrm.cpp index e817e27766e..2e9b3b60544 100644 --- a/Src/WebPageDiffFrm.cpp +++ b/Src/WebPageDiffFrm.cpp @@ -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([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, diff --git a/Src/WebPageDiffFrm.h b/Src/WebPageDiffFrm.h index 4515afcb47b..9b01815fe2c 100644 --- a/Src/WebPageDiffFrm.h +++ b/Src/WebPageDiffFrm.h @@ -53,7 +53,7 @@ class CWebPageDiffFrame : public CMergeFrameCommon,public IMergeDoc 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 @@ class CWebPageDiffFrame : public CMergeFrameCommon,public IMergeDoc 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);