Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
sdottaka committed Sep 27, 2023
1 parent 4182de4 commit 69ba23c
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 45 deletions.
39 changes: 20 additions & 19 deletions Src/HexMergeDoc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,23 +256,20 @@ bool CHexMergeDoc::PromptAndSaveIfNeeded(bool bAllowCancel)
result = false;
}

// If file were modified and saving was successfull,
// update status on dir view
if (bLSaveSuccess || bMSaveSuccess || bRSaveSuccess)
{
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;
}

/**
* @brief Return true if any of the panes has changed
*/
bool CHexMergeDoc::IsModified() const
{
for (int nBuffer = 0; nBuffer < m_nBuffers; ++nBuffer)
if (m_pView[nBuffer]->GetModified())
return true;
return false;
}

/**
* @brief Save modified documents
*/
Expand Down Expand Up @@ -326,7 +323,14 @@ bool CHexMergeDoc::DoFileSave(int nBuffer)
{
m_filePaths[nBuffer] = strSavePath;
UpdateHeaderPath(nBuffer);
UpdateLastCompareResult();
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);
}
}
}
}
Expand Down Expand Up @@ -728,10 +732,7 @@ void CHexMergeDoc::OnUpdateFileSaveRight(CCmdUI* pCmdUI)
*/
void CHexMergeDoc::OnUpdateFileSave(CCmdUI* pCmdUI)
{
bool bModified = false;
for (int nBuffer = 0; nBuffer < m_nBuffers; nBuffer++)
bModified |= m_pView[nBuffer]->GetModified();
pCmdUI->Enable(bModified);
pCmdUI->Enable(IsModified());
}

/**
Expand Down
1 change: 1 addition & 0 deletions Src/HexMergeDoc.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ class CHexMergeDoc : public CDocument, public IMergeDoc
void SaveAs(int nBuffer, bool packing = true) { DoFileSaveAs(nBuffer, packing); }
String GetSaveAsPath() const { return m_strSaveAsPath; }
void SetSaveAsPath(const String& strSaveAsPath) { m_strSaveAsPath = strSaveAsPath; }
bool IsModified() const;

private:
bool DoFileSave(int nBuffer);
Expand Down
31 changes: 12 additions & 19 deletions Src/ImgMergeFrm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -712,7 +712,8 @@ bool CImgMergeFrame::DoFileSave(int pane)
{
if (m_pImgMergeWindow->IsModified(pane))
{
if (m_nBufferType[pane] == BUFFERTYPE::UNNAMED)
if (m_nBufferType[pane] == BUFFERTYPE::UNNAMED ||
!m_pImgMergeWindow->IsSaveSupported(pane))
DoFileSaveAs(pane);
else
{
Expand Down Expand Up @@ -748,15 +749,23 @@ bool CImgMergeFrame::DoFileSave(int pane)
}
}
}
UpdateLastCompareResult();
int compareResult = UpdateLastCompareResult();
m_fileInfo[pane].Update(m_filePaths[pane]);

// If directory compare has results
if (m_pDirDoc && m_pDirDoc->HasDiffs())
{
m_pDirDoc->UpdateChangedItem(m_filePaths,
static_cast<unsigned>(-1), static_cast<unsigned>(-1),
compareResult == 0);
}
}
return true;
}

bool CImgMergeFrame::DoFileSaveAs(int pane, bool packing)
{
const String &path = m_filePaths.GetPath(pane);
const String path = m_filePaths.GetPath(pane) + (m_pImgMergeWindow->IsSaveSupported(pane) ? _T("") : _T(".png"));
String strPath;
String title;
if (pane == 0)
Expand Down Expand Up @@ -1239,22 +1248,6 @@ bool CImgMergeFrame::PromptAndSaveIfNeeded(bool bAllowCancel)
result = false;
}

// If file were modified and saving was successfull,
// update status on dir view
if ((bLModified && bLSaveSuccess) ||
(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),
compareResult != 0);
}
}

return result;
}

Expand Down
8 changes: 1 addition & 7 deletions Src/MergeDoc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2050,13 +2050,7 @@ void CMergeDoc::OnFileSaveRight()
*/
void CMergeDoc::OnUpdateFileSave(CCmdUI* pCmdUI)
{
bool bModified = false;
for (int nPane = 0; nPane < m_nBuffers; nPane++)
{
if (m_ptBuf[nPane]->IsModified())
bModified = true;
}
pCmdUI->Enable(bModified);
pCmdUI->Enable(IsModified());
}

/**
Expand Down

0 comments on commit 69ba23c

Please sign in to comment.