Skip to content

Commit

Permalink
Introduce IDirDoc interface
Browse files Browse the repository at this point in the history
  • Loading branch information
sdottaka committed Sep 24, 2023
1 parent 2252cdb commit 68ff0d0
Show file tree
Hide file tree
Showing 16 changed files with 158 additions and 144 deletions.
3 changes: 2 additions & 1 deletion Src/DirDoc.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "DirCmpReport.h"
#include "DirCompProgressBar.h"
#include "IMDITab.h"
#include "IDirDoc.h"

class CDirView;
struct IMergeDoc;
Expand All @@ -38,7 +39,7 @@ struct FileLocation;
* This class also has compare statistics which are updated during compare.
* GUI calls this class to operate with results.
*/
class CDirDoc : public CDocument, public IMDITab
class CDirDoc : public CDocument, public IMDITab, public IDirDoc
{
protected:
CDirDoc(); // protected constructor used by dynamic creation
Expand Down
49 changes: 8 additions & 41 deletions Src/HexMergeDoc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,13 @@
#include "UnicodeString.h"
#include "HexMergeFrm.h"
#include "HexMergeView.h"
#include "DiffItem.h"
#include "FolderCmp.h"
#include "DiffContext.h" // FILE_SAME
#include "DirDoc.h"
#include "DirActions.h"
#include "IDirDoc.h"
#include "OptionsDef.h"
#include "DiffFileInfo.h"
#include "SaveClosingDlg.h"
#include "SelectPluginDlg.h"
#include "DiffList.h"
#include "paths.h"
#include "OptionsMgr.h"
#include "FileOrFolderSelect.h"
#include "DiffWrapper.h"
#include "SyntaxColors.h"
#include "Merge.h"
#include "MainFrm.h"
Expand All @@ -41,28 +34,8 @@

int CHexMergeDoc::m_nBuffersTemp = 2;

static void UpdateDiffItem(int nBuffers, DIFFITEM &di, CDiffContext *pCtxt);
static int Try(HRESULT hr, UINT type = MB_OKCANCEL|MB_ICONSTOP);

/**
* @brief Update diff item
*/
static void UpdateDiffItem(int nBuffers, DIFFITEM &di, CDiffContext *pCtxt)
{
di.diffcode.setSideNone();
for (int nBuffer = 0; nBuffer < nBuffers; nBuffer++)
{
di.diffFileInfo[nBuffer].ClearPartial();
if (pCtxt->UpdateInfoFromDiskHalf(di, nBuffer))
di.diffcode.diffcode |= DIFFCODE::FIRST << nBuffer;
}
// Clear flags
di.diffcode.diffcode &= ~(DIFFCODE::TEXTFLAGS | DIFFCODE::COMPAREFLAGS | DIFFCODE::COMPAREFLAGS3WAY);
// Really compare
FolderCmp folderCmp(pCtxt);
di.diffcode.diffcode |= folderCmp.prepAndCompareFiles(di);
}

/**
* @brief Issue an error popup if passed in HRESULT is nonzero
*/
Expand Down Expand Up @@ -166,18 +139,8 @@ CHexMergeView * CHexMergeDoc::GetActiveMergeView() const
/**
* @brief Update associated diff item
*/
int CHexMergeDoc::UpdateDiffItem(CDirDoc *pDirDoc)
int CHexMergeDoc::UpdateDiffItem(IDirDoc *pDirDoc)
{
// If directory compare has results
if (pDirDoc != nullptr && pDirDoc->HasDiffs())
{
CDiffContext &ctxt = pDirDoc->GetDiffContext();
if (DIFFITEM *pos = FindItemFromPaths(ctxt, m_filePaths))
{
DIFFITEM &di = ctxt.GetDiffRefAt(pos);
::UpdateDiffItem(m_nBuffers, di, &ctxt);
}
}
bool bDiff = false;
size_t lengthFirst = m_pView[0]->GetLength();
void *bufferFirst = m_pView[0]->GetBuffer(lengthFirst);
Expand All @@ -194,6 +157,10 @@ int CHexMergeDoc::UpdateDiffItem(CDirDoc *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 @@ -456,7 +423,7 @@ void CHexMergeDoc::OnUpdateStatusNum(CCmdUI* pCmdUI)
/**
* @brief DirDoc gives us its identity just after it creates us
*/
void CHexMergeDoc::SetDirDoc(CDirDoc * pDirDoc)
void CHexMergeDoc::SetDirDoc(IDirDoc * pDirDoc)
{
ASSERT(pDirDoc != nullptr && m_pDirDoc == nullptr);
m_pDirDoc = pDirDoc;
Expand All @@ -478,7 +445,7 @@ CHexMergeFrame * CHexMergeDoc::GetParentFrame() const
/**
* @brief DirDoc is closing
*/
void CHexMergeDoc::DirDocClosing(CDirDoc * pDirDoc)
void CHexMergeDoc::DirDocClosing(IDirDoc * pDirDoc)
{
ASSERT(m_pDirDoc == pDirDoc);
m_pDirDoc = nullptr;
Expand Down
12 changes: 6 additions & 6 deletions Src/HexMergeDoc.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include "IMergeDoc.h"
#include "FileTransform.h"

class CDirDoc;
struct IDirDoc;
class CHexMergeFrame;
class CHexMergeView;

Expand Down Expand Up @@ -62,11 +62,11 @@ class CHexMergeDoc : public CDocument, public IMergeDoc
// Implementation
public:
~CHexMergeDoc();
int UpdateDiffItem(CDirDoc * pDirDoc);
int UpdateDiffItem(IDirDoc * pDirDoc);
bool PromptAndSaveIfNeeded(bool bAllowCancel);
CDirDoc* GetDirDoc() const override { return m_pDirDoc; };
void SetDirDoc(CDirDoc * pDirDoc) override;
void DirDocClosing(CDirDoc * pDirDoc) override;
IDirDoc* GetDirDoc() const override { return m_pDirDoc; };
void SetDirDoc(IDirDoc * pDirDoc) override;
void DirDocClosing(IDirDoc * pDirDoc) override;
bool CloseNow() override;
bool GenerateReport(const String& sFileName) const override { return true; }
const PackingInfo* GetUnpacker() const override { return &m_infoUnpacker; };
Expand Down Expand Up @@ -98,7 +98,7 @@ class CHexMergeDoc : public CDocument, public IMergeDoc
// Implementation data
protected:
CHexMergeView * m_pView[3]; /**< Pointer to left/right view */
CDirDoc * m_pDirDoc;
IDirDoc * m_pDirDoc;
String m_strDesc[3]; /**< Left/right side description text */
BUFFERTYPE m_nBufferType[3];
PackingInfo m_infoUnpacker;
Expand Down
38 changes: 38 additions & 0 deletions Src/IDirDoc.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#pragma once

#include "UnicodeString.h"

class PathContext;
struct IMergeDoc;
class CTempPathContext;
struct FileLocation;

struct IDirDoc
{
virtual void InitCompare(const PathContext& paths, bool bRecursive, CTempPathContext*) = 0;
virtual void SetHiddenItems(const std::vector<String>& hiddenItems) = 0;
virtual void SetReportFile(const String& sReportFile) = 0;
virtual void SetDescriptions(const String strDesc[]) = 0;
virtual void SetTitle(const tchar_t* pszTitle) = 0;
virtual void SetReadOnly(int nIndex, bool bRO) = 0;
virtual void Rescan() = 0;
virtual void AddMergeDoc(IMergeDoc* pMergeDoc) = 0;
virtual void MergeDocClosing(IMergeDoc* pMergeDoc) = 0;
virtual bool CloseMergeDocs() = 0;
virtual bool IsArchiveFolders() const = 0;
virtual bool HasDiffs() const = 0;
virtual void UpdateChangedItem(const PathContext& paths, unsigned nDiffs, unsigned nTrivialDiffs, bool bIdentical) = 0;
virtual void ApplyDisplayRoot(int nIndex, String& sText) = 0;
virtual bool CompareFilesIfFilesAreLarge(int nFiles, const FileLocation ifileloc[]) = 0;
virtual bool MoveableToNextDiff() = 0;
virtual bool MoveableToPrevDiff() = 0;
virtual void MoveToPrevDiff(IMergeDoc* pMergeDoc) = 0;
virtual void MoveToNextDiff(IMergeDoc* pMergeDoc) = 0;
virtual void MoveToFirstFile(IMergeDoc* pMergeDoc) = 0;
virtual void MoveToLastFile(IMergeDoc* pMergeDoc) = 0;
virtual void MoveToNextFile(IMergeDoc* pMergeDoc) = 0;
virtual void MoveToPrevFile(IMergeDoc* pMergeDoc) = 0;
virtual bool IsFirstFile() = 0;
virtual bool IsLastFile() = 0;
};

8 changes: 4 additions & 4 deletions Src/IMergeDoc.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include "UnicodeString.h"
#include "IMDITab.h"

class CDirDoc;
struct IDirDoc;
class PackingInfo;
class PrediffingInfo;

Expand All @@ -16,11 +16,11 @@ struct IMergeDoc : public IMDITab
Removed,
};

virtual CDirDoc* GetDirDoc() const = 0;
virtual void SetDirDoc(CDirDoc *pDirDoc) = 0;
virtual IDirDoc* GetDirDoc() const = 0;
virtual void SetDirDoc(IDirDoc *pDirDoc) = 0;
virtual bool CloseNow(void) = 0;
virtual bool GenerateReport(const String &path) const = 0;
virtual void DirDocClosing(CDirDoc * pDirDoc) = 0;
virtual void DirDocClosing(IDirDoc * pDirDoc) = 0;
virtual void CheckFileChanged() = 0;
virtual const PackingInfo *GetUnpacker() const = 0;
virtual void SetUnpacker(const PackingInfo *infoUnpacker) = 0;
Expand Down
10 changes: 6 additions & 4 deletions Src/ImgMergeFrm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#include "Merge.h"
#include "MainFrm.h"
#include "BCMenu.h"
#include "DirDoc.h"
#include "IDirDoc.h"
#include "OptionsDef.h"
#include "OptionsMgr.h"
#include "OptionsDiffColors.h"
Expand Down Expand Up @@ -332,7 +332,7 @@ void CImgMergeFrame::DoAutoMerge(int dstPane)
/**
* @brief DirDoc gives us its identity just after it creates us
*/
void CImgMergeFrame::SetDirDoc(CDirDoc * pDirDoc)
void CImgMergeFrame::SetDirDoc(IDirDoc * pDirDoc)
{
ASSERT(pDirDoc != nullptr && m_pDirDoc == nullptr);
m_pDirDoc = pDirDoc;
Expand Down Expand Up @@ -1156,7 +1156,7 @@ bool CImgMergeFrame::OpenImages()
/**
* @brief Update associated diff item
*/
int CImgMergeFrame::UpdateDiffItem(CDirDoc *pDirDoc)
int CImgMergeFrame::UpdateDiffItem(IDirDoc *pDirDoc)
{
// If directory compare has results
if (pDirDoc && pDirDoc->HasDiffs())
Expand Down Expand Up @@ -1269,7 +1269,9 @@ bool CImgMergeFrame::PromptAndSaveIfNeeded(bool bAllowCancel)
// If directory compare has results
if (m_pDirDoc && m_pDirDoc->HasDiffs())
{
// FIXME:
m_pDirDoc->UpdateChangedItem(m_filePaths,
static_cast<unsigned>(-1), static_cast<unsigned>(-1),
m_pImgMergeWindow->GetDiffCount() == 0);
}
}

Expand Down
12 changes: 6 additions & 6 deletions Src/ImgMergeFrm.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#include "MergeFrameCommon.h"
#include "FileTransform.h"

class CDirDoc;
struct IDirDoc;

/**
* @brief Frame class for file compare, handles panes, statusbar etc.
Expand Down Expand Up @@ -49,12 +49,12 @@ class CImgMergeFrame : public CMergeFrameCommon,public IMergeDoc
bool OpenDocs(int nFiles, const FileLocation fileloc[], const bool bRO[], const String strDesc[], CMDIFrameWnd *pParent);
void MoveOnLoad(int nPane = -1, int nLineIndex = -1);
void ChangeFile(int pane, const String& path);
CDirDoc* GetDirDoc() const override { return m_pDirDoc; };
void SetDirDoc(CDirDoc * pDirDoc) override;
IDirDoc* GetDirDoc() const override { return m_pDirDoc; };
void SetDirDoc(IDirDoc * pDirDoc) override;
void UpdateResources();
void RefreshOptions();
bool CloseNow() override;
void DirDocClosing(CDirDoc * pDirDoc) override { m_pDirDoc = nullptr; }
void DirDocClosing(IDirDoc * pDirDoc) override { m_pDirDoc = nullptr; }
void UpdateLastCompareResult();
void UpdateAutoPaneResize();
void UpdateSplitter();
Expand Down Expand Up @@ -104,7 +104,7 @@ class CImgMergeFrame : public CMergeFrameCommon,public IMergeDoc
void CreateImgWndStatusBar(CStatusBar &, CWnd *);
private:
bool OpenImages();
int UpdateDiffItem(CDirDoc * pDirDoc);
int UpdateDiffItem(IDirDoc * pDirDoc);
void UpdateHeaderSizes();
void UpdateHeaderPath(int pane);
void SetTitle(LPCTSTR lpszTitle);
Expand All @@ -125,7 +125,7 @@ class CImgMergeFrame : public CMergeFrameCommon,public IMergeDoc
bool m_bRO[3];
String m_strSaveAsPath; /**< "3rd path" where output saved if given */
bool m_bAutoMerged;
CDirDoc *m_pDirDoc;
IDirDoc *m_pDirDoc;
int m_nActivePane;
PackingInfo m_infoUnpacker;
std::vector<int> m_unpackerSubcodes[3];
Expand Down
Loading

0 comments on commit 68ff0d0

Please sign in to comment.