MCPcopy Create free account
hub / github.com/WinMerge/winmerge / ShowTextOrTableMergeDoc

Method ShowTextOrTableMergeDoc

Src/MainFrm.cpp:934–1032  ·  view source on GitHub ↗

* @brief Creates new MergeDoc instance and shows documents. * @param [in] pDirDoc Dir compare document to create a new Merge document for. * @param [in] ifilelocLeft Left side file location info. * @param [in] ifilelocRight Right side file location info. * @param [in] dwLeftFlags Left side flags. * @param [in] dwRightFlags Right side flags. * @param [in] infoUnpacker Plugin info. * @return

Source from the content-addressed store, hash-verified

932 * @return success/failure
933 */
934bool CMainFrame::ShowTextOrTableMergeDoc(std::optional<bool> table, IDirDoc * pDirDoc,
935 int nFiles, const FileLocation ifileloc[],
936 const fileopenflags_t dwFlags[], const String strDesc[], const String& sReportFile /*= _T("")*/,
937 const PackingInfo* infoUnpacker /*= nullptr*/, const PrediffingInfo* infoPrediffer /*= nullptr*/,
938 const OpenTextFileParams* pOpenParams /*= nullptr*/)
939{
940 CMultiDocTemplate* pDiffTemplate = theApp.GetDiffTemplate();
941 if (m_pMenus[MENU_MERGEVIEW] == nullptr)
942 pDiffTemplate->m_hMenuShared = NewMergeViewMenu();
943 CMergeDoc * pMergeDoc = GetMergeDocForDiff<CMergeDoc>(pDiffTemplate, pDirDoc, nFiles, false);
944
945 // Make local copies, so we can change encoding if we guess it below
946 FileLocation fileloc[3];
947 std::copy_n(ifileloc, nFiles, fileloc);
948
949 ASSERT(pMergeDoc != nullptr); // must ASSERT to get an answer to the question below ;-)
950 if (pMergeDoc == nullptr)
951 return false; // when does this happen ?
952
953 // if an unpacker is selected, it must be used during LoadFromFile
954 // MergeDoc must memorize it for SaveToFile
955 // Warning : this unpacker may differ from the pDirDoc one
956 // (through menu : "Plugins"->"Open with unpacker")
957 pMergeDoc->SetUnpacker(infoUnpacker);
958 pMergeDoc->SetPrediffer(infoPrediffer);
959
960 // detect codepage
961 int iGuessEncodingType = GetOptionsMgr()->GetInt(OPT_CP_DETECT);
962 for (int pane = 0; pane < nFiles; pane++)
963 {
964 if (fileloc[pane].encoding.m_unicoding == -1)
965 fileloc[pane].encoding.m_unicoding = ucr::NONE;
966 if (fileloc[pane].encoding.m_unicoding == ucr::NONE && fileloc[pane].encoding.m_codepage == -1)
967 {
968 FileLocationGuessEncodings(fileloc[pane], iGuessEncodingType);
969 }
970 }
971
972 pMergeDoc->SetEnableTableEditing(table);
973 if (pOpenParams && table.value_or(false))
974 {
975 CMergeDoc::TableProps props = CMergeDoc::MakeTablePropertiesByFileName(
976 pOpenParams->m_fileExt.empty() ? fileloc[0].filepath : pOpenParams->m_fileExt, true, false);
977 if (const auto* pOpenTableFileParams = dynamic_cast<const OpenTableFileParams*>(pOpenParams))
978 {
979 props.delimiter = pOpenTableFileParams->m_tableDelimiter.value_or(props.delimiter);
980 props.quote = pOpenTableFileParams->m_tableQuote.value_or(props.quote);
981 props.allowNewlinesInQuotes = pOpenTableFileParams->m_tableAllowNewlinesInQuotes.value_or(props.allowNewlinesInQuotes);
982 }
983 pMergeDoc->SetPreparedTableProperties(props);
984 }
985
986 // Note that OpenDocs() takes care of closing compare window when needed.
987 bool bResult = pMergeDoc->OpenDocs(nFiles, fileloc, GetROFromFlags(nFiles, dwFlags).data(), strDesc);
988 if (bResult)
989 {
990 if (CMergeEditFrame *pFrame = pMergeDoc->GetParentFrame())
991 if (!pFrame->IsActivated())

Callers

nothing calls this directly

Calls 15

GetROFromFlagsFunction · 0.85
GetActivePaneFromFlagsFunction · 0.85
GetDiffTemplateMethod · 0.80
SetEnableTableEditingMethod · 0.80
IsActivatedMethod · 0.80
SetTextTypeMethod · 0.80
SetModifiedMethod · 0.80
GetOptionsMgrFunction · 0.70
SetUnpackerMethod · 0.45
SetPredifferMethod · 0.45

Tested by

no test coverage detected