mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-12 19:19:30 +00:00
Calendar: Add setting to choose default view
This commit adds an entry to the Calendar Settings to allow the user to select between the month and year views as the startup default.
This commit is contained in:
parent
0eceed4fd7
commit
a1d98b825d
Notes:
sideshowbarker
2024-07-18 03:23:00 +09:00
Author: https://github.com/iCristalrope
Commit: a1d98b825d
Pull-request: https://github.com/SerenityOS/serenity/pull/14596
Reviewed-by: https://github.com/AtkinsSJ
Reviewed-by: https://github.com/krkk
Reviewed-by: https://github.com/trflynn89 ✅
5 changed files with 58 additions and 3 deletions
|
@ -99,6 +99,9 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
view_type_action_group->set_exclusive(true);
|
||||
view_type_action_group->add_action(*view_month_action);
|
||||
view_type_action_group->add_action(*view_year_action);
|
||||
auto default_view = Config::read_string("Calendar"sv, "View"sv, "DefaultView"sv, "Month"sv);
|
||||
if (default_view == "Year")
|
||||
view_year_action->set_checked(true);
|
||||
|
||||
(void)TRY(toolbar->try_add_action(prev_date_action));
|
||||
(void)TRY(toolbar->try_add_action(next_date_action));
|
||||
|
|
|
@ -13,16 +13,19 @@
|
|||
void CalendarSettingsWidget::apply_settings()
|
||||
{
|
||||
Config::write_string("Calendar"sv, "View"sv, "FirstDayOfWeek"sv, m_first_day_of_week_combobox->text());
|
||||
Config::write_string("Calendar"sv, "View"sv, "DefaultView"sv, m_default_view_combobox->text());
|
||||
}
|
||||
|
||||
void CalendarSettingsWidget::reset_default_values()
|
||||
{
|
||||
m_first_day_of_week_combobox->set_text("Sunday");
|
||||
m_default_view_combobox->set_text("Month");
|
||||
}
|
||||
|
||||
CalendarSettingsWidget::CalendarSettingsWidget()
|
||||
{
|
||||
load_from_gml(calendar_settings_widget_gml);
|
||||
|
||||
m_first_day_of_week_combobox = *find_descendant_of_type_named<GUI::ComboBox>("first_day_of_week");
|
||||
m_first_day_of_week_combobox->set_text(Config::read_string("Calendar"sv, "View"sv, "FirstDayOfWeek"sv, "Sunday"sv));
|
||||
m_first_day_of_week_combobox->set_only_allow_values_from_model(true);
|
||||
|
@ -30,4 +33,12 @@ CalendarSettingsWidget::CalendarSettingsWidget()
|
|||
m_first_day_of_week_combobox->on_change = [&](auto, auto) {
|
||||
set_modified(true);
|
||||
};
|
||||
|
||||
m_default_view_combobox = *find_descendant_of_type_named<GUI::ComboBox>("default_view");
|
||||
m_default_view_combobox->set_text(Config::read_string("Calendar"sv, "View"sv, "DefaultView"sv, "Month"sv));
|
||||
m_default_view_combobox->set_only_allow_values_from_model(true);
|
||||
m_default_view_combobox->set_model(*GUI::ItemListModel<StringView, Array<StringView, 2>>::create(m_view_modes));
|
||||
m_default_view_combobox->on_change = [&](auto, auto) {
|
||||
set_modified(true);
|
||||
};
|
||||
}
|
||||
|
|
|
@ -30,9 +30,40 @@
|
|||
fixed_width: 70
|
||||
}
|
||||
|
||||
@GUI::ComboBox {
|
||||
name: "first_day_of_week"
|
||||
}
|
||||
@GUI::ComboBox {
|
||||
name: "first_day_of_week"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@GUI::GroupBox {
|
||||
title: "Default view"
|
||||
fixed_height: 72
|
||||
layout: @GUI::VerticalBoxLayout {
|
||||
margins: [6]
|
||||
spacing: 2
|
||||
}
|
||||
|
||||
@GUI::Label {
|
||||
text: "Show the month or the year view when Calendar is started."
|
||||
word_wrap: true
|
||||
text_alignment: "CenterLeft"
|
||||
}
|
||||
|
||||
@GUI::Widget {
|
||||
layout: @GUI::HorizontalBoxLayout {
|
||||
spacing: 16
|
||||
}
|
||||
|
||||
@GUI::Label {
|
||||
text: "Default view:"
|
||||
text_alignment: "CenterLeft"
|
||||
fixed_width: 70
|
||||
}
|
||||
|
||||
@GUI::ComboBox {
|
||||
name: "default_view"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,6 +18,8 @@ public:
|
|||
|
||||
private:
|
||||
CalendarSettingsWidget();
|
||||
static constexpr Array<StringView, 2> const m_view_modes = { "Month"sv, "Year"sv };
|
||||
|
||||
RefPtr<GUI::ComboBox> m_first_day_of_week_combobox;
|
||||
RefPtr<GUI::ComboBox> m_default_view_combobox;
|
||||
};
|
||||
|
|
|
@ -45,6 +45,14 @@ Calendar::Calendar(Core::DateTime date_time, Mode mode)
|
|||
}
|
||||
}
|
||||
|
||||
auto default_view = Config::read_string("Calendar"sv, "View"sv, "DefaultView"sv, "Month"sv);
|
||||
if (default_view == "Year") {
|
||||
m_mode = Year;
|
||||
m_show_days = false;
|
||||
m_show_year = true;
|
||||
m_show_month_year = true;
|
||||
}
|
||||
|
||||
update_tiles(m_selected_date.year(), m_selected_date.month());
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue