Fix extension appending issue in file dialog

Fix #9510, close #9532
This commit is contained in:
mere-human 2021-02-16 22:29:31 +02:00 committed by Don HO
parent 75bcb7c536
commit f96d81af11
No known key found for this signature in database
GPG Key ID: 6C429F1D8D84F46E
1 changed files with 22 additions and 8 deletions

View File

@ -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<LPARAM>(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);
}