Skip to content

Commit

Permalink
MergeDoc.cpp: Change it to get the Prediffer plugin without depending…
Browse files Browse the repository at this point in the history
… on CDirDoc.
  • Loading branch information
sdottaka committed Sep 24, 2023
1 parent e4e1ddd commit 2252cdb
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 81 deletions.
24 changes: 11 additions & 13 deletions Src/DirView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1415,15 +1415,13 @@ void CDirView::Open(CDirDoc *pDoc, const PathContext& paths, fileopenflags_t dwF
}
}

if (!infoUnpacker)
{
PrediffingInfo* infoPrediffer = nullptr;
String filteredFilenames = CDiffContext::GetFilteredFilenames(filteredPaths);
GetDiffContext().FetchPluginInfos(filteredFilenames, &infoUnpacker, &infoPrediffer);
}
PackingInfo* tmpInfoUnpacker = nullptr;
PrediffingInfo* infoPrediffer = nullptr;
String filteredFilenames = CDiffContext::GetFilteredFilenames(filteredPaths);
GetDiffContext().FetchPluginInfos(filteredFilenames, !infoUnpacker ? &infoUnpacker : &tmpInfoUnpacker, &infoPrediffer);

GetMainFrame()->ShowAutoMergeDoc(0, GetDocument(), paths.GetSize(), fileloc,
dwFlags, strDesc, _T(""), infoUnpacker);
dwFlags, strDesc, _T(""), infoUnpacker, infoPrediffer);
}
}

Expand Down Expand Up @@ -1595,19 +1593,19 @@ void CDirView::OpenSelectionAs(UINT id)
}
dwFlags[pane] |= FFILEOPEN_NOMRU | (pDoc->GetReadOnly(nPane[pane]) ? FFILEOPEN_READONLY : 0);
}
PackingInfo* infoUnpacker = nullptr;
PrediffingInfo* infoPrediffer = nullptr;
GetDiffContext().FetchPluginInfos(CDiffContext::GetFilteredFilenames(filteredPaths), &infoUnpacker, &infoPrediffer);
if (ID_UNPACKERS_FIRST <= id && id <= ID_UNPACKERS_LAST)
{
PackingInfo infoUnpacker(
PackingInfo infoUnpackerAlt(
CMainFrame::GetPluginPipelineByMenuId(id, FileTransform::UnpackerEventNames, ID_UNPACKERS_FIRST));
GetMainFrame()->DoFileOrFolderOpen(&paths, dwFlags, strDesc, _T(""),
ctxt.m_bRecursive, nullptr, &infoUnpacker, nullptr, 0);
ctxt.m_bRecursive, nullptr, &infoUnpackerAlt, infoPrediffer, 0);
}
else
{
PackingInfo* infoUnpacker = nullptr;
PrediffingInfo* infoPrediffer = nullptr;
GetDiffContext().FetchPluginInfos(CDiffContext::GetFilteredFilenames(filteredPaths), &infoUnpacker, &infoPrediffer);
GetMainFrame()->ShowMergeDoc(id, pDoc, paths.GetSize(), fileloc, dwFlags, strDesc, _T(""), infoUnpacker);
GetMainFrame()->ShowMergeDoc(id, pDoc, paths.GetSize(), fileloc, dwFlags, strDesc, _T(""), infoUnpacker, infoPrediffer);
}
}

