From dddbf24ff55a7e7562372899ec0b5c52619ecf67 Mon Sep 17 00:00:00 2001 From: Niranjen P Date: Fri, 20 Jun 2025 02:00:24 +0930 Subject: [PATCH] Add a clear button for filter field in Shortcut Mapper Fix #15742, close #16713 --- .../src/WinControls/Grid/ShortcutMapper.cpp | 29 +++++++++++++++---- .../src/WinControls/Grid/ShortcutMapper.rc | 2 ++ .../src/WinControls/Grid/ShortcutMapper_rc.h | 1 + 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/PowerEditor/src/WinControls/Grid/ShortcutMapper.cpp b/PowerEditor/src/WinControls/Grid/ShortcutMapper.cpp index a1dafc7ec..e7c20a650 100644 --- a/PowerEditor/src/WinControls/Grid/ShortcutMapper.cpp +++ b/PowerEditor/src/WinControls/Grid/ShortcutMapper.cpp @@ -543,6 +543,19 @@ void ShortcutMapper::resizeDialogElements() ::GetWindowRect(hFilterEdit, &rcFilterEdit); ::MapWindowPoints(nullptr, _hSelf, reinterpret_cast(&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; diff --git a/PowerEditor/src/WinControls/Grid/ShortcutMapper.rc b/PowerEditor/src/WinControls/Grid/ShortcutMapper.rc index 3ab92d773..cccb66292 100755 --- a/PowerEditor/src/WinControls/Grid/ShortcutMapper.rc +++ b/PowerEditor/src/WinControls/Grid/ShortcutMapper.rc @@ -14,6 +14,7 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +#pragma code_page(65001) #include #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 diff --git a/PowerEditor/src/WinControls/Grid/ShortcutMapper_rc.h b/PowerEditor/src/WinControls/Grid/ShortcutMapper_rc.h index 28d102fd3..b62bdf8d4 100644 --- a/PowerEditor/src/WinControls/Grid/ShortcutMapper_rc.h +++ b/PowerEditor/src/WinControls/Grid/ShortcutMapper_rc.h @@ -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)