From d81cb0d533cb635f81845aa597e35504c532ea2e Mon Sep 17 00:00:00 2001 From: tomcw Date: Sat, 3 Jun 2017 18:21:27 +0100 Subject: [PATCH] Disk Config dialog: small refactor --- source/Configuration/PageDisk.cpp | 89 ++++++++++++++++--------------- 1 file changed, 45 insertions(+), 44 deletions(-) diff --git a/source/Configuration/PageDisk.cpp b/source/Configuration/PageDisk.cpp index 6df8bb96..757ada9e 100644 --- a/source/Configuration/PageDisk.cpp +++ b/source/Configuration/PageDisk.cpp @@ -215,62 +215,63 @@ void CPageDisk::EnableDisk(HWND hWnd, BOOL bEnable) void CPageDisk::HandleHDDCombo(HWND hWnd, UINT driveSelected, UINT comboSelected) { + if (!IsDlgButtonChecked(hWnd, IDC_HDD_ENABLE)) + return; + // Search from "select hard drive" DWORD dwOpenDialogIndex = (DWORD)SendDlgItemMessage(hWnd, comboSelected, CB_FINDSTRINGEXACT, -1, (LPARAM)&m_defaultHDDOptions[0]); DWORD dwComboSelection = (DWORD)SendDlgItemMessage(hWnd, comboSelected, CB_GETCURSEL, 0, 0); - if (IsDlgButtonChecked(hWnd, IDC_HDD_ENABLE)) + + SendDlgItemMessage(hWnd, comboSelected, CB_SETCURSEL, -1, 0); // Set to "empty" item + + if (dwComboSelection == dwOpenDialogIndex) { - SendDlgItemMessage(hWnd, comboSelected, CB_SETCURSEL, -1, 0); // Set to "empty" item + EnableHDD(hWnd, FALSE); // Prevent multiple Selection dialogs to be triggered + bool bRes = HD_Select(driveSelected); + EnableHDD(hWnd, TRUE); - if (dwComboSelection == dwOpenDialogIndex) + if (!bRes) { - EnableHDD(hWnd, FALSE); // Prevent multiple Selection dialogs to be triggered - bool bRes = HD_Select(driveSelected); - EnableHDD(hWnd, TRUE); + if (SendDlgItemMessage(hWnd, comboSelected, CB_GETCOUNT, 0, 0) == 3) // If there's already a HDD... + SendDlgItemMessage(hWnd, comboSelected, CB_SETCURSEL, 0, 0); // then reselect it in the ComboBox + return; + } - if (!bRes) - { - if (SendDlgItemMessage(hWnd, comboSelected, CB_GETCOUNT, 0, 0) == 3) // If there's already a disk... - SendDlgItemMessage(hWnd, comboSelected, CB_SETCURSEL, 0, 0); // then reselect it in the ComboBox - return; - } + // Add hard drive name as item 0 and select it + if (dwOpenDialogIndex > 0) + { + // Remove old item first + SendDlgItemMessage(hWnd, comboSelected, CB_DELETESTRING, 0, 0); + } - // Add hard drive name as item 0 and select it - if (dwOpenDialogIndex > 0) + SendDlgItemMessage(hWnd, comboSelected, CB_INSERTSTRING, 0, (LPARAM)HD_GetFullName(driveSelected)); + SendDlgItemMessage(hWnd, comboSelected, CB_SETCURSEL, 0, 0); + + // If the HD was in the other combo, remove now + DWORD comboOther = (comboSelected == IDC_COMBO_HDD1) ? IDC_COMBO_HDD2 : IDC_COMBO_HDD1; + + DWORD duplicated = (DWORD)SendDlgItemMessage(hWnd, comboOther, CB_FINDSTRINGEXACT, -1, (LPARAM)HD_GetFullName(driveSelected)); + if (duplicated != CB_ERR) + { + SendDlgItemMessage(hWnd, comboOther, CB_DELETESTRING, duplicated, 0); + SendDlgItemMessage(hWnd, comboOther, CB_SETCURSEL, -1, 0); + } + } + else if (dwComboSelection == (dwOpenDialogIndex+1)) + { + if (dwComboSelection > 1) + { + UINT uCommand = (driveSelected == 0) ? IDC_COMBO_HDD1 : IDC_COMBO_HDD2; + if (RemovalConfirmation(uCommand)) { - // Remove old item first + // Unplug selected disk + HD_Unplug(driveSelected); + // Remove drive from list SendDlgItemMessage(hWnd, comboSelected, CB_DELETESTRING, 0, 0); } - - SendDlgItemMessage(hWnd, comboSelected, CB_INSERTSTRING, 0, (LPARAM)HD_GetFullName(driveSelected)); - SendDlgItemMessage(hWnd, comboSelected, CB_SETCURSEL, 0, 0); - - // If the HD was in the other combo, remove now - DWORD comboOther = (comboSelected == IDC_COMBO_HDD1) ? IDC_COMBO_HDD2 : IDC_COMBO_HDD1; - - DWORD duplicated = (DWORD)SendDlgItemMessage(hWnd, comboOther, CB_FINDSTRINGEXACT, -1, (LPARAM)HD_GetFullName(driveSelected)); - if (duplicated != CB_ERR) + else { - SendDlgItemMessage(hWnd, comboOther, CB_DELETESTRING, duplicated, 0); - SendDlgItemMessage(hWnd, comboOther, CB_SETCURSEL, -1, 0); - } - } - else if (dwComboSelection == (dwOpenDialogIndex+1)) - { - if (dwComboSelection > 1) - { - UINT uCommand = (driveSelected == 0) ? IDC_COMBO_HDD1 : IDC_COMBO_HDD2; - if (RemovalConfirmation(uCommand)) - { - // Unplug selected disk - HD_Unplug(driveSelected); - // Remove drive from list - SendDlgItemMessage(hWnd, comboSelected, CB_DELETESTRING, 0, 0); - } - else - { - SendDlgItemMessage(hWnd, comboSelected, CB_SETCURSEL, 0, 0); - } + SendDlgItemMessage(hWnd, comboSelected, CB_SETCURSEL, 0, 0); } } }