From 6ebad51cf681e860a09ad13c78575d58894557bc Mon Sep 17 00:00:00 2001 From: Aurumaker72 Date: Sun, 30 Jun 2024 09:40:09 +0200 Subject: [PATCH] Runner: Fix various interaction issues --- main/win/features/Runner.cpp | 38 ++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/main/win/features/Runner.cpp b/main/win/features/Runner.cpp index bb6ec036..5df91fc6 100644 --- a/main/win/features/Runner.cpp +++ b/main/win/features/Runner.cpp @@ -15,6 +15,8 @@ namespace Runner { + int32_t last_selected_id = -1; + void run_auto(int id, std::filesystem::path path) { switch (id) @@ -48,6 +50,7 @@ namespace Runner { case WM_INITDIALOG: { + last_selected_id = -1; auto populate_with_paths = [&](const int id, std::vector paths) { auto ctl = GetDlgItem(hwnd, id); @@ -66,9 +69,6 @@ namespace Runner populate_with_paths(IDC_LIST_SCRIPTS, Config.recent_lua_script_paths); break; } - case WM_DESTROY: - - break; case WM_CLOSE: EndDialog(hwnd, IDCANCEL); break; @@ -81,6 +81,12 @@ namespace Runner if (HIWORD(wParam) == LBN_DBLCLK) { auto index = ListBox_GetCurSel(GetDlgItem(hwnd, LOWORD(wParam))); + + if (index == -1) + { + break; + } + auto buffer = (char*)ListBox_GetItemData(GetDlgItem(hwnd, LOWORD(wParam)), index); std::filesystem::path path(buffer); delete buffer; @@ -89,23 +95,29 @@ namespace Runner run_auto(LOWORD(wParam), path); } - break; - case IDOK: + if (HIWORD(wParam) == LBN_SELCHANGE) { - auto ctl_hwnd = GetFocus(); - if (!ctl_hwnd) + // Clear the selections of the other items + for (auto id : {IDC_LIST_ROMS, IDC_LIST_MOVIES, IDC_LIST_SCRIPTS}) { - break; + if (id == LOWORD(wParam)) + { + continue; + } + ListBox_SetCurSel(GetDlgItem(hwnd, id), -1); } - char name[260]{}; - GetClassName(ctl_hwnd, name, sizeof(name)); - if (lstrcmpi(name, "ListBox")) + + last_selected_id = LOWORD(wParam); + } + break; + case IDOK: + { + if (!last_selected_id) { break; } - SendMessage(hwnd, WM_COMMAND, MAKEWPARAM(GetDlgCtrlID(ctl_hwnd), LBN_DBLCLK), 0); - + SendMessage(hwnd, WM_COMMAND, MAKEWPARAM(last_selected_id, LBN_DBLCLK), 0); break; } case IDCANCEL: