Skip to content

Commit

Permalink
Add a "Defaults" button to the "Options (Codepage)" dialog. (#2448)
Browse files Browse the repository at this point in the history
  • Loading branch information
tjmprm77 committed Sep 23, 2024
1 parent 3c314cd commit ce86211
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 1 deletion.
4 changes: 3 additions & 1 deletion Src/Merge.rc
Original file line number Diff line number Diff line change
Expand Up @@ -1966,6 +1966,7 @@ BEGIN
CONTROL "Detect codepage for text files with mlang.dll\nNeed to restart session.",IDC_DETECT_CODEPAGE2,
"Button",BS_AUTOCHECKBOX | BS_TOP | BS_MULTILINE | WS_TABSTOP,13,139,269,34
COMBOBOX IDC_DETECT_AUTODETECTTYPE,23,175,247,130,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP
PUSHBUTTON "Defaults", IDC_COMPARE_DEFAULTS, 191, 228, 88, 14
END

IDD_PREFERENCES DIALOGEX 0, 0, 414, 280
Expand Down Expand Up @@ -2901,7 +2902,8 @@ BEGIN
0, 0, 100, 0,
0, 0, 100, 0,
0, 0, 100, 0,
0, 0, 100, 0
0, 0, 100, 0,
100, 0, 0, 0
END

IDD_PROPPAGE_COLOR_SCHEMES AFX_DIALOG_LAYOUT
Expand Down
69 changes: 69 additions & 0 deletions Src/PropCodepage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ void PropCodepage::DoDataExchange(CDataExchange* pDX)

BEGIN_MESSAGE_MAP(PropCodepage, OptionsPanel)
//{{AFX_MSG_MAP(PropCodepage)
ON_BN_CLICKED(IDC_COMPARE_DEFAULTS, OnDefaults)
ON_BN_CLICKED(IDC_CP_SYSTEM, OnCpSystem)
ON_BN_CLICKED(IDC_CP_CUSTOM, OnCpCustom)
ON_BN_CLICKED(IDC_DETECT_CODEPAGE2, OnDetectCodepage2)
Expand Down Expand Up @@ -105,6 +106,7 @@ BOOL PropCodepage::OnInitDialog()
continue;
String desc = strutils::format(_T("% 5d - %s"), cpi[i].codepage, cpi[i].desc);
Index = m_comboCustomCodepageValue.AddString(desc.c_str());
m_comboCustomCodepageValue.SetItemData(static_cast<int>(Index), cpi[i].codepage);
if (cpi[i].codepage == m_nCustomCodepageValue)
m_comboCustomCodepageValue.SetCurSel(static_cast<int>(Index));
}
Expand All @@ -119,6 +121,7 @@ BOOL PropCodepage::OnInitDialog()
if (m_comboCustomCodepageValue.FindStringExact(0, desc.c_str()) == CB_ERR)
{
Index = m_comboCustomCodepageValue.AddString(desc.c_str());
m_comboCustomCodepageValue.SetItemData(static_cast<int>(Index), ManualAddTypeList[i]);
if (ManualAddTypeList[i] == m_nCustomCodepageValue)
m_comboCustomCodepageValue.SetCurSel(static_cast<int>(Index));
}
Expand All @@ -140,6 +143,29 @@ BOOL PropCodepage::OnInitDialog()
// EXCEPTION: OCX Property Pages should return FALSE
}

/**
* @brief Sets options to defaults.
*/
void PropCodepage::OnDefaults()
{
m_nCodepageSystem = GetOptionsMgr()->GetDefault<unsigned>(OPT_CP_DEFAULT_MODE);
m_nCustomCodepageValue = GetOptionsMgr()->GetDefault<unsigned>(OPT_CP_DEFAULT_CUSTOM);
m_cCustomCodepageValue = strutils::to_str(m_nCustomCodepageValue);
m_bDetectCodepage = GetOptionsMgr()->GetDefault<unsigned>(OPT_CP_DETECT) & 1;
m_bDetectCodepage2 = (GetOptionsMgr()->GetDefault<unsigned>(OPT_CP_DETECT) & 2) != 0;
m_nAutodetectType = ((unsigned)GetOptionsMgr()->GetDefault<unsigned>(OPT_CP_DETECT) >> 16);
if (m_nAutodetectType == 0)
m_nAutodetectType = 50001;

UpdateData(FALSE);

UpdateControls();
SetCursorSelectForCustomCodepage(m_nCustomCodepageValue);
SetCursorSelectForAutoDetectType(m_nAutodetectType);

UpdateData(TRUE);
}

void PropCodepage::OnCpSystem()
{
EnableDlgItem(IDC_CUSTOM_CP_NUMBER, false);
Expand Down Expand Up @@ -174,3 +200,46 @@ void PropCodepage::GetEncodingCodePageFromNameString()
if (nCustomCodepageValue)
m_nCustomCodepageValue = nCustomCodepageValue;
}

/**
* @brief Called Updates controls enabled/disables state.
*/
void PropCodepage::UpdateControls()
{
EnableDlgItem(IDC_CUSTOM_CP_NUMBER, IsDlgButtonChecked(IDC_CP_CUSTOM) == 1);
EnableDlgItem(IDC_DETECT_AUTODETECTTYPE, IsDlgButtonChecked(IDC_DETECT_CODEPAGE2) == 1);
}

/**
* @brief Select the item specified by the codepage in the "Custom codepage" combo box.
* @param [in] codepage The codepage of the selected item.
*/
void PropCodepage::SetCursorSelectForCustomCodepage(int codepage)
{
int itemCount = m_comboCustomCodepageValue.GetCount();
for (int i = 0; i < itemCount; i++)
{
if (m_comboCustomCodepageValue.GetItemData(i) == codepage)
{
m_comboCustomCodepageValue.SetCurSel(i);
break;
}
}
}

/**
* @brief Select the item specified by the codepage in the "Auto Detect Type" combo box.
* @param [in] codepage The codepage of the selected item.
*/
void PropCodepage::SetCursorSelectForAutoDetectType(int codepage)
{
int itemCount = m_comboAutodetectType.GetCount();
for (int i = 0; i < itemCount; i++)
{
if (m_comboAutodetectType.GetItemData(i) == codepage)
{
m_comboAutodetectType.SetCurSel(i);
break;
}
}
}
6 changes: 6 additions & 0 deletions Src/PropCodepage.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ class PropCodepage : public OptionsPanel
int m_nAutodetectType;
//}}AFX_DATA

private:
// Implementation methods
void UpdateControls();
void SetCursorSelectForCustomCodepage(int codepage);
void SetCursorSelectForAutoDetectType(int codepage);

// Overrides
// ClassWizard generate virtual function overrides
Expand All @@ -46,6 +51,7 @@ class PropCodepage : public OptionsPanel
//{{AFX_MSG(PropCodepage)
virtual BOOL OnInitDialog() override;
void GetEncodingCodePageFromNameString();
afx_msg void OnDefaults();
afx_msg void OnCpSystem();
afx_msg void OnCpCustom();
afx_msg void OnCpUi();
Expand Down

0 comments on commit ce86211

Please sign in to comment.