Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modify the "Go to" dialog. #1896

Merged
merged 1 commit into from
Jun 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions Src/Merge.rc
Original file line number Diff line number Diff line change
Expand Up @@ -1661,16 +1661,17 @@ 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
CONTROL "&Right",IDC_WMGOTO_FILERIGHT,"Button",BS_AUTORADIOBUTTON,13,58,56,10
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
Expand Down
4 changes: 4 additions & 0 deletions Src/MergeEditView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
87 changes: 86 additions & 1 deletion Src/WMGotoDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
};

/////////////////////////////////////////////////////////////////////////////
Expand All @@ -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;
}
Expand All @@ -85,23 +98,95 @@ 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
}


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<int>(m_pimpl->DoModal()); }

2 changes: 2 additions & 0 deletions Src/WMGotoDlg.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
15 changes: 8 additions & 7 deletions Src/resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down