Expand Down
100 changes: 45 additions & 55 deletions Src/MainFrm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -770,10 +770,9 @@ FileLocationGuessEncodings(FileLocation & fileloc, int iGuessEncoding)
bool CMainFrame::ShowAutoMergeDoc(UINT nID, CDirDoc * pDirDoc,
int nFiles, const FileLocation ifileloc[],
const fileopenflags_t dwFlags[], const String strDesc[], const String& sReportFile /*= _T("")*/,
const PackingInfo * infoUnpacker /*= nullptr*/, const OpenFileParams* pOpenParams /*= nullptr*/)
const PackingInfo* infoUnpacker /*= nullptr*/, const PrediffingInfo* infoPrediffer /*= nullptr*/,
const OpenFileParams* pOpenParams /*= nullptr*/)
{
ASSERT(pDirDoc != nullptr);

if (sReportFile.empty() && pDirDoc->CompareFilesIfFilesAreLarge(nFiles, ifileloc))
return false;

Expand All @@ -799,60 +798,66 @@ bool CMainFrame::ShowAutoMergeDoc(UINT nID, CDirDoc * pDirDoc,
for (int pane = 0; pane < nFiles; ++pane)
{
if (CWebPageDiffFrame::MatchURLPattern(ifileloc[pane].filepath))
return ShowWebDiffDoc(pDirDoc, nFiles, ifileloc, dwFlags, strDesc, sReportFile, infoUnpacker, dynamic_cast<const OpenWebPageParams*>(pOpenParams));
return ShowWebDiffDoc(pDirDoc, nFiles, ifileloc, dwFlags, strDesc, sReportFile, infoUnpacker, infoPrediffer, dynamic_cast<const OpenWebPageParams*>(pOpenParams));
String filepath = ifileloc[pane].filepath + unpackedFileExtension;
if (filterImg.includeFile(filepath) && CImgMergeFrame::IsLoadable())
return ShowImgMergeDoc(pDirDoc, nFiles, ifileloc, dwFlags, strDesc, sReportFile, infoUnpacker, dynamic_cast<const OpenImageFileParams *>(pOpenParams));
return ShowImgMergeDoc(pDirDoc, nFiles, ifileloc, dwFlags, strDesc, sReportFile, infoUnpacker, infoPrediffer, dynamic_cast<const OpenImageFileParams *>(pOpenParams));
else if (filterBin.includeFile(filepath) && CHexMergeView::IsLoadable())
return ShowHexMergeDoc(pDirDoc, nFiles, ifileloc, dwFlags, strDesc, sReportFile, infoUnpacker, dynamic_cast<const OpenBinaryFileParams *>(pOpenParams));
return ShowHexMergeDoc(pDirDoc, nFiles, ifileloc, dwFlags, strDesc, sReportFile, infoUnpacker, infoPrediffer, dynamic_cast<const OpenBinaryFileParams *>(pOpenParams));
}
switch (std::abs(static_cast<int>(nID)))
{
case ID_MERGE_COMPARE_TEXT:
return ShowTextMergeDoc(pDirDoc, nFiles, ifileloc, dwFlags,
strDesc, sReportFile, infoUnpacker, dynamic_cast<const OpenTextFileParams*>(pOpenParams));
strDesc, sReportFile, infoUnpacker, infoPrediffer, dynamic_cast<const OpenTextFileParams*>(pOpenParams));
case ID_MERGE_COMPARE_TABLE:
return ShowTableMergeDoc(pDirDoc, nFiles, ifileloc, dwFlags,
strDesc, sReportFile, infoUnpacker, dynamic_cast<const OpenTextFileParams*>(pOpenParams));
strDesc, sReportFile, infoUnpacker, infoPrediffer, dynamic_cast<const OpenTextFileParams*>(pOpenParams));
case ID_MERGE_COMPARE_HEX:
return ShowHexMergeDoc(pDirDoc, nFiles, ifileloc, dwFlags,
strDesc, sReportFile, infoUnpacker, dynamic_cast<const OpenBinaryFileParams*>(pOpenParams));
strDesc, sReportFile, infoUnpacker, infoPrediffer, dynamic_cast<const OpenBinaryFileParams*>(pOpenParams));
case ID_MERGE_COMPARE_IMAGE:
return ShowImgMergeDoc(pDirDoc, nFiles, ifileloc, dwFlags,
strDesc, sReportFile, infoUnpacker, dynamic_cast<const OpenImageFileParams*>(pOpenParams));
strDesc, sReportFile, infoUnpacker, infoPrediffer, dynamic_cast<const OpenImageFileParams*>(pOpenParams));
case ID_MERGE_COMPARE_WEBPAGE:
return ShowWebDiffDoc(pDirDoc, nFiles, ifileloc, dwFlags,
strDesc, sReportFile, infoUnpacker, dynamic_cast<const OpenWebPageParams*>(pOpenParams));
strDesc, sReportFile, infoUnpacker, infoPrediffer, dynamic_cast<const OpenWebPageParams*>(pOpenParams));
default:
return ShowTextOrTableMergeDoc({}, pDirDoc, nFiles, ifileloc, dwFlags, strDesc, sReportFile, infoUnpacker, dynamic_cast<const OpenTextFileParams*>(pOpenParams));
return ShowTextOrTableMergeDoc({}, pDirDoc, nFiles, ifileloc, dwFlags, strDesc, sReportFile, infoUnpacker, infoPrediffer, dynamic_cast<const OpenTextFileParams*>(pOpenParams));
}
}

