Add ability to delete from Find combobox history

When any of the Find window comboboxes are dropped and an entry is highlighted, pressing the Delete key will remove the highlighted entry from the following comboboxes:

1. Find what combobox
2. Replace with combobox
3. Directory combobox
4. Filters combobox

No method is provided for clearing all entries at once, but as the "depth" of the comboboxes is limited to a small amount, clearing one entry at a time (when one wants to clear all) is not overly burdensome.

Fix #9366, close #9396
pull/9405/head
Scott Sumner 4 years ago committed by Don HO
parent 5003a45306
commit b5ec511c38
No known key found for this signature in database
GPG Key ID: 6C429F1D8D84F46E

@ -443,10 +443,9 @@ int FindReplaceDlg::saveComboHistory(int id, int maxcount, vector<generic_string
int count = static_cast<int32_t>(::SendMessage(hCombo, CB_GETCOUNT, 0, 0));
count = min(count, maxcount);
if (count == CB_ERR) return 0;
if (count == CB_ERR) return 0;
if (count)
strings.clear();
strings.clear();
if (saveEmpty)
{
@ -456,7 +455,7 @@ int FindReplaceDlg::saveComboHistory(int id, int maxcount, vector<generic_string
}
}
for (int i = 0 ; i < count ; ++i)
for (int i = 0 ; i < count ; ++i)
{
auto cbTextLen = ::SendMessage(hCombo, CB_GETLBTEXTLEN, i, 0);
if (cbTextLen <= FINDREPLACE_MAXLENGTH - 1)
@ -465,7 +464,7 @@ int FindReplaceDlg::saveComboHistory(int id, int maxcount, vector<generic_string
strings.push_back(generic_string(text));
}
}
return count;
return count;
}
void FindReplaceDlg::updateCombos()
@ -865,12 +864,16 @@ INT_PTR CALLBACK FindReplaceDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM
COMBOBOXINFO cbinfo = { sizeof(COMBOBOXINFO) };
GetComboBoxInfo(hFindCombo, &cbinfo);
originalComboEditProc = SetWindowLongPtr(cbinfo.hwndItem, GWLP_WNDPROC, reinterpret_cast<LONG_PTR>(comboEditProc));
SetWindowLongPtr(cbinfo.hwndItem, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(cbinfo.hwndCombo));
GetComboBoxInfo(hReplaceCombo, &cbinfo);
SetWindowLongPtr(cbinfo.hwndItem, GWLP_WNDPROC, reinterpret_cast<LONG_PTR>(comboEditProc));
SetWindowLongPtr(cbinfo.hwndItem, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(cbinfo.hwndCombo));
GetComboBoxInfo(hFiltersCombo, &cbinfo);
SetWindowLongPtr(cbinfo.hwndItem, GWLP_WNDPROC, reinterpret_cast<LONG_PTR>(comboEditProc));
SetWindowLongPtr(cbinfo.hwndItem, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(cbinfo.hwndCombo));
GetComboBoxInfo(hDirCombo, &cbinfo);
SetWindowLongPtr(cbinfo.hwndItem, GWLP_WNDPROC, reinterpret_cast<LONG_PTR>(comboEditProc));
SetWindowLongPtr(cbinfo.hwndItem, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(cbinfo.hwndCombo));
if ((NppParameters::getInstance()).getNppGUI()._monospacedFontFindDlg)
{
@ -3245,7 +3248,31 @@ LRESULT FAR PASCAL FindReplaceDlg::finderProc(HWND hwnd, UINT message, WPARAM wP
LRESULT FAR PASCAL FindReplaceDlg::comboEditProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
if (message == WM_CHAR && wParam == 0x7F) // ASCII "DEL" (Ctrl+Backspace)
HWND hwndCombo = reinterpret_cast<HWND>(GetWindowLongPtr(hwnd, GWLP_USERDATA));
bool isDropped = ::SendMessage(hwndCombo, CB_GETDROPPEDSTATE, 0, 0) != 0;
if (isDropped && (message == WM_KEYDOWN) && (wParam == VK_DELETE))
{
int curSel = static_cast<int>(::SendMessage(hwndCombo, CB_GETCURSEL, 0, 0));
if (curSel != CB_ERR)
{
int itemsRemaining = static_cast<int>(::SendMessage(hwndCombo, CB_DELETESTRING, curSel, 0));
// if we close the dropdown and reopen it, it will be correctly-sized for remaining items
::SendMessage(hwndCombo, CB_SHOWDROPDOWN, FALSE, 0);
if (itemsRemaining > 0)
{
if (itemsRemaining == curSel)
{
--curSel;
}
::SendMessage(hwndCombo, CB_SETCURSEL, curSel, 0);
::SendMessage(hwndCombo, CB_SHOWDROPDOWN, TRUE, 0);
}
return 0;
}
}
else if (message == WM_CHAR && wParam == 0x7F) // ASCII "DEL" (Ctrl+Backspace)
{
delLeftWordInEdit(hwnd);
return 0;

Loading…
Cancel
Save