Called when one of the format drop downs is changed.
| 452 | |
| 453 | // Called when one of the format drop downs is changed. |
| 454 | void SelectionBar::OnUpdate(wxCommandEvent &evt) |
| 455 | { |
| 456 | evt.Skip(false); |
| 457 | |
| 458 | wxWindow *w = FindFocus(); |
| 459 | |
| 460 | auto focusedCtrlIt = |
| 461 | std::find(mTimeControls.begin(), mTimeControls.end(), w); |
| 462 | |
| 463 | const auto focusedCtrlIdx = |
| 464 | focusedCtrlIt != mTimeControls.end() ? |
| 465 | std::distance(mTimeControls.begin(), focusedCtrlIt) : |
| 466 | -1; |
| 467 | |
| 468 | auto format = evt.GetString(); |
| 469 | |
| 470 | // Save format name before recreating the controls so they resize properly |
| 471 | if (mTimeControls.front()) |
| 472 | { |
| 473 | auto &formats = ProjectNumericFormats::Get(mProject); |
| 474 | formats.SetSelectionFormat(format); |
| 475 | // Then my Subscription is called |
| 476 | } |
| 477 | |
| 478 | // ReCreateButtons() will get rid of our sizers and controls |
| 479 | // so reset pointers first. |
| 480 | std::fill(mTimeControls.begin(), mTimeControls.end(), nullptr); |
| 481 | |
| 482 | ToolBar::ReCreateButtons(); |
| 483 | |
| 484 | ValuesToControls(); |
| 485 | |
| 486 | UpdateTimeControlsFormat(format); |
| 487 | |
| 488 | if (focusedCtrlIdx >= 0 && mTimeControls[focusedCtrlIdx]) |
| 489 | mTimeControls[focusedCtrlIdx]->SetFocus(); |
| 490 | |
| 491 | RegenerateTooltips(); |
| 492 | |
| 493 | Updated(); |
| 494 | } |
| 495 | |
| 496 | void SelectionBar::OnIdle( wxIdleEvent &evt ) |
| 497 | { |