* Select the first available airport. * @param change_class If true, change the class if no airport in the current * class is available. */
| 539 | * class is available. |
| 540 | */ |
| 541 | void SelectFirstAvailableAirport(bool change_class) |
| 542 | { |
| 543 | /* First try to select an airport in the selected class. */ |
| 544 | AirportClass *sel_apclass = AirportClass::Get(_selected_airport_class); |
| 545 | for (const AirportSpec *as : sel_apclass->Specs()) { |
| 546 | if (as->IsAvailable()) { |
| 547 | this->SelectOtherAirport(as->index); |
| 548 | return; |
| 549 | } |
| 550 | } |
| 551 | if (change_class) { |
| 552 | /* If that fails, select the first available airport |
| 553 | * from the first class where airports are available. */ |
| 554 | for (const auto &cls : AirportClass::Classes()) { |
| 555 | for (const auto &as : cls.Specs()) { |
| 556 | if (as->IsAvailable()) { |
| 557 | _selected_airport_class = cls.Index(); |
| 558 | this->vscroll->SetCount(cls.GetSpecCount()); |
| 559 | this->SelectOtherAirport(as->index); |
| 560 | return; |
| 561 | } |
| 562 | } |
| 563 | } |
| 564 | } |
| 565 | /* If all airports are unavailable, select nothing. */ |
| 566 | this->SelectOtherAirport(-1); |
| 567 | } |
| 568 | |
| 569 | void OnDropdownSelect(WidgetID widget, int index, int) override |
| 570 | { |
no test coverage detected