Add a clear button for filter field in Shortcut Mapper

Fix #15742, close #16713
This commit is contained in:
Niranjen P 2025-06-20 02:00:24 +09:30 committed by Don Ho
parent 45ce3418da
commit dddbf24ff5
3 changed files with 27 additions and 5 deletions

View File

@ -543,6 +543,19 @@ void ShortcutMapper::resizeDialogElements()
::GetWindowRect(hFilterEdit, &rcFilterEdit);
::MapWindowPoints(nullptr, _hSelf, reinterpret_cast<LPPOINT>(&rcFilterEdit), 2);
HWND hFilterClearBtn = ::GetDlgItem(_hSelf, IDC_BABYGRID_FILTER_CLEAR);
int clrBtnWidth = rcFilterEdit.bottom - rcFilterEdit.top;
int clrBtnHeight = clrBtnWidth;
int filterEditLeft = rcFilterEdit.left;
int filterEditTop = rcFilterEdit.top;
int filterEditWidth = rcClient.right - filterEditLeft - clrBtnWidth - 5;
int filterEditHeight = clrBtnHeight;
int clrBtnLeft = filterEditLeft + filterEditWidth + 1;
int clrBtnTop = filterEditTop;
RECT rcInfo{};
HWND hInfo = ::GetDlgItem(_hSelf, IDC_BABYGRID_INFO);
::GetWindowRect(hInfo, &rcInfo);
@ -559,10 +572,9 @@ void ShortcutMapper::resizeDialogElements()
::InflateRect(&rcClient, -padding, -(gapBtn + getRcHeight(rcOkBtn)));
const int gapBtnEdit = rcClearBtn.top - rcFilterEdit.bottom;
const int heightFilter = getRcHeight(rcFilterEdit);
const int heightInfo = getRcHeight(rcInfo);
constexpr int nCtrls = 7;
constexpr int nCtrls = 8;
auto hdwp = ::BeginDeferWindowPos(nCtrls);
hdwp = setOrDeferWindowPos(hdwp, hModBtn, nullptr, center - gapBtnHalf - wBtn * 2 - gapBtn, rcClient.bottom, 0, 0, SWP_NOSIZE | flags);
@ -570,9 +582,10 @@ void ShortcutMapper::resizeDialogElements()
hdwp = setOrDeferWindowPos(hdwp, hDelBtn, nullptr, center + gapBtnHalf, rcClient.bottom, 0, 0, SWP_NOSIZE | flags);
hdwp = setOrDeferWindowPos(hdwp, hOkBtn, nullptr, center + gapBtnHalf + wBtn + gapBtn, rcClient.bottom, 0, 0, SWP_NOSIZE | flags);
rcClient.bottom -= (gapBtnEdit + heightFilter);
rcClient.bottom -= (gapBtnEdit + filterEditHeight);
hdwp = setOrDeferWindowPos(hdwp, hStatic, nullptr, rcClient.left, rcClient.bottom + gapBtnEdit / 2, 0, 0, SWP_NOSIZE | flags);
hdwp = setOrDeferWindowPos(hdwp, hFilterEdit, nullptr, rcFilterEdit.left, rcClient.bottom, rcClient.right - rcFilterEdit.left, heightFilter, flags);
hdwp = setOrDeferWindowPos(hdwp, hFilterEdit, nullptr, filterEditLeft, filterEditTop, filterEditWidth, filterEditHeight, flags);
hdwp = setOrDeferWindowPos(hdwp, hFilterClearBtn, nullptr, clrBtnLeft, clrBtnTop, clrBtnWidth, clrBtnHeight, SWP_SHOWWINDOW | SWP_NOACTIVATE | flags);
hdwp = setOrDeferWindowPos(hdwp, hInfo, nullptr, rcClient.left, rcClient.bottom - gapBtnEdit - heightInfo, getRcWidth(rcClient), heightInfo, flags);
if (hdwp)
@ -1360,7 +1373,13 @@ intptr_t CALLBACK ShortcutMapper::run_dlgProc(UINT message, WPARAM wParam, LPARA
}
return TRUE;
}
case IDC_BABYGRID_FILTER_CLEAR:
{
HWND hFilterEdit = ::GetDlgItem(_hSelf, IDC_BABYGRID_FILTER);
::SetWindowText(hFilterEdit, L"");
::SetFocus(hFilterEdit);
return TRUE;
}
default:
{
break;

View File

@ -14,6 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#pragma code_page(65001)
#include <windows.h>
#include "ShortcutMapper_rc.h"
@ -32,6 +33,7 @@ BEGIN
EDITTEXT IDC_BABYGRID_INFO,4,283,442,29,ES_MULTILINE | ES_AUTOHSCROLL | ES_READONLY | WS_VSCROLL | NOT WS_TABSTOP
RTEXT "Filter:",IDC_BABYGRID_STATIC,4,318,25,8
EDITTEXT IDC_BABYGRID_FILTER,32,316,414,12,ES_AUTOHSCROLL | ES_WANTRETURN
PUSHBUTTON "✕", IDC_BABYGRID_FILTER_CLEAR, 440, 316, 12, 12, WS_TABSTOP
PUSHBUTTON "Modify",IDM_BABYGRID_MODIFY,120,333,47,14
PUSHBUTTON "Clear",IDM_BABYGRID_CLEAR,174,333,47,14
PUSHBUTTON "Delete",IDM_BABYGRID_DELETE,228,333,47,14

View File

@ -26,3 +26,4 @@
#define IDM_BABYGRID_CLEAR (IDD_SHORTCUTMAPPER_DLG + 6)
#define IDC_BABYGRID_STATIC (IDD_SHORTCUTMAPPER_DLG + 7)
#define IDC_BABYGRID_FILTER (IDD_SHORTCUTMAPPER_DLG + 8)
#define IDC_BABYGRID_FILTER_CLEAR (IDD_SHORTCUTMAPPER_DLG + 9)