1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 20:37:34 +00:00

ClockWidget: Deduplicate logic for updating calendar buttons

This commit is contained in:
implicitfield 2023-06-20 19:34:25 +04:00 committed by Ali Mohammad Pur
parent 9a1018389c
commit 28b5438395
2 changed files with 13 additions and 12 deletions

View file

@ -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->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_prev_date->on_click = [&](auto) {
m_calendar->show_previous_date(); m_calendar->show_previous_date();
if (m_calendar->mode() == GUI::Calendar::Year) update_selected_calendar_button();
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());
}; };
m_selected_calendar_button = navigation_container.add<GUI::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->set_fixed_height(24);
m_selected_calendar_button->on_click = [&](auto) { m_selected_calendar_button->on_click = [&](auto) {
m_calendar->toggle_mode(); m_calendar->toggle_mode();
if (m_calendar->mode() == GUI::Calendar::Year) update_selected_calendar_button();
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());
}; };
m_next_date = navigation_container.add<GUI::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->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_next_date->on_click = [&](auto) {
m_calendar->show_next_date(); m_calendar->show_next_date();
if (m_calendar->mode() == GUI::Calendar::Year) update_selected_calendar_button();
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());
}; };
auto& separator1 = root_container->add<GUI::HorizontalSeparator>(); 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()); 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());
}
} }

View file

@ -45,6 +45,8 @@ private:
void position_calendar_window(); void position_calendar_window();
void jump_to_current_date(); void jump_to_current_date();
void update_selected_calendar_button();
DeprecatedString m_time_format; DeprecatedString m_time_format;
RefPtr<GUI::Window> m_calendar_window; RefPtr<GUI::Window> m_calendar_window;
RefPtr<GUI::Calendar> m_calendar; RefPtr<GUI::Calendar> m_calendar;