mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 10:57:35 +00:00
ClockWidget: Deduplicate logic for updating calendar buttons
This commit is contained in:
parent
9a1018389c
commit
28b5438395
2 changed files with 13 additions and 12 deletions
|
@ -54,10 +54,7 @@ ClockWidget::ClockWidget()
|
|||
m_prev_date->set_icon(Gfx::Bitmap::load_from_file("/res/icons/16x16/go-back.png"sv).release_value_but_fixme_should_propagate_errors());
|
||||
m_prev_date->on_click = [&](auto) {
|
||||
m_calendar->show_previous_date();
|
||||
if (m_calendar->mode() == GUI::Calendar::Year)
|
||||
m_selected_calendar_button->set_text(m_calendar->formatted_date(GUI::Calendar::YearOnly).release_value_but_fixme_should_propagate_errors());
|
||||
else
|
||||
m_selected_calendar_button->set_text(m_calendar->formatted_date().release_value_but_fixme_should_propagate_errors());
|
||||
update_selected_calendar_button();
|
||||
};
|
||||
|
||||
m_selected_calendar_button = navigation_container.add<GUI::Button>();
|
||||
|
@ -65,10 +62,7 @@ ClockWidget::ClockWidget()
|
|||
m_selected_calendar_button->set_fixed_height(24);
|
||||
m_selected_calendar_button->on_click = [&](auto) {
|
||||
m_calendar->toggle_mode();
|
||||
if (m_calendar->mode() == GUI::Calendar::Year)
|
||||
m_selected_calendar_button->set_text(m_calendar->formatted_date(GUI::Calendar::YearOnly).release_value_but_fixme_should_propagate_errors());
|
||||
else
|
||||
m_selected_calendar_button->set_text(m_calendar->formatted_date().release_value_but_fixme_should_propagate_errors());
|
||||
update_selected_calendar_button();
|
||||
};
|
||||
|
||||
m_next_date = navigation_container.add<GUI::Button>();
|
||||
|
@ -77,10 +71,7 @@ ClockWidget::ClockWidget()
|
|||
m_next_date->set_icon(Gfx::Bitmap::load_from_file("/res/icons/16x16/go-forward.png"sv).release_value_but_fixme_should_propagate_errors());
|
||||
m_next_date->on_click = [&](auto) {
|
||||
m_calendar->show_next_date();
|
||||
if (m_calendar->mode() == GUI::Calendar::Year)
|
||||
m_selected_calendar_button->set_text(m_calendar->formatted_date(GUI::Calendar::YearOnly).release_value_but_fixme_should_propagate_errors());
|
||||
else
|
||||
m_selected_calendar_button->set_text(m_calendar->formatted_date().release_value_but_fixme_should_propagate_errors());
|
||||
update_selected_calendar_button();
|
||||
};
|
||||
|
||||
auto& separator1 = root_container->add<GUI::HorizontalSeparator>();
|
||||
|
@ -212,4 +203,12 @@ void ClockWidget::jump_to_current_date()
|
|||
m_selected_calendar_button->set_text(m_calendar->formatted_date().release_value_but_fixme_should_propagate_errors());
|
||||
}
|
||||
|
||||
void ClockWidget::update_selected_calendar_button()
|
||||
{
|
||||
if (m_calendar->mode() == GUI::Calendar::Year)
|
||||
m_selected_calendar_button->set_text(m_calendar->formatted_date(GUI::Calendar::YearOnly).release_value_but_fixme_should_propagate_errors());
|
||||
else
|
||||
m_selected_calendar_button->set_text(m_calendar->formatted_date().release_value_but_fixme_should_propagate_errors());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue