From 5aef26eb3b5769c4327ebaa29ea56f36aa92fdec Mon Sep 17 00:00:00 2001 From: Jun Tajima <56220423+tjmprm77@users.noreply.github.com> Date: Sun, 11 Jun 2023 19:07:51 +0900 Subject: [PATCH] Modify the "Go to" dialog. - Show the acceptable range for the selected "File" and "Go to what". - Disable the "Go to" button if the input form does not contain a value within the acceptable range. - Disable the "Difference" radio button when the files have no differences (i.e. identical files). --- Src/Merge.rc | 7 ++-- Src/MergeEditView.cpp | 4 ++ Src/WMGotoDlg.cpp | 87 ++++++++++++++++++++++++++++++++++++++++++- Src/WMGotoDlg.h | 2 + Src/resource.h | 15 ++++---- 5 files changed, 104 insertions(+), 11 deletions(-) diff --git a/Src/Merge.rc b/Src/Merge.rc index f60677f343b..b9d2f76ab37 100644 --- a/Src/Merge.rc +++ b/Src/Merge.rc @@ -1661,7 +1661,8 @@ CAPTION "Go to" FONT 8, "MS Shell Dlg", 0, 0, 0x1 BEGIN LTEXT "G&o to:",IDC_STATIC,7,9,68,10 - EDITTEXT IDC_WMGOTO_PARAM,77,7,78,14,ES_AUTOHSCROLL | ES_NUMBER + LTEXT "", IDC_WMGOTO_RANGE,77,9,65,10 + EDITTEXT IDC_WMGOTO_PARAM,146,7,64,14,ES_AUTOHSCROLL | ES_NUMBER GROUPBOX "File",IDC_STATIC,7,27,65,45 CONTROL "&Left",IDC_WMGOTO_FILELEFT,"Button",BS_AUTORADIOBUTTON | WS_GROUP,13,38,56,10 CONTROL "&Middle",IDC_WMGOTO_FILEMIDDLE,"Button",BS_AUTORADIOBUTTON,13,48,56,10 @@ -1669,8 +1670,8 @@ BEGIN GROUPBOX "Go to what",IDC_STATIC,77,27,78,45 CONTROL "Li&ne",IDC_WMGOTO_TOLINE,"Button",BS_AUTORADIOBUTTON | WS_GROUP,84,38,68,10 CONTROL "&Difference",IDC_WMGOTO_TODIFF,"Button",BS_AUTORADIOBUTTON,84,48,68,10 - DEFPUSHBUTTON "&Go to",IDOK,161,7,50,14 - PUSHBUTTON "Cancel",IDCANCEL,161,24,50,14 + DEFPUSHBUTTON "&Go to",IDOK,161,41,50,14 + PUSHBUTTON "Cancel",IDCANCEL,161,58,50,14 END IDD_PROPPAGE_COMPARE DIALOGEX 0, 0, 285, 242 diff --git a/Src/MergeEditView.cpp b/Src/MergeEditView.cpp index 4f2e64138f7..42fb7e6d65f 100644 --- a/Src/MergeEditView.cpp +++ b/Src/MergeEditView.cpp @@ -3047,6 +3047,10 @@ void CMergeEditView::OnWMGoto() dlg.m_nFile = (pDoc->m_nBuffers < 3) ? (m_nThisPane == 1 ? 2 : 0) : m_nThisPane; dlg.m_nGotoWhat = 0; dlg.m_nFiles = pDoc->m_nBuffers; + dlg.m_nLastLine[0] = nLastLine[0] + 1; + dlg.m_nLastLine[1] = (pDoc->m_nBuffers < 3) ? -1 : nLastLine[1] + 1; + dlg.m_nLastLine[2] = (pDoc->m_nBuffers < 3) ? nLastLine[1] + 1: nLastLine[2] + 1; + dlg.m_nLastDiff = pDoc->m_diffList.GetSize(); if (dlg.DoModal() == IDOK) { diff --git a/Src/WMGotoDlg.cpp b/Src/WMGotoDlg.cpp index 144d6178478..af5c34b1b3b 100644 --- a/Src/WMGotoDlg.cpp +++ b/Src/WMGotoDlg.cpp @@ -45,11 +45,18 @@ class WMGotoDlg::Impl : public CTrDialog // Generated message map functions //{{AFX_MSG(WMGotoDlg) // NOTE: the ClassWizard will add member functions here + afx_msg void OnChangeParam(); + afx_msg void OnBnClicked(UINT nID); //}}AFX_MSG DECLARE_MESSAGE_MAP() private: WMGotoDlg *m_p; + String m_strRange; /**< Acceptable range */ + + int GetRangeMax(); + void UpdateRange(); + void UpdateGoToButton(); }; ///////////////////////////////////////////////////////////////////////////// @@ -74,6 +81,12 @@ BOOL WMGotoDlg::Impl::OnInitDialog() if (m_p->m_nFiles < 3) EnableDlgItem(IDC_WMGOTO_FILEMIDDLE, false); + if (m_p->m_nLastDiff == 0) + EnableDlgItem(IDC_WMGOTO_TODIFF, false); + + UpdateRange(); + UpdateGoToButton(); + UpdateData(FALSE); return TRUE; } @@ -85,6 +98,7 @@ void WMGotoDlg::Impl::DoDataExchange(CDataExchange* pDX) DDX_Text(pDX, IDC_WMGOTO_PARAM, m_p->m_strParam); DDX_Radio(pDX, IDC_WMGOTO_FILELEFT, m_p->m_nFile); DDX_Radio(pDX, IDC_WMGOTO_TOLINE, m_p->m_nGotoWhat); + DDX_Text(pDX, IDC_WMGOTO_RANGE, m_strRange); //}}AFX_DATA_MAP } @@ -92,16 +106,87 @@ void WMGotoDlg::Impl::DoDataExchange(CDataExchange* pDX) BEGIN_MESSAGE_MAP(WMGotoDlg::Impl, CTrDialog) //{{AFX_MSG_MAP(WMGotoDlg::Impl) // NOTE: the ClassWizard will add message map macros here + ON_EN_CHANGE(IDC_WMGOTO_PARAM, OnChangeParam) + ON_CONTROL_RANGE(BN_CLICKED, IDC_WMGOTO_FILELEFT, IDC_WMGOTO_FILERIGHT, OnBnClicked) + ON_CONTROL_RANGE(BN_CLICKED, IDC_WMGOTO_TOLINE, IDC_WMGOTO_TODIFF, OnBnClicked) //}}AFX_MSG_MAP END_MESSAGE_MAP() +/** + * @brief Called when the edit string changes. + */ +void WMGotoDlg::Impl::OnChangeParam() +{ + UpdateData(TRUE); + UpdateGoToButton(); +} + +/** + * @brief Called when user selects "File" or "Go to what" radio button. + * @param [in] nID Button ID of the selected item + */ +void WMGotoDlg::Impl::OnBnClicked(UINT nID) +{ + bool bIsValidId = (nID >= IDC_WMGOTO_FILELEFT && nID <= IDC_WMGOTO_FILERIGHT) || (nID >= IDC_WMGOTO_TOLINE && nID <= IDC_WMGOTO_TODIFF); + assert(bIsValidId); + if (!bIsValidId) + return; + + UpdateData(TRUE); + UpdateRange(); + UpdateGoToButton(); + UpdateData(FALSE); +} + +/** + * @brief Get upper bound of acceptable range for selected "File" and "Go to what". + * @return Upper bound of acceptable range for selected "File" and "Go to what". + */ +int WMGotoDlg::Impl::GetRangeMax() +{ + bool bIsValidState = ((m_p->m_nGotoWhat >= 0 && m_p->m_nGotoWhat <= 1) && (m_p->m_nFile >= 0 && m_p->m_nFile <= 2)); + assert(bIsValidState); + if (!bIsValidState) + return -1; + + return (m_p->m_nGotoWhat == 0) ? m_p->m_nLastLine[m_p->m_nFile] : m_p->m_nLastDiff; +} + +/** + * @brief Update the acceptable range. + */ +void WMGotoDlg::Impl::UpdateRange() +{ + int nRangeMax = GetRangeMax(); + m_strRange = (nRangeMax > 0) ? strutils::format(_T("(1-%d)"), nRangeMax) : _T(""); +} + +/** + * @brief Update the enabled state of the "Go to" button. + */ +void WMGotoDlg::Impl::UpdateGoToButton() +{ + int nNum = 0; + try + { + nNum = std::stoi(m_p->m_strParam); + } + catch (...) + { + nNum = 0; + } + + bool bEnable = (nNum > 0 && nNum <= GetRangeMax()); + EnableDlgItem(IDOK, bEnable); +} + ///////////////////////////////////////////////////////////////////////////// // WMGotoDlg message handlers WMGotoDlg::WMGotoDlg() - : m_pimpl(new WMGotoDlg::Impl(this)), m_nFile(-1), m_nGotoWhat(-1), m_nFiles(-1) {} + : m_pimpl(new WMGotoDlg::Impl(this)), m_nFile(-1), m_nGotoWhat(-1), m_nFiles(-1), m_nLastLine{-1, -1, -1}, m_nLastDiff(-1) {} WMGotoDlg::~WMGotoDlg() = default; int WMGotoDlg::DoModal() { return static_cast(m_pimpl->DoModal()); } diff --git a/Src/WMGotoDlg.h b/Src/WMGotoDlg.h index bb9d68b38fd..94187d90653 100644 --- a/Src/WMGotoDlg.h +++ b/Src/WMGotoDlg.h @@ -22,6 +22,8 @@ class WMGotoDlg int m_nFile; /**< Target file number. */ int m_nGotoWhat; /**< Goto line or difference? */ int m_nFiles; /**< Number of files being compared. */ + int m_nLastLine[3]; /**< Last line in each pane. */ + int m_nLastDiff; /**< Last diff. */ private: WMGotoDlg(const WMGotoDlg &) = delete; WMGotoDlg & operator=(const WMGotoDlg &) = delete; diff --git a/Src/resource.h b/Src/resource.h index 2b7f3d74487..7b517e22bec 100644 --- a/Src/resource.h +++ b/Src/resource.h @@ -301,13 +301,14 @@ #define IDC_WMGOTO_TOLINE 1115 #define IDC_WMGOTO_TODIFF 1116 #define IDC_WMGOTO_PARAM 1117 -#define IDC_OPEN_CONTRIBUTORS 1118 -#define IDC_COMPAREMETHODCOMBO 1119 -#define IDC_USE_RECYCLE_BIN 1120 -#define IDC_COMPARE_DEFAULTS 1121 -#define IDC_DIFF_DEFAULTS 1122 -#define IDC_MOVED_BLOCKS 1123 -#define IDC_RESET_ALL_MESSAGE_BOXES 1124 +#define IDC_WMGOTO_RANGE 1118 +#define IDC_OPEN_CONTRIBUTORS 1119 +#define IDC_COMPAREMETHODCOMBO 1120 +#define IDC_USE_RECYCLE_BIN 1121 +#define IDC_COMPARE_DEFAULTS 1122 +#define IDC_DIFF_DEFAULTS 1123 +#define IDC_MOVED_BLOCKS 1124 +#define IDC_RESET_ALL_MESSAGE_BOXES 1125 #define IDC_COLDLG_DEFAULTS 1126 #define IDC_COLDLG_ADDITIONAL_PROPERTIES 1127 #define IDC_OPEN_STATUS 1128