bool CMainFrame::ShowMergeDoc(UINT nID, CDirDoc* pDirDoc,
int nFiles, const FileLocation ifileloc[],
const fileopenflags_t dwFlags[], const String strDesc[], const String& sReportFile /*= _T("")*/,
const PackingInfo* infoUnpacker /*= nullptr*/, const OpenFileParams* pOpenParams /*= nullptr*/)
const PackingInfo* infoUnpacker /*= nullptr*/, const PrediffingInfo* infoPrediffer /*= nullptr*/,
const OpenFileParams* pOpenParams /*= nullptr*/)
{
switch (nID)
{
case ID_MERGE_COMPARE_TEXT:
return ShowTextMergeDoc(pDirDoc, nFiles, ifileloc, dwFlags,
strDesc, sReportFile, infoUnpacker, dynamic_cast<const OpenTextFileParams*>(pOpenParams));
strDesc, sReportFile, infoUnpacker, infoPrediffer,
dynamic_cast<const OpenTextFileParams*>(pOpenParams));
case ID_MERGE_COMPARE_TABLE:
return ShowTableMergeDoc(pDirDoc, nFiles, ifileloc, dwFlags,
strDesc, sReportFile, infoUnpacker, dynamic_cast<const OpenTextFileParams*>(pOpenParams));
strDesc, sReportFile, infoUnpacker, infoPrediffer,
dynamic_cast<const OpenTextFileParams*>(pOpenParams));
case ID_MERGE_COMPARE_HEX:
return ShowHexMergeDoc(pDirDoc, nFiles, ifileloc, dwFlags,
strDesc, sReportFile, infoUnpacker, dynamic_cast<const OpenBinaryFileParams*>(pOpenParams));
strDesc, sReportFile, infoUnpacker, infoPrediffer,
dynamic_cast<const OpenBinaryFileParams*>(pOpenParams));
case ID_MERGE_COMPARE_IMAGE:
return ShowImgMergeDoc(pDirDoc, nFiles, ifileloc, dwFlags,
strDesc, sReportFile, infoUnpacker, dynamic_cast<const OpenImageFileParams*>(pOpenParams));
strDesc, sReportFile, infoUnpacker, infoPrediffer,
dynamic_cast<const OpenImageFileParams*>(pOpenParams));
case ID_MERGE_COMPARE_WEBPAGE:
return ShowWebDiffDoc(pDirDoc, nFiles, ifileloc, dwFlags,
strDesc, sReportFile, infoUnpacker, dynamic_cast<const OpenWebPageParams*>(pOpenParams));
strDesc, sReportFile, infoUnpacker, infoPrediffer,
dynamic_cast<const OpenWebPageParams*>(pOpenParams));
default:
return ShowAutoMergeDoc(nID, pDirDoc, nFiles, ifileloc, dwFlags,
strDesc, sReportFile, infoUnpacker, pOpenParams);
strDesc, sReportFile, infoUnpacker, infoPrediffer, pOpenParams);
}
}

