Skip to content

Commit

Permalink
Modify the "File Filters" dialog. (#2118)
Browse files Browse the repository at this point in the history
- Disable the "Test", "Edit" and "Remove" buttons when no filter is selected in addition to when "None" filter is selected.
  • Loading branch information
tjmprm77 authored Nov 23, 2023
1 parent 1ecd713 commit 550f773
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 11 deletions.
39 changes: 28 additions & 11 deletions Src/FileFiltersDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,8 @@ BOOL FileFiltersDlg::OnInitDialog()
}
}

SetButtonState();

return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
Expand Down Expand Up @@ -282,25 +284,18 @@ bool FileFiltersDlg::IsFilterItemNone(int item) const
/**
* @brief Called when item state is changed.
*
* Disable Edit-button when "None" filter is selected.
* Disable the "Test", "Edit" and "Remove" buttons when no item is selected or "None" filter is selected.
* @param [in] pNMHDR Listview item data.
* @param [out] pResult Result of the action is returned in here.
*/
void FileFiltersDlg::OnLvnItemchangedFilterfileList(NMHDR *pNMHDR, LRESULT *pResult)
{
LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);

// If item got selected
if (pNMLV->uNewState & LVIS_SELECTED)
// If item got selected or deselected
if ((pNMLV->uNewState & LVIS_SELECTED) || (pNMLV->uOldState & LVIS_SELECTED))
{
String txtNone = _("<None>");
String txt = m_listFilters.GetItemText(pNMLV->iItem, 0);

bool isNone = strutils::compare_nocase(txt, txtNone) == 0;

EnableDlgItem(IDC_FILTERFILE_TEST_BTN, !isNone);
EnableDlgItem(IDC_FILTERFILE_EDITBTN, !isNone);
EnableDlgItem(IDC_FILTERFILE_DELETEBTN, !isNone);
SetButtonState();
}
*pResult = 0;
}
Expand Down Expand Up @@ -525,6 +520,7 @@ void FileFiltersDlg::OnBnClickedFilterfileDelete()
}
}
}
SetButtonState();
}

/**
Expand Down Expand Up @@ -609,3 +605,24 @@ void FileFiltersDlg::OnBnClickedFilterfileInstall()
}
}
}

/**
* @brief Disable the "Test", "Edit" and "Remove" buttons when no item is selected or "None" filter is selected.
*/
void FileFiltersDlg::SetButtonState()
{
bool isNone = true;

int sel = -1;
sel = m_listFilters.GetNextItem(sel, LVNI_SELECTED);
if (sel != -1)
{
String txtNone = _("<None>");
String txt = m_listFilters.GetItemText(sel, 0);
isNone = strutils::compare_nocase(txt, txtNone) == 0;
}

EnableDlgItem(IDC_FILTERFILE_TEST_BTN, !isNone);
EnableDlgItem(IDC_FILTERFILE_EDITBTN, !isNone);
EnableDlgItem(IDC_FILTERFILE_DELETEBTN, !isNone);
}
3 changes: 3 additions & 0 deletions Src/FileFiltersDlg.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,7 @@ class FileFiltersDlg : public CTrPropertyPage
afx_msg void OnBnClickedFilterfileInstall();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()

private:
void SetButtonState();
};

0 comments on commit 550f773

Please sign in to comment.