diff --git a/Userland/Applications/Calendar/main.cpp b/Userland/Applications/Calendar/main.cpp index 0889a6d8863..28cf1023a9a 100644 --- a/Userland/Applications/Calendar/main.cpp +++ b/Userland/Applications/Calendar/main.cpp @@ -49,33 +49,11 @@ ErrorOr serenity_main(Main::Arguments arguments) auto calendar = main_widget->find_descendant_of_type_named("calendar"); auto prev_date_action = GUI::Action::create({}, TRY(Gfx::Bitmap::load_from_file("/res/icons/16x16/go-back.png"sv)), [&](const GUI::Action&) { - unsigned view_month = calendar->view_month(); - unsigned view_year = calendar->view_year(); - if (calendar->mode() == GUI::Calendar::Month) { - view_month--; - if (calendar->view_month() == 1) { - view_month = 12; - view_year--; - } - } else { - view_year--; - } - calendar->update_tiles(view_year, view_month); + calendar->show_previous_date(); }); auto next_date_action = GUI::Action::create({}, TRY(Gfx::Bitmap::load_from_file("/res/icons/16x16/go-forward.png"sv)), [&](const GUI::Action&) { - unsigned view_month = calendar->view_month(); - unsigned view_year = calendar->view_year(); - if (calendar->mode() == GUI::Calendar::Month) { - view_month++; - if (calendar->view_month() == 12) { - view_month = 1; - view_year++; - } - } else { - view_year++; - } - calendar->update_tiles(view_year, view_month); + calendar->show_next_date(); }); auto add_event_action = GUI::Action::create("&Add Event", {}, TRY(Gfx::Bitmap::load_from_file("/res/icons/16x16/add-event.png"sv)), [&](const GUI::Action&) { diff --git a/Userland/Libraries/LibGUI/Calendar.cpp b/Userland/Libraries/LibGUI/Calendar.cpp index 160e100ec22..1224c6ccb27 100644 --- a/Userland/Libraries/LibGUI/Calendar.cpp +++ b/Userland/Libraries/LibGUI/Calendar.cpp @@ -82,6 +82,38 @@ void Calendar::toggle_mode() invalidate_layout(); } +void Calendar::show_previous_date() +{ + unsigned view_month = m_view_month; + unsigned view_year = m_view_year; + if (m_mode == GUI::Calendar::Month) { + --view_month; + if (view_month == 0) { + view_month = 12; + --view_year; + } + } else { + --view_year; + } + update_tiles(view_year, view_month); +} + +void Calendar::show_next_date() +{ + unsigned view_month = m_view_month; + unsigned view_year = m_view_year; + if (m_mode == GUI::Calendar::Month) { + ++view_month; + if (view_month == 13) { + view_month = 1; + ++view_year; + } + } else { + ++view_year; + } + update_tiles(view_year, view_month); +} + void Calendar::resize_event(GUI::ResizeEvent& event) { m_event_size.set_width(event.size().width() - (frame_thickness() * 2)); diff --git a/Userland/Libraries/LibGUI/Calendar.h b/Userland/Libraries/LibGUI/Calendar.h index d9afb32db67..2a4ef4b82ea 100644 --- a/Userland/Libraries/LibGUI/Calendar.h +++ b/Userland/Libraries/LibGUI/Calendar.h @@ -64,6 +64,9 @@ public: void set_show_days_of_the_week(bool b) { m_show_days = b; } bool is_showing_days_of_the_week() const { return m_show_days; } + void show_previous_date(); + void show_next_date(); + Gfx::IntSize unadjusted_tile_size() const { return m_unadjusted_tile_size; } void set_unadjusted_tile_size(int width, int height) { diff --git a/Userland/Services/Taskbar/ClockWidget.cpp b/Userland/Services/Taskbar/ClockWidget.cpp index 1848007072c..e68b23a6ab5 100644 --- a/Userland/Services/Taskbar/ClockWidget.cpp +++ b/Userland/Services/Taskbar/ClockWidget.cpp @@ -53,18 +53,7 @@ ClockWidget::ClockWidget() m_prev_date->set_fixed_size(24, 24); 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) { - unsigned view_month = m_calendar->view_month(); - unsigned view_year = m_calendar->view_year(); - if (m_calendar->mode() == GUI::Calendar::Month) { - view_month--; - if (m_calendar->view_month() == 1) { - view_month = 12; - view_year--; - } - } else { - view_year--; - } - m_calendar->update_tiles(view_year, view_month); + 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 @@ -87,18 +76,7 @@ ClockWidget::ClockWidget() m_next_date->set_fixed_size(24, 24); 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) { - unsigned view_month = m_calendar->view_month(); - unsigned view_year = m_calendar->view_year(); - if (m_calendar->mode() == GUI::Calendar::Month) { - view_month++; - if (m_calendar->view_month() == 12) { - view_month = 1; - view_year++; - } - } else { - view_year++; - } - m_calendar->update_tiles(view_year, view_month); + 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