Skip to content

Commit

Permalink
Modify the "Line Filters" dialog.
Browse files Browse the repository at this point in the history
- Disable the "Edit" and "Remove" buttons when no filter is selected.
  • Loading branch information
tjmprm77 committed Sep 30, 2023
1 parent d6f48c4 commit 4b6619c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
33 changes: 32 additions & 1 deletion Src/LineFiltersDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ BEGIN_MESSAGE_MAP(LineFiltersDlg, CTrPropertyPage)
ON_NOTIFY(LVN_ITEMACTIVATE, IDC_LFILTER_LIST, OnLvnItemActivateLfilterList)
ON_NOTIFY(LVN_KEYDOWN, IDC_LFILTER_LIST, OnLvnKeyDownLfilterList)
ON_NOTIFY(LVN_ENDLABELEDIT, IDC_LFILTER_LIST, OnEndLabelEditLfilterList)
ON_NOTIFY(LVN_ITEMCHANGED, IDC_LFILTER_LIST, OnLvnItemChangedLfilterList)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

Expand All @@ -70,7 +71,8 @@ BOOL LineFiltersDlg::OnInitDialog()
CTrPropertyPage::OnInitDialog();

InitList();

SetButtonState();

return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
Expand Down Expand Up @@ -236,3 +238,32 @@ void LineFiltersDlg::OnEndLabelEditLfilterList(NMHDR *pNMHDR, LRESULT *pResult)
{
*pResult = 1;
}

/**
* @brief Called when item state is changed.
*
* Disable "Edit" and "Remove" buttons when no item is selected.
* @param [in] pNMHDR Listview item data.
* @param [out] pResult Result of the action is returned in here.
*/
void LineFiltersDlg::OnLvnItemChangedLfilterList(NMHDR* pNMHDR, LRESULT* pResult)
{
LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
if ((pNMLV->uOldState & LVIS_SELECTED) != (pNMLV->uNewState & LVIS_SELECTED))
{
SetButtonState();
}
*pResult = 0;
}

/**
* @brief Disable "Edit" and "Remove" buttons when no item is selected.
*/
void LineFiltersDlg::SetButtonState()
{
int sel = -1;
sel = m_filtersList.GetNextItem(sel, LVNI_SELECTED);
bool bIsSelected = (sel != -1);
EnableDlgItem(IDC_LFILTER_EDITBTN, bIsSelected);
EnableDlgItem(IDC_LFILTER_REMOVEBTN, bIsSelected);
}
3 changes: 3 additions & 0 deletions Src/LineFiltersDlg.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class LineFiltersDlg : public CTrPropertyPage
afx_msg void OnLvnItemActivateLfilterList(NMHDR *pNMHDR, LRESULT *pResult);
afx_msg void OnLvnKeyDownLfilterList(NMHDR *pNMHDR, LRESULT *pResult);
afx_msg void OnEndLabelEditLfilterList(NMHDR *pNMHDR, LRESULT *pResult);
afx_msg void OnLvnItemChangedLfilterList(NMHDR* pNMHDR, LRESULT* pResult);
//}}AFX_MSG
DECLARE_MESSAGE_MAP()

Expand All @@ -63,4 +64,6 @@ class LineFiltersDlg : public CTrPropertyPage
CListCtrl m_filtersList; /**< List control having filter strings */

LineFiltersList * m_pList; /**< Helper list for getting/setting filters. */

void SetButtonState();
};

0 comments on commit 4b6619c

Please sign in to comment.