| 1449 | } |
| 1450 | |
| 1451 | bool AppFrame::actionOnMenuSettings(wxCommandEvent& event) { |
| 1452 | |
| 1453 | int antennaIdMax = wxID_ANTENNAS_BASE + antennaNames.size(); |
| 1454 | |
| 1455 | if (event.GetId() >= wxID_ANTENNAS_BASE && event.GetId() < antennaIdMax) { |
| 1456 | |
| 1457 | wxGetApp().setAntennaName(antennaNames[event.GetId() - wxID_ANTENNAS_BASE]); |
| 1458 | |
| 1459 | antennaMenuItems[wxID_ANTENNA_CURRENT]->SetItemLabel(getSettingsLabel("Antenna", wxGetApp().getAntennaName())); |
| 1460 | return true; |
| 1461 | } |
| 1462 | else if (event.GetId() >= wxID_SETTINGS_BASE && event.GetId() < settingsIdMax) { |
| 1463 | |
| 1464 | int setIdx = event.GetId() - wxID_SETTINGS_BASE; |
| 1465 | int menuIdx = 0; |
| 1466 | |
| 1467 | for (auto & arg : settingArgs) { |
| 1468 | if (arg.type == SoapySDR::ArgInfo::STRING && !arg.options.empty() && setIdx >= menuIdx && setIdx < menuIdx + (int)arg.options.size()) { |
| 1469 | int optIdx = setIdx - menuIdx; |
| 1470 | wxGetApp().getSDRThread()->writeSetting(arg.key, arg.options[optIdx]); |
| 1471 | |
| 1472 | //update parent menu item label to display the current value |
| 1473 | settingsMenuItems[menuIdx + wxID_SETTINGS_BASE]->SetItemLabel(getSettingsLabel(arg.name, arg.options[optIdx], arg.units)); |
| 1474 | break; |
| 1475 | } |
| 1476 | else if (arg.type == SoapySDR::ArgInfo::STRING && !arg.options.empty()) { |
| 1477 | menuIdx += arg.options.size(); |
| 1478 | } |
| 1479 | else if (menuIdx == setIdx) { |
| 1480 | if (arg.type == SoapySDR::ArgInfo::BOOL) { |
| 1481 | wxGetApp().getSDRThread()->writeSetting(arg.key, (wxGetApp().getSDRThread()->readSetting(arg.key) == "true") ? "false" : "true"); |
| 1482 | break; |
| 1483 | } |
| 1484 | else if (arg.type == SoapySDR::ArgInfo::STRING) { |
| 1485 | wxString stringVal = wxGetTextFromUser(arg.description, arg.name, wxGetApp().getSDRThread()->readSetting(arg.key)); |
| 1486 | |
| 1487 | settingsMenuItems[menuIdx + wxID_SETTINGS_BASE]->SetItemLabel(getSettingsLabel(arg.name, stringVal.ToStdString(), arg.units)); |
| 1488 | |
| 1489 | if (!stringVal.ToStdString().empty()) { |
| 1490 | wxGetApp().getSDRThread()->writeSetting(arg.key, stringVal.ToStdString()); |
| 1491 | } |
| 1492 | break; |
| 1493 | } |
| 1494 | else if (arg.type == SoapySDR::ArgInfo::INT) { |
| 1495 | int currentVal; |
| 1496 | try { |
| 1497 | currentVal = std::stoi(wxGetApp().getSDRThread()->readSetting(arg.key)); |
| 1498 | } |
| 1499 | catch (const std::invalid_argument &) { |
| 1500 | currentVal = 0; |
| 1501 | } |
| 1502 | int intVal = wxGetNumberFromUser(arg.description, arg.units, arg.name, currentVal, arg.range.minimum(), arg.range.maximum(), this); |
| 1503 | |
| 1504 | settingsMenuItems[menuIdx + wxID_SETTINGS_BASE]->SetItemLabel(getSettingsLabel(arg.name, std::to_string(intVal), arg.units)); |
| 1505 | |
| 1506 | if (intVal != -1) { |
| 1507 | wxGetApp().getSDRThread()->writeSetting(arg.key, std::to_string(intVal)); |
| 1508 | } |
nothing calls this directly
no test coverage detected