Skip to content

Commit

Permalink
Runner: Fix various interaction issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Aurumaker72 committed Jun 30, 2024
1 parent bfb466f commit 6ebad51
Showing 1 changed file with 25 additions and 13 deletions.
38 changes: 25 additions & 13 deletions main/win/features/Runner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

namespace Runner
{
int32_t last_selected_id = -1;

void run_auto(int id, std::filesystem::path path)
{
switch (id)
Expand Down Expand Up @@ -48,6 +50,7 @@ namespace Runner
{
case WM_INITDIALOG:
{
last_selected_id = -1;
auto populate_with_paths = [&](const int id, std::vector<std::string> paths)
{
auto ctl = GetDlgItem(hwnd, id);
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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:
Expand Down

0 comments on commit 6ebad51

Please sign in to comment.