1 /////////////////////////////////////////////////////////////////////////////
2 // WinMerge: an interactive diff/merge utility
3 // Copyright (C) 1997-2000 Thingamahoochie Software
5 // SPDX-License-Identifier: GPL-2.0-or-later
6 /////////////////////////////////////////////////////////////////////////////
8 * @file MergeDocEncoding.cpp
10 * @brief Implementation file for CMergeDoc
16 #include "MergeEditView.h"
17 #include "LoadSaveCodepageDlg.h"
26 * @brief Display file encoding dialog to user & handle user's choices
28 bool CMergeDoc::DoFileEncodingDialog(int pane)
30 if (!PromptAndSaveIfNeeded(true))
33 CLoadSaveCodepageDlg dlg(m_nBuffers);
34 dlg.EnableSaveCodepage(true);
37 dlg.SetCodepages(m_ptBuf[0]->getCodepage());
38 dlg.SetCodepageBOM(m_ptBuf[0]->getHasBom());
42 dlg.SetCodepages(m_ptBuf[pane]->getCodepage());
43 dlg.SetCodepageBOM(m_ptBuf[pane]->getHasBom());
46 dlg.SetAffectMiddle(false);
47 dlg.SetAffectRight(false);
49 if (m_nBuffers > 2 && pane == 1)
51 dlg.SetAffectLeft(false);
52 dlg.SetAffectRight(false);
54 if (pane == m_nBuffers - 1)
56 dlg.SetAffectLeft(false);
57 dlg.SetAffectMiddle(false);
60 if (IDOK != dlg.DoModal())
63 bool doLeft = dlg.DoesAffectLeft();
64 bool doMiddle = dlg.DoesAffectMiddle();
65 bool doRight = dlg.DoesAffectRight();
66 FileLocation fileloc[3];
68 for (pane = 0; pane < m_nBuffers; pane++)
70 bRO[pane] = m_ptBuf[pane]->GetReadOnly();
71 if ((pane == 0 && doLeft) ||
72 (pane == 1 && doRight && m_nBuffers < 3) ||
73 (pane == 1 && doMiddle && m_nBuffers == 3) ||
74 (pane == 2 && doRight && m_nBuffers == 3))
76 fileloc[pane].encoding.SetCodepage(dlg.GetLoadCodepage());
77 switch (fileloc[pane].encoding.m_unicoding)
82 m_ptBuf[pane]->setHasBom(dlg.GetSaveCodepageBOM());
90 fileloc[pane].encoding.m_unicoding = m_ptBuf[pane]->getUnicoding();
91 fileloc[pane].encoding.m_codepage = m_ptBuf[pane]->getCodepage();
93 fileloc[pane].setPath(m_filePaths[pane]);
95 OpenDocs(m_nBuffers, fileloc, bRO, m_strDesc);
97 if (dlg.GetSaveCodepage() != dlg.GetLoadCodepage() || m_ptBuf[0]->getHasBom() != dlg.GetSaveCodepageBOM())
99 int nSaveCodepage = dlg.GetSaveCodepage();
100 for (pane = 0; pane < m_nBuffers; pane++)
102 bRO[pane] = m_ptBuf[pane]->GetReadOnly();
104 (pane == 0 && doLeft) ||
105 (pane == 1 && doRight && m_nBuffers < 3) ||
106 (pane == 1 && doMiddle && m_nBuffers == 3) ||
107 (pane == 2 && doRight && m_nBuffers == 3)
110 switch (nSaveCodepage)
115 m_ptBuf[pane]->setHasBom(dlg.GetSaveCodepageBOM());
120 m_ptBuf[pane]->setCodepage(nSaveCodepage);
121 m_ptBuf[pane]->SetModified();
122 UpdateHeaderPath(pane);
123 ForEachView([](auto& pView) { pView->UpdateStatusbar(); });