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
Notes: sideshowbarker 2024-07-17 01:12:07 +09:00
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->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());
}
}

View File

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