Expand Down Expand Up @@ -891,7 +896,8 @@ int GetActivePaneFromFlags(int nFiles, const fileopenflags_t dwFlags[])
bool CMainFrame::ShowTextOrTableMergeDoc(std::optional<bool> table, CDirDoc * pDirDoc,
int nFiles, const FileLocation ifileloc[],
const fileopenflags_t dwFlags[], const String strDesc[], const String& sReportFile /*= _T("")*/,
const PackingInfo * infoUnpacker /*= nullptr*/, const OpenTextFileParams* pOpenParams /*= nullptr*/)
const PackingInfo* infoUnpacker /*= nullptr*/, const PrediffingInfo* infoPrediffer /*= nullptr*/,
const OpenTextFileParams* pOpenParams /*= nullptr*/)
{
CMultiDocTemplate* pDiffTemplate = theApp.GetDiffTemplate();
if (m_pMenus[MENU_MERGEVIEW] == nullptr)
Expand All @@ -911,6 +917,7 @@ bool CMainFrame::ShowTextOrTableMergeDoc(std::optional<bool> table, CDirDoc * pD
// Warning : this unpacker may differ from the pDirDoc one
// (through menu : "Plugins"->"Open with unpacker")
pMergeDoc->SetUnpacker(infoUnpacker);
pMergeDoc->SetPrediffer(infoPrediffer);

// detect codepage
int iGuessEncodingType = GetOptionsMgr()->GetInt(OPT_CP_DETECT);
Expand Down Expand Up @@ -989,22 +996,25 @@ bool CMainFrame::ShowTextOrTableMergeDoc(std::optional<bool> table, CDirDoc * pD
bool CMainFrame::ShowTextMergeDoc(CDirDoc* pDirDoc,
int nFiles, const FileLocation ifileloc[],
const fileopenflags_t dwFlags[], const String strDesc[], const String& sReportFile /*= _T("")*/,
const PackingInfo* infoUnpacker /*= nullptr*/, const OpenTextFileParams* pOpenParams /*= nullptr*/)
const PackingInfo* infoUnpacker /*= nullptr*/, const PrediffingInfo* infoPrediffer /*= nullptr*/,
const OpenTextFileParams* pOpenParams /*= nullptr*/)
{
return ShowTextOrTableMergeDoc(false, pDirDoc, nFiles, ifileloc, dwFlags, strDesc, sReportFile, infoUnpacker, pOpenParams);
return ShowTextOrTableMergeDoc(false, pDirDoc, nFiles, ifileloc, dwFlags, strDesc, sReportFile, infoUnpacker, infoPrediffer, pOpenParams);
}

bool CMainFrame::ShowTableMergeDoc(CDirDoc* pDirDoc,
int nFiles, const FileLocation ifileloc[],
const fileopenflags_t dwFlags[], const String strDesc[], const String& sReportFile /*= _T("")*/,
const PackingInfo* infoUnpacker /*= nullptr*/, const OpenTextFileParams* pOpenParams /*= nullptr*/)
const PackingInfo* infoUnpacker /*= nullptr*/, const PrediffingInfo* infoPrediffer /*= nullptr*/,
const OpenTextFileParams* pOpenParams /*= nullptr*/)
{
return ShowTextOrTableMergeDoc(true, pDirDoc, nFiles, ifileloc, dwFlags, strDesc, sReportFile, infoUnpacker, pOpenParams);
return ShowTextOrTableMergeDoc(true, pDirDoc, nFiles, ifileloc, dwFlags, strDesc, sReportFile, infoUnpacker, infoPrediffer, pOpenParams);
}

bool CMainFrame::ShowHexMergeDoc(CDirDoc * pDirDoc, int nFiles, const FileLocation fileloc[],
const fileopenflags_t dwFlags[], const String strDesc[], const String& sReportFile /*= _T("")*/,
const PackingInfo * infoUnpacker /*= nullptr*/, const OpenBinaryFileParams* pOpenParams /*= nullptr*/)
const PackingInfo* infoUnpacker /*= nullptr*/, const PrediffingInfo* infoPrediffer /*= nullptr*/,
const OpenBinaryFileParams* pOpenParams /*= nullptr*/)
{
CMultiDocTemplate* pHexMergeTemplate = theApp.GetHexMergeTemplate();
if (m_pMenus[MENU_HEXMERGEVIEW] == nullptr)
Expand All @@ -1031,7 +1041,8 @@ bool CMainFrame::ShowHexMergeDoc(CDirDoc * pDirDoc, int nFiles, const FileLocati

bool CMainFrame::ShowImgMergeDoc(CDirDoc * pDirDoc, int nFiles, const FileLocation fileloc[],
const fileopenflags_t dwFlags[], const String strDesc[], const String& sReportFile /*= _T("")*/,
const PackingInfo * infoUnpacker /*= nullptr*/, const OpenImageFileParams* pOpenParams /*= nullptr*/)
const PackingInfo* infoUnpacker /*= nullptr*/, const PrediffingInfo* infoPrediffer /*= nullptr*/,
const OpenImageFileParams* pOpenParams /*= nullptr*/)
{
CImgMergeFrame *pImgMergeFrame = new CImgMergeFrame();
if (!CImgMergeFrame::menu.m_hMenu)
Expand Down Expand Up @@ -1063,7 +1074,8 @@ bool CMainFrame::ShowImgMergeDoc(CDirDoc * pDirDoc, int nFiles, const FileLocati

bool CMainFrame::ShowWebDiffDoc(CDirDoc * pDirDoc, int nFiles, const FileLocation fileloc[],
const fileopenflags_t dwFlags[], const String strDesc[], const String& sReportFile /*= _T("")*/,
const PackingInfo * infoUnpacker /*= nullptr*/, const OpenWebPageParams* pOpenParams /*= nullptr*/)
const PackingInfo* infoUnpacker /*= nullptr*/, const PrediffingInfo* infoPrediffer /*= nullptr*/,
const OpenWebPageParams* pOpenParams /*= nullptr*/)
{
CWebPageDiffFrame *pWebPageMergeFrame = new CWebPageDiffFrame();
if (!CWebPageDiffFrame::menu.m_hMenu)
Expand Down Expand Up @@ -1097,8 +1109,6 @@ bool CMainFrame::ShowTextMergeDoc(CDirDoc* pDirDoc, int nBuffers, const String t
{
FileLocation fileloc[3];
fileopenflags_t dwFlags[3] = {};
CDirDoc* pDirDoc2 = pDirDoc->GetMainView() ? pDirDoc :
static_cast<CDirDoc*>(theApp.GetDirTemplate()->CreateNewDocument());
m_tempFiles.reserve(nBuffers);
for (int nBuffer = 0; nBuffer < nBuffers; ++nBuffer)
{
Expand All @@ -1113,7 +1123,7 @@ bool CMainFrame::ShowTextMergeDoc(CDirDoc* pDirDoc, int nBuffers, const String t
}
fileloc[nBuffer].setPath(workFile);
}
return ShowTextMergeDoc(pDirDoc2, nBuffers, fileloc, dwFlags, strDesc, _T(""), nullptr, pOpenParams);
return ShowTextMergeDoc(pDirDoc, nBuffers, fileloc, dwFlags, strDesc, _T(""), nullptr, nullptr, pOpenParams);
}

/**
Expand Down Expand Up @@ -1399,10 +1409,6 @@ bool CMainFrame::DoFileOrFolderOpen(const PathContext * pFiles /*= nullptr*/,
pDirTemplate->m_hMenuShared = NewDirViewMenu();
pDirDoc = static_cast<CDirDoc*>(pDirTemplate->OpenDocumentFile(nullptr));
}
else
{
pDirDoc = static_cast<CDirDoc*>(pDirTemplate->CreateNewDocument());
}
}

// open the diff
Expand Down Expand Up @@ -1433,14 +1439,8 @@ bool CMainFrame::DoFileOrFolderOpen(const PathContext * pFiles /*= nullptr*/,
for (int nPane = 0; nPane < tFiles.GetSize(); nPane++)
fileloc[nPane].setPath(tFiles[nPane]);

if (infoPrediffer && !infoPrediffer->GetPluginPipeline().empty())
{
String strBothFilenames = strutils::join(tFiles.begin(), tFiles.end(), _T("|"));
pDirDoc->GetPluginManager().SetPrediffer(strBothFilenames, infoPrediffer->GetPluginPipeline());
}

ShowMergeDoc(nID, pDirDoc, tFiles.GetSize(), fileloc, dwFlags, strDesc, sReportFile,
infoUnpacker, pOpenParams);
infoUnpacker, infoPrediffer, pOpenParams);
}

if (pFiles != nullptr && (!dwFlags || !(dwFlags[0] & FFILEOPEN_NOMRU)))
Expand All @@ -1460,17 +1460,11 @@ bool CMainFrame::DoFileOpen(UINT nID, const PathContext* pFiles,
const OpenFileParams *pOpenParams /*= nullptr*/)
{
ASSERT(pFiles != nullptr);
CDirDoc* pDirDoc = static_cast<CDirDoc*>(theApp.GetDirTemplate()->CreateNewDocument());
FileLocation fileloc[3];
for (int pane = 0; pane < pFiles->GetSize(); pane++)
fileloc[pane].setPath((*pFiles)[pane]);
if (infoPrediffer && !infoPrediffer->GetPluginPipeline().empty())
{
String strBothFilenames = strutils::join(pFiles->begin(), pFiles->end(), _T("|"));
pDirDoc->GetPluginManager().SetPrediffer(strBothFilenames, infoPrediffer->GetPluginPipeline());
}
bool result = ShowMergeDoc(nID, pDirDoc, pFiles->GetSize(), fileloc,
dwFlags, strDesc, sReportFile, infoUnpacker, pOpenParams);
bool result = ShowMergeDoc(nID, nullptr, pFiles->GetSize(), fileloc,
dwFlags, strDesc, sReportFile, infoUnpacker, infoPrediffer, pOpenParams);
if (!dwFlags || !(dwFlags[0] & FFILEOPEN_NOMRU))
AddToRecentDocs(*pFiles, (unsigned *)dwFlags, strDesc, false, _T(""), infoUnpacker, infoPrediffer, nID, pOpenParams);
return result;
Expand Down Expand Up @@ -1790,7 +1784,7 @@ DocClass * GetMergeDocForDiff(CMultiDocTemplate *pTemplate, CDirDoc *pDirDoc, in
// Create a new merge doc
DocClass::m_nBuffersTemp = nFiles;
DocClass *pMergeDoc = static_cast<DocClass*>(pTemplate->OpenDocumentFile(nullptr, bMakeVisible));
if (pMergeDoc != nullptr)
if (pMergeDoc != nullptr && pDirDoc != nullptr)
{
pDirDoc->AddMergeDoc(pMergeDoc);
pMergeDoc->SetDirDoc(pDirDoc);
Expand Down Expand Up @@ -2005,8 +1999,6 @@ bool CMainFrame::DoFileNew(UINT nID, int nPanes,
const PrediffingInfo *infoPrediffer /*= nullptr*/,
const OpenFileParams *pOpenParams)
{
CDirDoc *pDirDoc = static_cast<CDirDoc*>(theApp.GetDirTemplate()->CreateNewDocument());

// Load emptyfile descriptors and open empty docs
// Use default codepage
FileLocation fileloc[3];
Expand All @@ -2028,9 +2020,7 @@ bool CMainFrame::DoFileNew(UINT nID, int nPanes,
strDesc2[i] = strDesc[i];
fileloc[i].encoding.SetCodepage(ucr::getDefaultCodepage());
}
if (infoPrediffer && !infoPrediffer->GetPluginPipeline().empty())
pDirDoc->GetPluginManager().SetPrediffer(_T("|"), infoPrediffer->GetPluginPipeline());
return ShowMergeDoc(nID, pDirDoc, nPanes, fileloc, dwFlags, strDesc2, _T(""), nullptr, pOpenParams);
return ShowMergeDoc(nID, nullptr, nPanes, fileloc, dwFlags, strDesc2, _T(""), nullptr, infoPrediffer, pOpenParams);
}

/**
Expand Down
Loading

0 comments on commit 2252cdb

Please sign in to comment.