Enhance Run Macro dialog

- reorder tab focus.
- add key accelerators.
- optimize dark mode.

fix #13544, close #13545
This commit is contained in:
ozone10 2023-04-16 11:00:34 +02:00 committed by Don Ho
parent 1a1ce04caa
commit 87e34c1f7b
6 changed files with 60 additions and 97 deletions

View File

@ -1265,7 +1265,7 @@ You can define several column markers by using white space to separate the diffe
<MultiMacro title="Run a Macro Multiple Times"> <MultiMacro title="Run a Macro Multiple Times">
<Item id="1" name="&amp;Run"/> <Item id="1" name="&amp;Run"/>
<Item id="2" name="&amp;Cancel"/> <Item id="2" name="&amp;Cancel"/>
<Item id="8006" name="Macro to run :"/> <Item id="8006" name="Macro to run"/>
<Item id="8001" name="Run"/> <Item id="8001" name="Run"/>
<Item id="8005" name="times"/> <Item id="8005" name="times"/>
<Item id="8002" name="Run until the &amp;end of file"/> <Item id="8002" name="Run until the &amp;end of file"/>

View File

@ -1260,7 +1260,7 @@ You can define several column markers by using white space to separate the diffe
<MultiMacro title="Run a Macro Multiple Times"> <MultiMacro title="Run a Macro Multiple Times">
<Item id="1" name="&amp;Run"/> <Item id="1" name="&amp;Run"/>
<Item id="2" name="&amp;Cancel"/> <Item id="2" name="&amp;Cancel"/>
<Item id="8006" name="Macro to run :"/> <Item id="8006" name="Macro to run"/>
<Item id="8001" name="Run"/> <Item id="8001" name="Run"/>
<Item id="8005" name="times"/> <Item id="8005" name="times"/>
<Item id="8002" name="Run until the &amp;end of file"/> <Item id="8002" name="Run until the &amp;end of file"/>

View File

