From f96d81af11de99fd48e4ef37e0265aa5e45033fd Mon Sep 17 00:00:00 2001 From: mere-human <9664141+mere-human@users.noreply.github.com> Date: Tue, 16 Feb 2021 22:29:31 +0200 Subject: [PATCH] Fix extension appending issue in file dialog Fix #9510, close #9532 --- .../OpenSaveFileDialog/CustomFileDialog.cpp | 30 ++++++++++++++----- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/PowerEditor/src/WinControls/OpenSaveFileDialog/CustomFileDialog.cpp b/PowerEditor/src/WinControls/OpenSaveFileDialog/CustomFileDialog.cpp index d4677eb56..6e6960631 100644 --- a/PowerEditor/src/WinControls/OpenSaveFileDialog/CustomFileDialog.cpp +++ b/PowerEditor/src/WinControls/OpenSaveFileDialog/CustomFileDialog.cpp @@ -369,7 +369,11 @@ private: // Update the edit box text. // It will update the address if the path is a directory. if (nameChanged) - sendDialogFileName(fileName.c_str()); + { + // Clear the name first to ensure it's updated properly. + _dialog->SetFileName(_T("")); + _dialog->SetFileName(fileName.c_str()); + } } // Transforms a forward-slash path to a canonical Windows path. @@ -395,12 +399,6 @@ private: return transformed; } - // Sets the file name and waits until it is processed by the edit control. - void sendDialogFileName(const TCHAR* name) - { - ::SendMessage(_hwndNameEdit, WM_SETTEXT, 0, reinterpret_cast(name)); - } - // Enumerates the child windows of a dialog. // Sets up window procedure overrides for "OK" button and file name edit box. static BOOL CALLBACK EnumChildProc(HWND hwnd, LPARAM) @@ -435,7 +433,23 @@ private: static LRESULT CALLBACK OkButtonWndProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { - if (msg == WM_LBUTTONDOWN) + // The ways to press a button: + // 1. space/enter is pressed when the button has focus (WM_KEYDOWN) + // 2. left mouse click on a button (WM_LBUTTONDOWN) + // 3. Alt + S + bool pressed = false; + switch (msg) + { + case BM_SETSTATE: + // Sent after all press events above except when press return while focused. + pressed = (wparam == TRUE); + break; + case WM_GETDLGCODE: + // Sent for the keyboard input. + pressed = (wparam == VK_RETURN); + break; + } + if (pressed) _staticThis->onPreFileOk(); return CallWindowProc(_okButtonProc, hwnd, msg, wparam, lparam); }