From a6cd3de8a749ed1708533a1f5fcee0255fedb867 Mon Sep 17 00:00:00 2001 From: Gargaj Date: Sat, 12 Jul 2025 17:53:43 +0200 Subject: [PATCH] Add button to insert variables in the run dialog Close #16820 --- .../StaticDialog/RunDlg/RunDlg.cpp | 74 ++++++++++++++++++- .../WinControls/StaticDialog/RunDlg/RunDlg.h | 1 + .../WinControls/StaticDialog/RunDlg/RunDlg.rc | 33 +++++++-- .../StaticDialog/RunDlg/RunDlg_rc.h | 5 +- 4 files changed, 104 insertions(+), 9 deletions(-) diff --git a/PowerEditor/src/WinControls/StaticDialog/RunDlg/RunDlg.cpp b/PowerEditor/src/WinControls/StaticDialog/RunDlg/RunDlg.cpp index 960b9886d..cdd0cbbac 100644 --- a/PowerEditor/src/WinControls/StaticDialog/RunDlg/RunDlg.cpp +++ b/PowerEditor/src/WinControls/StaticDialog/RunDlg/RunDlg.cpp @@ -244,6 +244,56 @@ HINSTANCE Command::run(HWND hWnd, const wchar_t* cwd) return res; } +void RunDlg::insertVariable(unsigned char id) +{ + wchar_t cmd[MAX_PATH]{}; + ::GetDlgItemText(_hSelf, IDC_COMBO_RUN_PATH, cmd, MAX_PATH); + + wstring variable; + switch (id) + { + case 0: + variable = fullCurrentPath; + break; + case 1: + variable = currentDirectory; + break; + case 2: + variable = onlyFileName; + break; + case 3: + variable = fileNamePart; + break; + case 4: + variable = fileExtPart; + break; + case 5: + variable = currentWord; + break; + case 6: + variable = nppDir; + break; + case 7: + variable = nppFullFilePath; + break; + case 8: + variable = currentLine; + break; + case 9: + variable = currentColumn; + break; + case 10: + variable = currentLineStr; + break; + default: + return; // Invalid id number + } + + wstring cmdNew = cmd; + cmdNew += L"$(" + variable + L")"; + ::SetDlgItemText(_hSelf, IDC_COMBO_RUN_PATH, cmdNew.c_str()); +} + intptr_t CALLBACK RunDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam) { switch (message) @@ -312,6 +362,12 @@ intptr_t CALLBACK RunDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam case WM_COMMAND: { + if (LOWORD(wParam) >= IDM_RUN_DLG_VARMENU_START && LOWORD(wParam) <= IDM_RUN_DLG_VARMENU_END) + { + insertVariable(static_cast(LOWORD(wParam) - IDM_RUN_DLG_VARMENU_START)); + return TRUE; + } + switch (LOWORD(wParam)) { case IDCANCEL : @@ -406,7 +462,23 @@ intptr_t CALLBACK RunDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam return TRUE; } - default : + case IDC_BUTTON_VARIABLES: + { + RECT rcButton; + GetWindowRect(::GetDlgItem(_hSelf, IDC_BUTTON_VARIABLES), &rcButton); + + HMENU hmenu; // menu template + HMENU hVariablePopup; // shortcut menu + hmenu = ::LoadMenu(_hInst, MAKEINTRESOURCE(IDR_RUN_DLG_MENU_VARIABLES)); + hVariablePopup = ::GetSubMenu(hmenu, 0); + TrackPopupMenu(hVariablePopup, TPM_LEFTALIGN, rcButton.right, rcButton.top, 0, _hSelf, NULL); + PostMessage(_hSelf, WM_NULL, 0, 0); + DestroyMenu(hmenu); + + return TRUE; + } + + default: break; } } diff --git a/PowerEditor/src/WinControls/StaticDialog/RunDlg/RunDlg.h b/PowerEditor/src/WinControls/StaticDialog/RunDlg/RunDlg.h index da9d34c9c..738f7ba12 100644 --- a/PowerEditor/src/WinControls/StaticDialog/RunDlg/RunDlg.h +++ b/PowerEditor/src/WinControls/StaticDialog/RunDlg/RunDlg.h @@ -59,6 +59,7 @@ public : void destroy() override {}; protected : + void insertVariable(unsigned char id); intptr_t CALLBACK run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam) override; private : diff --git a/PowerEditor/src/WinControls/StaticDialog/RunDlg/RunDlg.rc b/PowerEditor/src/WinControls/StaticDialog/RunDlg/RunDlg.rc index d93e58461..6ee768dd4 100644 --- a/PowerEditor/src/WinControls/StaticDialog/RunDlg/RunDlg.rc +++ b/PowerEditor/src/WinControls/StaticDialog/RunDlg/RunDlg.rc @@ -24,16 +24,35 @@ along with this program. If not, see . #define IDC_STATIC -1 #endif -IDD_RUN_DLG DIALOGEX 0, 0, 186, 80 +IDD_RUN_DLG DIALOGEX 0, 0, 402, 80 STYLE DS_SETFONT | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU EXSTYLE WS_EX_DLGMODALFRAME | WS_EX_WINDOWEDGE CAPTION "Run..." FONT 8, L"MS Shell Dlg", 400, 0, 0x1 BEGIN - GROUPBOX "The &Program to Run",IDC_MAINTEXT_STATIC,7,6,172,48,BS_CENTER - COMBOBOX IDC_COMBO_RUN_PATH,14,26,138,71,CBS_DROPDOWN | CBS_AUTOHSCROLL | CBS_SORT | WS_VSCROLL | WS_TABSTOP - PUSHBUTTON "...",IDC_BUTTON_FILE_BROWSER,156,25,16,14 - DEFPUSHBUTTON "&Run",IDOK,16,60,50,14 - PUSHBUTTON "&Save...",IDC_BUTTON_SAVE,69,60,50,14 - PUSHBUTTON "&Cancel",IDCANCEL,122,60,50,14 + GROUPBOX "The &Program to Run",IDC_MAINTEXT_STATIC,7,6,388,48,BS_CENTER + COMBOBOX IDC_COMBO_RUN_PATH,14,26,338,71,CBS_DROPDOWN | CBS_AUTOHSCROLL | CBS_SORT | WS_VSCROLL | WS_TABSTOP + PUSHBUTTON "...",IDC_BUTTON_FILE_BROWSER,356,25,16,14 + PUSHBUTTON "&+",IDC_BUTTON_VARIABLES,372,25,16,14 + DEFPUSHBUTTON "&Run",IDOK,124,60,50,14 + PUSHBUTTON "&Save...",IDC_BUTTON_SAVE,177,60,50,14 + PUSHBUTTON "&Cancel",IDCANCEL,230,60,50,14 +END + +IDR_RUN_DLG_MENU_VARIABLES MENU +BEGIN + POPUP "Variables menu" + BEGIN + MENUITEM "&FULL_CURRENT_PATH\tFull path to active file", IDM_RUN_DLG_VARMENU_START + 0 + MENUITEM "CURRENT_&DIRECTORY\tActive file's directory", IDM_RUN_DLG_VARMENU_START + 1 + MENUITEM "FILE_&NAME\tActive file's name", IDM_RUN_DLG_VARMENU_START + 2 + MENUITEM "NAME_&PART\tFile name without extension", IDM_RUN_DLG_VARMENU_START + 3 + MENUITEM "E&XT_PART\tFile extension (with .)", IDM_RUN_DLG_VARMENU_START + 4 + MENUITEM "CURRENT_&WORD\tSelected word or word under caret", IDM_RUN_DLG_VARMENU_START + 5 + MENUITEM "NPP_&DIRECTORY\tnotepad++.exe directory", IDM_RUN_DLG_VARMENU_START + 6 + MENUITEM "NPP_F&ULL_FILE_PATH\tFull path of notepad++.exe", IDM_RUN_DLG_VARMENU_START + 7 + MENUITEM "CURRENT_&LINE\tLine number of caret", IDM_RUN_DLG_VARMENU_START + 8 + MENUITEM "CURRENT_&COLUMN\tColumn number of caret", IDM_RUN_DLG_VARMENU_START + 9 + MENUITEM "CURRENT_LINE&STR\tCurrent line text", IDM_RUN_DLG_VARMENU_START + 10 + END END diff --git a/PowerEditor/src/WinControls/StaticDialog/RunDlg/RunDlg_rc.h b/PowerEditor/src/WinControls/StaticDialog/RunDlg/RunDlg_rc.h index 726111559..6e5db62ac 100644 --- a/PowerEditor/src/WinControls/StaticDialog/RunDlg/RunDlg_rc.h +++ b/PowerEditor/src/WinControls/StaticDialog/RunDlg/RunDlg_rc.h @@ -21,4 +21,7 @@ #define IDC_COMBO_RUN_PATH (IDD_RUN_DLG + 2) #define IDC_MAINTEXT_STATIC (IDD_RUN_DLG + 3) #define IDC_BUTTON_SAVE (IDD_RUN_DLG + 4) - +#define IDC_BUTTON_VARIABLES (IDD_RUN_DLG + 5) +#define IDR_RUN_DLG_MENU_VARIABLES 1950 +#define IDM_RUN_DLG_VARMENU_START (IDD_RUN_DLG + 60) +#define IDM_RUN_DLG_VARMENU_END (IDM_RUN_DLG_VARMENU_START + 10)