From ce862115140c1fb6138eb288d012297f44ca213e Mon Sep 17 00:00:00 2001 From: Jun Tajima <56220423+tjmprm77@users.noreply.github.com> Date: Mon, 23 Sep 2024 20:12:50 +0900 Subject: [PATCH] Add a "Defaults" button to the "Options (Codepage)" dialog. (#2448) --- Src/Merge.rc | 4 ++- Src/PropCodepage.cpp | 69 ++++++++++++++++++++++++++++++++++++++++++++ Src/PropCodepage.h | 6 ++++ 3 files changed, 78 insertions(+), 1 deletion(-) diff --git a/Src/Merge.rc b/Src/Merge.rc index bdb8ee25088..52e7a040dc5 100644 --- a/Src/Merge.rc +++ b/Src/Merge.rc @@ -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 @@ -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 diff --git a/Src/PropCodepage.cpp b/Src/PropCodepage.cpp index 01044f76b10..6919bbc9206 100644 --- a/Src/PropCodepage.cpp +++ b/Src/PropCodepage.cpp @@ -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) @@ -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(Index), cpi[i].codepage); if (cpi[i].codepage == m_nCustomCodepageValue) m_comboCustomCodepageValue.SetCurSel(static_cast(Index)); } @@ -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(Index), ManualAddTypeList[i]); if (ManualAddTypeList[i] == m_nCustomCodepageValue) m_comboCustomCodepageValue.SetCurSel(static_cast(Index)); } @@ -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(OPT_CP_DEFAULT_MODE); + m_nCustomCodepageValue = GetOptionsMgr()->GetDefault(OPT_CP_DEFAULT_CUSTOM); + m_cCustomCodepageValue = strutils::to_str(m_nCustomCodepageValue); + m_bDetectCodepage = GetOptionsMgr()->GetDefault(OPT_CP_DETECT) & 1; + m_bDetectCodepage2 = (GetOptionsMgr()->GetDefault(OPT_CP_DETECT) & 2) != 0; + m_nAutodetectType = ((unsigned)GetOptionsMgr()->GetDefault(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); @@ -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; + } + } +} diff --git a/Src/PropCodepage.h b/Src/PropCodepage.h index ac67678d96c..e990d3bc19d 100644 --- a/Src/PropCodepage.h +++ b/Src/PropCodepage.h @@ -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 @@ -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();