Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
sdottaka committed Sep 24, 2023
1 parent 68ff0d0 commit 50a6bc9
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 60 deletions.
25 changes: 14 additions & 11 deletions Src/HexMergeDoc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -323,7 +326,7 @@ bool CHexMergeDoc::DoFileSave(int nBuffer)
{
m_filePaths[nBuffer] = strSavePath;
UpdateHeaderPath(nBuffer);
UpdateDiffItem(m_pDirDoc);
UpdateLastCompareResult();
}
}
}
Expand Down Expand Up @@ -356,7 +359,7 @@ bool CHexMergeDoc::DoFileSaveAs(int nBuffer, bool packing)
}

m_filePaths.SetPath(nBuffer, strPath);
UpdateDiffItem(m_pDirDoc);
UpdateLastCompareResult();
UpdateHeaderPath(nBuffer);
return true;
}
Expand Down Expand Up @@ -532,7 +535,7 @@ bool CHexMergeDoc::OpenDocs(int nFiles, const FileLocation fileloc[], const bool
if (nNormalBuffer > 0)
OnRefresh();
else
UpdateDiffItem(m_pDirDoc);
UpdateLastCompareResult();
}
else
{
Expand Down Expand Up @@ -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); });
Expand Down
2 changes: 1 addition & 1 deletion Src/HexMergeDoc.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
40 changes: 10 additions & 30 deletions Src/ImgMergeFrm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -748,7 +748,7 @@ bool CImgMergeFrame::DoFileSave(int pane)
}
}
}
UpdateDiffItem(m_pDirDoc);
UpdateLastCompareResult();
m_fileInfo[pane].Update(m_filePaths[pane]);
}
return true;
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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<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.
*
Expand Down Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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); });
Expand Down
3 changes: 1 addition & 2 deletions Src/ImgMergeFrm.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
23 changes: 9 additions & 14 deletions Src/WebPageDiffFrm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
{
Expand Down Expand Up @@ -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,
Expand Down
3 changes: 1 addition & 2 deletions Src/WebPageDiffFrm.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 50a6bc9

Please sign in to comment.