#include <shlwapi.h> // PathFindFileName()
#include <Poco/StringTokenizer.h>
#include "Merge.h"
-#include "MergeDoc.h"
-#include "HexMergeDoc.h"
+#include "IMergeDoc.h"
+#include "CompareOptions.h"
#include "UnicodeString.h"
#include "CompareStats.h"
#include "FilterList.h"
POSITION pos = m_MergeDocs.GetHeadPosition();
while (pos)
{
- CMergeDoc * pMergeDoc = m_MergeDocs.GetNext(pos);
+ IMergeDoc * pMergeDoc = m_MergeDocs.GetNext(pos);
pMergeDoc->DirDocClosing(this);
}
- pos = m_HexMergeDocs.GetHeadPosition();
- while (pos)
- {
- CHexMergeDoc * pHexMergeDoc = m_HexMergeDocs.GetNext(pos);
- pHexMergeDoc->DirDocClosing(this);
- }
// Delete all temporary folders belonging to this document
while (m_pTempPathContext)
{
/**
* @brief A new MergeDoc has been opened.
*/
-void CDirDoc::AddMergeDoc(CMergeDoc * pMergeDoc)
+void CDirDoc::AddMergeDoc(IMergeDoc * pMergeDoc)
{
ASSERT(pMergeDoc);
m_MergeDocs.AddTail(pMergeDoc);
}
/**
- * @brief A new HexMergeDoc has been opened.
- */
-void CDirDoc::AddHexMergeDoc(CHexMergeDoc * pHexMergeDoc)
-{
- ASSERT(pHexMergeDoc);
- m_HexMergeDocs.AddTail(pHexMergeDoc);
-}
-
-/**
* @brief MergeDoc informs us it is closing.
*/
-void CDirDoc::MergeDocClosing(CDocument * pMergeDoc)
+void CDirDoc::MergeDocClosing(IMergeDoc * pMergeDoc)
{
ASSERT(pMergeDoc);
if (POSITION pos = m_MergeDocs.CPtrList::Find(pMergeDoc))
m_MergeDocs.RemoveAt(pos);
- else if (POSITION pos = m_HexMergeDocs.CPtrList::Find(pMergeDoc))
- m_HexMergeDocs.RemoveAt(pos);
else
ASSERT(FALSE);
if (m_pCtxt == NULL && !m_bReuseCloses)
m_pDirView->PostMessage(WM_COMMAND, ID_FILE_CLOSE);
}
- else if (m_MergeDocs.GetCount() == 0 && m_HexMergeDocs.GetCount() == 0)
+ else if (m_MergeDocs.GetCount() == 0)
{
delete this;
}
POSITION pos = m_MergeDocs.GetHeadPosition();
while (pos)
{
- CMergeDoc * pMergeDoc = m_MergeDocs.GetNext(pos);
+ IMergeDoc * pMergeDoc = m_MergeDocs.GetNext(pos);
if (!pMergeDoc->CloseNow())
return FALSE;
}
- pos = m_HexMergeDocs.GetHeadPosition();
- while (pos)
- {
- CHexMergeDoc * pHexMergeDoc = m_HexMergeDocs.GetNext(pos);
- if (!pHexMergeDoc->CloseNow())
- return FALSE;
- }
return TRUE;
}
}
/**
- * @brief Obtain a merge doc to display a difference in files.
- * @param [out] pNew Set to TRUE if a new doc is created,
- * and FALSE if an existing one reused.
- * @return Pointer to CMergeDoc to use (new or existing).
- */
-CMergeDoc * CDirDoc::GetMergeDocForDiff(int nFiles, BOOL * pNew)
-{
- CMergeDoc * pMergeDoc = 0;
- // policy -- use an existing merge doc if available
- const BOOL bMultiDocs = GetOptionsMgr()->GetBool(OPT_MULTIDOC_MERGEDOCS);
- if (!bMultiDocs && !m_MergeDocs.IsEmpty())
- {
- *pNew = FALSE;
- pMergeDoc = m_MergeDocs.GetHead();
- }
- else
- {
- // Create a new merge doc
- CMergeDoc::m_nBuffersTemp = nFiles;
- pMergeDoc = (CMergeDoc*)theApp.m_pDiffTemplate->OpenDocumentFile(NULL);
- AddMergeDoc(pMergeDoc);
- pMergeDoc->SetDirDoc(this);
- *pNew = TRUE;
- }
- return pMergeDoc;
-}
-
-/**
- * @brief Obtain a hex merge doc to display a difference in files.
- * @param [out] pNew Set to TRUE if a new doc is created,
- * and FALSE if an existing one reused.
- * @return Pointer to CHexMergeDoc to use (new or existing).
- */
-CHexMergeDoc * CDirDoc::GetHexMergeDocForDiff(int nFiles, BOOL * pNew)
-{
- CHexMergeDoc * pHexMergeDoc = 0;
- // policy -- use an existing merge doc if available
- const BOOL bMultiDocs = GetOptionsMgr()->GetBool(OPT_MULTIDOC_MERGEDOCS);
- if (!bMultiDocs && !m_HexMergeDocs.IsEmpty())
- {
- *pNew = FALSE;
- pHexMergeDoc = m_HexMergeDocs.GetHead();
- }
- else
- {
- // Create a new merge doc
- CHexMergeDoc::m_nBuffersTemp = nFiles;
- pHexMergeDoc = (CHexMergeDoc*)theApp.m_pHexMergeTemplate->OpenDocumentFile(NULL);
- if (pHexMergeDoc)
- {
- AddHexMergeDoc(pHexMergeDoc);
- pHexMergeDoc->SetDirDoc(this);
- }
- *pNew = TRUE;
- }
- return pHexMergeDoc;
-}
-
-/**
* @brief Update changed item's compare status
* @param [in] paths Paths for files we update
* @param [in] nDiffs Total amount of differences
#include "PluginManager.h"
class CDirView;
-class CMergeDoc;
-class CHexMergeDoc;
-typedef CTypedPtrList<CPtrList, CMergeDoc *> MergeDocPtrList;
-typedef CTypedPtrList<CPtrList, CHexMergeDoc *> HexMergeDocPtrList;
+struct IMergeDoc;
+typedef CTypedPtrList<CPtrList, IMergeDoc *> MergeDocPtrList;
class DirDocFilterGlobal;
class DirDocFilterByExtension;
class CustomStatusCursor;
public:
BOOL CloseMergeDocs();
CDirView * GetMainView() const;
- CMergeDoc * GetMergeDocForDiff(int nFiles, BOOL * pNew);
- CHexMergeDoc * GetHexMergeDocForDiff(int nFiles, BOOL * pNew);
+
BOOL ReusingDirDoc();
// Overrides
void Redisplay();
virtual ~CDirDoc();
void SetDirView( CDirView *newView ); // TODO Perry
- void AddMergeDoc(CMergeDoc * pMergeDoc);
- void AddHexMergeDoc(CHexMergeDoc * pHexMergeDoc);
- void MergeDocClosing(CDocument * pMergeDoc);
+ void AddMergeDoc(IMergeDoc * pMergeDoc);
+ void MergeDocClosing(IMergeDoc * pMergeDoc);
CDiffThread m_diffThread;
void SetDiffStatus(UINT diffcode, UINT mask, int idx);
void SetDiffCounts(UINT diffs, UINT ignored, int idx);
CDirView *m_pDirView; /**< Pointer to GUI */
boost::scoped_ptr<CompareStats> m_pCompareStats; /**< Compare statistics */
MergeDocPtrList m_MergeDocs; /**< List of file compares opened from this compare */
- HexMergeDocPtrList m_HexMergeDocs; /**< List of hex file compares opened from this compare */
bool m_bRO[3]; /**< Is left/middle/right side read-only */
bool m_bRecursive; /**< Is current compare recursive? */
boost::scoped_ptr<CustomStatusCursor> m_statusCursor;
#include "ClipBoard.h"
#include "DirFrame.h" // StatePane
#include "DirDoc.h"
-#include "MergeDoc.h"
-#include "HexMergeFrm.h"
-#include "HexMergeDoc.h"
-#include "ImgMergeFrm.h"
+#include "IMergeDoc.h"
+#include "FileLocation.h"
#include "MainFrm.h"
#include "resource.h"
#include "coretools.h"
m_pDirView->OpenSelection();
CFrameWnd * pFrame = GetMainFrame()->GetActiveFrame();
- CMainFrame::FRAMETYPE frametype = GetMainFrame()->GetFrameType(pFrame);
- if (frametype == CMainFrame::FRAME_FILE)
+ IMergeDoc * pMergeDoc = dynamic_cast<IMergeDoc *>(pFrame->GetActiveDocument());
+ if (!pMergeDoc)
+ pMergeDoc = dynamic_cast<IMergeDoc *>(pFrame);
+
+ if (pMergeDoc)
{
- CMergeDoc * pMergeDoc = (CMergeDoc *) pFrame->GetActiveDocument();
pMergeDoc->GenerateReport(paths_ConcatPath(sDestDir, sLinkPath).c_str());
pMergeDoc->CloseNow();
}
- else if (frametype == CMainFrame::FRAME_IMGFILE)
- {
- CImgMergeFrame *pImgMergeFrame = static_cast<CImgMergeFrame *>(pFrame);
- pImgMergeFrame->GenerateReport(paths_ConcatPath(sDestDir, sLinkPath).c_str());
- pImgMergeFrame->CloseNow();
- }
MSG msg;
while (::PeekMessage(&msg, NULL, NULL, NULL, PM_NOREMOVE))
/**
* @brief DirDoc commanding us to close
*/
-BOOL CHexMergeDoc::CloseNow()
+bool CHexMergeDoc::CloseNow()
{
// Allow user to cancel closing
if (!PromptAndSaveIfNeeded(TRUE))
- return FALSE;
+ return false;
GetParentFrame()->CloseNow();
- return TRUE;
+ return true;
}
/**
#include "PathContext.h"
#include "DiffFileInfo.h"
+#include "IMergeDoc.h"
class CDirDoc;
class CHexMergeFrame;
/**
* @brief Document class for bytewise merging two files presented as hexdumps
*/
-class CHexMergeDoc : public CDocument
+class CHexMergeDoc : public CDocument, public IMergeDoc
{
public:
enum BUFFERTYPE
BOOL PromptAndSaveIfNeeded(BOOL bAllowCancel);
void SetDirDoc(CDirDoc * pDirDoc);
void DirDocClosing(CDirDoc * pDirDoc);
- BOOL CloseNow();
+ bool CloseNow();
+ bool GenerateReport(LPCTSTR szFileName) { return true; }
CHexMergeFrame * GetParentFrame() const;
void UpdateHeaderPath(int pane);
HRESULT OpenDocs(const PathContext &paths, const bool bRO[]);
--- /dev/null
+#pragma once\r
+\r
+#include "UnicodeString.h"\r
+\r
+class CDirDoc;\r
+\r
+struct IMergeDoc\r
+{\r
+ virtual void SetDirDoc(CDirDoc *pDirDoc) = 0;\r
+ virtual bool CloseNow(void) = 0;\r
+ virtual bool GenerateReport(const TCHAR *path) = 0;\r
+ virtual void DirDocClosing(CDirDoc * pDirDoc) = 0;\r
+ virtual void CheckFileChanged() = 0;\r
+};\r
+\r
CImgMergeFrame::~CImgMergeFrame()
{
+ if (m_pDirDoc)
+ {
+ m_pDirDoc->MergeDocClosing(this);
+ m_pDirDoc = NULL;
+ }
+
if (m_hIdentical != NULL)
{
DestroyIcon(m_hIdentical);
#include "EditorFilepathBar.h"
#include "PathContext.h"
#include "DiffFileInfo.h"
+#include "IMergeDoc.h"
#include "../Externals/winimerge/src/WinIMergeLib.h"
class CDirDoc;
/**
* @brief Frame class for file compare, handles panes, statusbar etc.
*/
-class CImgMergeFrame : public CMDIChildWnd
+class CImgMergeFrame : public CMDIChildWnd, public IMergeDoc
{
private:
enum BUFFERTYPE
void SetDirDoc(CDirDoc * pDirDoc);
void UpdateResources();
bool CloseNow();
+ void DirDocClosing(CDirDoc * pDirDoc) { m_pDirDoc = NULL; }
void SetSharedMenu(HMENU hMenu) { m_hMenuShared = hMenu; };
void SetLastCompareResult(int nResult);
void UpdateAutoPaneResize();
int nFiles, const FileLocation ifileloc[],
const DWORD dwFlags[] /*=0*/, const PackingInfo * infoUnpacker /*= NULL*/)
{
- BOOL docNull;
if (!m_pMenus[MENU_MERGEVIEW])
theApp.m_pDiffTemplate->m_hMenuShared = NewMergeViewMenu();
- CMergeDoc * pMergeDoc = GetMergeDocToShow(nFiles, pDirDoc, &docNull);
+ CMergeDoc * pMergeDoc = GetMergeDocToShow(nFiles, pDirDoc);
// Make local copies, so we can change encoding if we guess it below
FileLocation fileloc[3];
}
}
}
- if (docNull)
- {
- CWnd* pWnd = pMergeDoc->GetParentFrame();
- MDIActivate(pWnd);
- }
- else
- MDINext();
}
return openResults;
}
void CMainFrame::ShowHexMergeDoc(CDirDoc * pDirDoc,
const PathContext &paths, const bool bRO[])
{
- BOOL docNull;
if (!m_pMenus[MENU_HEXMERGEVIEW])
theApp.m_pHexMergeTemplate->m_hMenuShared = NewHexMergeViewMenu();
- if (CHexMergeDoc *pHexMergeDoc = GetHexMergeDocToShow(paths.GetSize(), pDirDoc, &docNull))
+ if (CHexMergeDoc *pHexMergeDoc = GetHexMergeDocToShow(paths.GetSize(), pDirDoc))
pHexMergeDoc->OpenDocs(paths, bRO);
}
}
pImgMergeFrame->SetDirDoc(pDirDoc);
+ pDirDoc->AddMergeDoc(pImgMergeFrame);
if (!pImgMergeFrame->OpenImages(files, bRO, nActivePane, this))
{
/**
* @brief Obtain a merge doc to display a difference in files.
+ * @return Pointer to CMergeDoc to use.
+ */
+template<class DocClass>
+DocClass * GetMergeDocForDiff(CMultiDocTemplate *pTemplate, CDirDoc *pDirDoc, int nFiles)
+{
+ // Create a new merge doc
+ DocClass::m_nBuffersTemp = nFiles;
+ DocClass *pMergeDoc = (DocClass*)pTemplate->OpenDocumentFile(NULL);
+ pDirDoc->AddMergeDoc(pMergeDoc);
+ pMergeDoc->SetDirDoc(pDirDoc);
+ return pMergeDoc;
+}
+
+/**
+ * @brief Obtain a merge doc to display a difference in files.
* This function (usually) uses DirDoc to determine if new or existing
* MergeDoc is used. However there is exceptional case when DirDoc does
* not contain diffs. Then we have only file compare, and if we also have
* @param [out] pNew Did we create a new document?
* @return Pointer to merge doucument.
*/
-CMergeDoc * CMainFrame::GetMergeDocToShow(int nFiles, CDirDoc * pDirDoc, BOOL * pNew)
+CMergeDoc * CMainFrame::GetMergeDocToShow(int nFiles, CDirDoc * pDirDoc)
{
const BOOL bMultiDocs = GetOptionsMgr()->GetBool(OPT_MULTIDOC_MERGEDOCS);
const MergeDocList &docs = GetAllMergeDocs();
CMergeDoc * pMergeDoc = docs.GetAt(pos);
pMergeDoc->CloseNow();
}
- CMergeDoc * pMergeDoc = pDirDoc->GetMergeDocForDiff(nFiles, pNew);
+ CMergeDoc * pMergeDoc = GetMergeDocForDiff<CMergeDoc>(theApp.m_pDiffTemplate, pDirDoc, nFiles);
return pMergeDoc;
}
* @param [out] pNew Did we create a new document?
* @return Pointer to merge doucument.
*/
-CHexMergeDoc * CMainFrame::GetHexMergeDocToShow(int nFiles, CDirDoc * pDirDoc, BOOL * pNew)
+CHexMergeDoc * CMainFrame::GetHexMergeDocToShow(int nFiles, CDirDoc * pDirDoc)
{
const BOOL bMultiDocs = GetOptionsMgr()->GetBool(OPT_MULTIDOC_MERGEDOCS);
const HexMergeDocList &docs = GetAllHexMergeDocs();
CHexMergeDoc * pHexMergeDoc = docs.GetAt(pos);
pHexMergeDoc->CloseNow();
}
- CHexMergeDoc * pHexMergeDoc = pDirDoc->GetHexMergeDocForDiff(nFiles, pNew);
+ CHexMergeDoc * pHexMergeDoc = GetMergeDocForDiff<CHexMergeDoc>(theApp.m_pHexMergeTemplate, pDirDoc, nFiles);
return pHexMergeDoc;
}
CFrameWnd * pFrame = GetActiveFrame();
if (pFrame)
{
- if (pFrame->IsKindOf(RUNTIME_CLASS(CChildFrame)))
- {
- CMergeDoc * pMergeDoc = (CMergeDoc *) pFrame->GetActiveDocument();
- if (pMergeDoc)
- pMergeDoc->CheckFileChanged();
- }
- else if (pFrame->IsKindOf(RUNTIME_CLASS(CHexMergeFrame)))
- {
- CHexMergeDoc * pMergeDoc = (CHexMergeDoc *) pFrame->GetActiveDocument();
- if (pMergeDoc)
- pMergeDoc->CheckFileChanged();
- }
- else if (pFrame->IsKindOf(RUNTIME_CLASS(CImgMergeFrame)))
- {
- CImgMergeFrame *pImgMergeFrame = static_cast<CImgMergeFrame *>(pFrame);
- pImgMergeFrame->CheckFileChanged();
- }
+ IMergeDoc *pMergeDoc = dynamic_cast<IMergeDoc *>(pFrame->GetActiveDocument());
+ if (!pMergeDoc)
+ pMergeDoc = dynamic_cast<IMergeDoc *>(pFrame);
+ if (pMergeDoc)
+ pMergeDoc->CheckFileChanged();
}
return 0;
}
CFrameWnd * pFrame = GetActiveFrame();
if (pFrame)
{
- switch (GetFrameType(pFrame))
- {
- case FRAME_FILE:
- {
- CMergeDoc * pMergeDoc = (CMergeDoc *) pFrame->GetActiveDocument();
- if (pMergeDoc)
- PostMessage(WM_USER+1);
- break;
- }
- case FRAME_HEXFILE:
- {
- CHexMergeDoc * pMergeDoc = (CHexMergeDoc *) pFrame->GetActiveDocument();
- if (pMergeDoc)
- PostMessage(WM_USER+1);
- break;
- }
- case FRAME_IMGFILE:
+ IMergeDoc *pMergeDoc = dynamic_cast<IMergeDoc *>(pFrame->GetActiveDocument());
+ if (!pMergeDoc)
+ pMergeDoc = dynamic_cast<IMergeDoc *>(pFrame);
+ if (pMergeDoc)
PostMessage(WM_USER+1);
- break;
- }
}
}
const DirDocList &GetAllDirDocs();
const HexMergeDocList &GetAllHexMergeDocs();
void RedisplayAllDirDocs();
- CMergeDoc * GetMergeDocToShow(int nFiles, CDirDoc * pDirDoc, BOOL * pNew);
- CHexMergeDoc * GetHexMergeDocToShow(int nDirs, CDirDoc * pDirDoc, BOOL * pNew);
+ CMergeDoc * GetMergeDocToShow(int nFiles, CDirDoc * pDirDoc);
+ CHexMergeDoc * GetHexMergeDocToShow(int nDirs, CDirDoc * pDirDoc);
CDirDoc * GetDirDocToShow(int nDirs, BOOL * pNew);
void UpdateFont(FRAMETYPE frame);
BOOL CreateToolbar();
RelativePath=".\IListCtrl.h">\r
</File>\r
<File\r
+ RelativePath=".\IMergeDoc.h">\r
+ </File>\r
+ <File\r
RelativePath="IntToIntMap.h">\r
</File>\r
<File\r
<ClInclude Include="Common\coretools.h" />\r
<ClInclude Include="Common\coretypes.h" />\r
<ClInclude Include="Common\CSubclass.h" />\r
+ <ClInclude Include="IMergeDoc.h" />\r
<ClInclude Include="ImgMergeFrm.h" />\r
<ClInclude Include="Merge7zFormatShellImpl.h" />\r
<ClInclude Include="OptionsCustomColors.h" />\r
<ClInclude Include="PropCompareImage.h">\r
<Filter>MFCGui\Dialogs\PropertyPages</Filter>\r
</ClInclude>\r
+ <ClInclude Include="IMergeDoc.h">\r
+ <Filter>Header Files</Filter>\r
+ </ClInclude>\r
</ItemGroup>\r
<ItemGroup>\r
<None Include="res\binarydiff.ico">\r
#include "TempFile.h"
#include "PathContext.h"
#include "DiffFileInfo.h"
+#include "IMergeDoc.h"
/**
* @brief Additional action codes for WinMerge.
/**
* @brief Document class for merging two files
*/
-class CMergeDoc : public CDocument
+class CMergeDoc : public CDocument, public IMergeDoc
{
public:
enum FileChange
msgstr ""
"Project-Id-Version: WinMerge\n"
"Report-Msgid-Bugs-To: http://bugs.winmerge.org/\n"
-"POT-Creation-Date: 2014-11-03 10:06+0000\n"
+"POT-Creation-Date: 2014-11-05 10:12+0000\n"
"PO-Revision-Date: \n"
"Last-Translator: \n"
"Language-Team: English <winmerge-translate@lists.sourceforge.net>\n"