@ -1463,13 +1463,7 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa
{ {
if (!_recordingMacro) // if we're not currently recording, then playback the recorded keystrokes if (!_recordingMacro) // if we're not currently recording, then playback the recorded keystrokes
{ {
int times = 1; int times = _runMacroDlg.isMulti() ? _runMacroDlg.getTimes() : -1;
if (_runMacroDlg.getMode() == RM_RUN_MULTI)
times = _runMacroDlg.getTimes();
else if (_runMacroDlg.getMode() == RM_RUN_EOF)
times = -1;
else
break;
int counter = 0; int counter = 0;
intptr_t lastLine = _pEditView->execute(SCI_GETLINECOUNT) - 1; intptr_t lastLine = _pEditView->execute(SCI_GETLINECOUNT) - 1;

View File

@ -40,9 +40,9 @@ void RunMacroDlg::initMacroList()
_macroIndex = 0; _macroIndex = 0;
} }
intptr_t CALLBACK RunMacroDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM) intptr_t CALLBACK RunMacroDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam)
{ {
switch (message) switch (message)
{ {
case WM_INITDIALOG : case WM_INITDIALOG :
{ {
@ -50,47 +50,42 @@ intptr_t CALLBACK RunMacroDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM)
initMacroList(); initMacroList();
::SetDlgItemInt(_hSelf, IDC_M_RUN_TIMES, _times, FALSE); ::SetDlgItemInt(_hSelf, IDC_M_RUN_TIMES, _times, FALSE);
switch (_mode) setChecked(IDC_M_RUN_MULTI);
{
case RM_RUN_MULTI:
check(IDC_M_RUN_MULTI);
break;
case RM_RUN_EOF:
check(IDC_M_RUN_EOF);
break;
}
::SendDlgItemMessage(_hSelf, IDC_M_RUN_TIMES, EM_LIMITTEXT, 4, 0); ::SendDlgItemMessage(_hSelf, IDC_M_RUN_TIMES, EM_LIMITTEXT, 4, 0);
goToCenter(); goToCenter(SWP_SHOWWINDOW | SWP_NOSIZE);
return TRUE; return TRUE;
} }
case WM_CTLCOLOREDIT: case WM_CTLCOLOREDIT:
{ {
if (NppDarkMode::isEnabled()) return NppDarkMode::onCtlColorSofter(reinterpret_cast<HDC>(wParam));
{
return NppDarkMode::onCtlColorSofter(reinterpret_cast<HDC>(wParam));
}
break;
} }
case WM_CTLCOLORLISTBOX: case WM_CTLCOLORLISTBOX:
{ {
if (NppDarkMode::isEnabled()) return NppDarkMode::onCtlColorListbox(wParam, lParam);
{
return NppDarkMode::onCtlColor(reinterpret_cast<HDC>(wParam));
}
break;
} }
case WM_CTLCOLORDLG: case WM_CTLCOLORDLG:
{
return NppDarkMode::onCtlColorDarker(reinterpret_cast<HDC>(wParam));
}
case WM_CTLCOLORSTATIC: case WM_CTLCOLORSTATIC:
{ {
if (NppDarkMode::isEnabled()) auto hdcStatic = reinterpret_cast<HDC>(wParam);
const auto dlgCtrlID = ::GetDlgCtrlID(reinterpret_cast<HWND>(lParam));
const bool isStaticText = (dlgCtrlID == IDC_TIMES_STATIC);
//set the static text colors to show enable/disable instead of ::EnableWindow which causes blurry text
if (isStaticText)
{ {
return NppDarkMode::onCtlColorDarker(reinterpret_cast<HDC>(wParam)); const bool isTextEnabled = isCheckedOrNot(IDC_M_RUN_MULTI);
return NppDarkMode::onCtlColorDarkerBGStaticText(hdcStatic, isTextEnabled);
} }
break; return NppDarkMode::onCtlColorDarker(hdcStatic);
} }
case WM_PRINTCLIENT: case WM_PRINTCLIENT:
@ -108,39 +103,34 @@ intptr_t CALLBACK RunMacroDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM)
return TRUE; return TRUE;
} }
case WM_COMMAND : case WM_COMMAND:
{ {
if (HIWORD(wParam) == EN_CHANGE)
{
switch (LOWORD(wParam))
{
case IDC_M_RUN_TIMES:
check(IDC_M_RUN_MULTI);
return TRUE;
default:
return FALSE;
}
}
switch (wParam) switch (wParam)
{ {
case IDCANCEL : case IDC_M_RUN_MULTI:
case IDC_M_RUN_EOF:
{
const bool isMulti = (wParam == IDC_M_RUN_MULTI);
if (isMulti)
{
::EnableWindow(::GetDlgItem(_hSelf, IDC_M_RUN_TIMES), TRUE);
_times = ::GetDlgItemInt(_hSelf, IDC_M_RUN_TIMES, NULL, FALSE);
}
else
{
::EnableWindow(::GetDlgItem(_hSelf, IDC_M_RUN_TIMES), FALSE);
}
redrawDlgItem(IDC_TIMES_STATIC);
return TRUE;
}
case IDCANCEL:
::ShowWindow(_hSelf, SW_HIDE); ::ShowWindow(_hSelf, SW_HIDE);
return TRUE; return TRUE;
case IDOK : case IDOK:
if ( isCheckedOrNot(IDC_M_RUN_MULTI) ) if (::SendDlgItemMessage(_hSelf, IDC_MACRO_COMBO, CB_GETCOUNT, 0, 0) > 0)
{
_mode = RM_RUN_MULTI;
_times = ::GetDlgItemInt(_hSelf, IDC_M_RUN_TIMES, NULL, FALSE);
}
else if ( isCheckedOrNot(IDC_M_RUN_EOF) )
{
_mode = RM_RUN_EOF;
}
if (::SendDlgItemMessage(_hSelf, IDC_MACRO_COMBO, CB_GETCOUNT, 0, 0))
::SendMessage(_hParent, WM_MACRODLGRUNMACRO, 0, 0); ::SendMessage(_hParent, WM_MACRODLGRUNMACRO, 0, 0);
return TRUE; return TRUE;
@ -157,21 +147,6 @@ intptr_t CALLBACK RunMacroDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM)
return FALSE; return FALSE;
} }
void RunMacroDlg::check(int id)
{
// IDC_M_RUN_MULTI
if ( id == IDC_M_RUN_MULTI )
::SendDlgItemMessage(_hSelf, IDC_M_RUN_MULTI, BM_SETCHECK, BST_CHECKED, 0);
else
::SendDlgItemMessage(_hSelf, IDC_M_RUN_MULTI, BM_SETCHECK, BST_UNCHECKED, 0);
// IDC_M_RUN_EOF
if ( id == IDC_M_RUN_EOF )
::SendDlgItemMessage(_hSelf, IDC_M_RUN_EOF, BM_SETCHECK, BST_CHECKED, 0);
else
::SendDlgItemMessage(_hSelf, IDC_M_RUN_EOF, BM_SETCHECK, BST_UNCHECKED, 0);
}
int RunMacroDlg::getMacro2Exec() const int RunMacroDlg::getMacro2Exec() const
{ {
bool isCurMacroPresent = static_cast<MacroStatus>(::SendMessage(_hParent, NPPM_GETCURRENTMACROSTATUS, 0, 0)) == MacroStatus::RecordingStopped; bool isCurMacroPresent = static_cast<MacroStatus>(::SendMessage(_hParent, NPPM_GETCURRENTMACROSTATUS, 0, 0)) == MacroStatus::RecordingStopped;

View File

@ -21,20 +21,12 @@
#include "RunMacroDlg_rc.h" #include "RunMacroDlg_rc.h"
#include "StaticDialog.h" #include "StaticDialog.h"
#define RM_CANCEL -1
#define RM_RUN_MULTI 1
#define RM_RUN_EOF 2
class RunMacroDlg : public StaticDialog class RunMacroDlg : public StaticDialog
{ {
public : public :
RunMacroDlg() = default; RunMacroDlg() = default;
~RunMacroDlg() = default; ~RunMacroDlg() = default;
void init(HINSTANCE hInst, HWND hPere/*, ScintillaEditView **ppEditView*/) {
Window::init(hInst, hPere);
};
void doDialog(bool isRTL = false) { void doDialog(bool isRTL = false) {
if (!isCreated()) if (!isCreated())
create(IDD_RUN_MACRO_DLG, isRTL); create(IDD_RUN_MACRO_DLG, isRTL);
@ -49,15 +41,13 @@ public :
void initMacroList(); void initMacroList();
int getMode() const {return _mode;}; int isMulti() const { return isCheckedOrNot(IDC_M_RUN_MULTI); };
int getTimes() const {return _times;}; int getTimes() const {return _times;};
int getMacro2Exec() const; int getMacro2Exec() const;
private : private :
virtual intptr_t CALLBACK run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam); intptr_t CALLBACK run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam) override;
void check(int);
int _mode = RM_RUN_MULTI;
int _times = 1; int _times = 1;
int _macroIndex = 0; int _macroIndex = 0;
}; };

View File

@ -19,18 +19,22 @@
#include <windows.h> #include <windows.h>
#include "RunMacroDlg_rc.h" #include "RunMacroDlg_rc.h"
IDD_RUN_MACRO_DLG DIALOGEX 0, 0, 168, 110 IDD_RUN_MACRO_DLG DIALOGEX 0, 0, 168, 95
STYLE DS_SETFONT | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU STYLE DS_SETFONT | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU
EXSTYLE WS_EX_DLGMODALFRAME | WS_EX_WINDOWEDGE EXSTYLE WS_EX_DLGMODALFRAME | WS_EX_WINDOWEDGE
CAPTION "Run a Macro Multiple Times" CAPTION "Run a Macro Multiple Times"
FONT 8, TEXT("MS Shell Dlg"), 400, 0, 0x1 FONT 8, TEXT("MS Shell Dlg"), 400, 0, 0x1
BEGIN BEGIN
DEFPUSHBUTTON "&Run",IDOK,27,82,50,14 GROUPBOX "&Macro to run",IDC_MACRO2RUN_STATIC,7,3,154,30,BS_CENTER
PUSHBUTTON "&Cancel",IDCANCEL,91,82,50,14 COMBOBOX IDC_MACRO_COMBO,14,14,140,30,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP
CONTROL "Run",IDC_M_RUN_MULTI,"Button",BS_AUTORADIOBUTTON,18,38,47,10
CONTROL "Run until the &end of file", IDC_M_RUN_EOF,"Button", BS_AUTORADIOBUTTON,18,56,140,10 CONTROL "R&un",IDC_M_RUN_MULTI,"Button",BS_AUTORADIOBUTTON,18,42,47,10
EDITTEXT IDC_M_RUN_TIMES,67,35,25,14,ES_AUTOHSCROLL | ES_NUMBER | WS_EX_DLGMODALFRAME
COMBOBOX IDC_MACRO_COMBO,67,10,96,30,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP CONTROL "Run until the &end of file", IDC_M_RUN_EOF,"Button",BS_AUTORADIOBUTTON,18,57,140,10
RTEXT "Macro to run :",IDC_MACRO2RUN_STATIC,5,12,59,8
LTEXT "times",IDC_TIMES_STATIC,97,38,65,8 EDITTEXT IDC_M_RUN_TIMES,67,40,25,12, ES_CENTER | ES_AUTOHSCROLL | ES_NUMBER
LTEXT "times",IDC_TIMES_STATIC,97,42,65,10
DEFPUSHBUTTON "&Run",IDOK,32,75,50,14
PUSHBUTTON "&Cancel",IDCANCEL,86,75,50,14
END END