1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 06:17:35 +00:00

BrowserSettings: Set window modified state

This commit is contained in:
Sam Atkins 2022-05-11 17:35:54 +01:00 committed by Andreas Kling
parent 4f9f948b6d
commit f27985a021
2 changed files with 26 additions and 14 deletions

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2021, Sam Atkins <atkinssj@serenityos.org> * Copyright (c) 2021-2022, Sam Atkins <atkinssj@serenityos.org>
* *
* SPDX-License-Identifier: BSD-2-Clause * SPDX-License-Identifier: BSD-2-Clause
*/ */
@ -61,26 +61,31 @@ BrowserSettingsWidget::BrowserSettingsWidget()
load_from_gml(browser_settings_widget_gml); load_from_gml(browser_settings_widget_gml);
m_homepage_url_textbox = find_descendant_of_type_named<GUI::TextBox>("homepage_url_textbox"); m_homepage_url_textbox = find_descendant_of_type_named<GUI::TextBox>("homepage_url_textbox");
m_homepage_url_textbox->set_text(Config::read_string("Browser", "Preferences", "Home", default_homepage_url)); m_homepage_url_textbox->set_text(Config::read_string("Browser", "Preferences", "Home", default_homepage_url), GUI::AllowCallback::No);
m_homepage_url_textbox->on_change = [&]() { set_modified(true); };
m_color_scheme_combobox = find_descendant_of_type_named<GUI::ComboBox>("color_scheme_combobox"); m_color_scheme_combobox = find_descendant_of_type_named<GUI::ComboBox>("color_scheme_combobox");
m_color_scheme_combobox->set_only_allow_values_from_model(true); m_color_scheme_combobox->set_only_allow_values_from_model(true);
m_color_scheme_combobox->set_model(adopt_ref(*new ColorSchemeModel())); m_color_scheme_combobox->set_model(adopt_ref(*new ColorSchemeModel()));
m_color_scheme_combobox->set_selected_index(0); m_color_scheme_combobox->set_selected_index(0, GUI::AllowCallback::No);
set_color_scheme(Config::read_string("Browser", "Preferences", "ColorScheme", default_color_scheme)); set_color_scheme(Config::read_string("Browser", "Preferences", "ColorScheme", default_color_scheme));
m_color_scheme_combobox->on_change = [&](auto, auto) { set_modified(true); };
m_show_bookmarks_bar_checkbox = find_descendant_of_type_named<GUI::CheckBox>("show_bookmarks_bar_checkbox"); m_show_bookmarks_bar_checkbox = find_descendant_of_type_named<GUI::CheckBox>("show_bookmarks_bar_checkbox");
m_show_bookmarks_bar_checkbox->set_checked(Config::read_bool("Browser", "Preferences", "ShowBookmarksBar", default_show_bookmarks_bar), GUI::AllowCallback::No); m_show_bookmarks_bar_checkbox->set_checked(Config::read_bool("Browser", "Preferences", "ShowBookmarksBar", default_show_bookmarks_bar), GUI::AllowCallback::No);
m_show_bookmarks_bar_checkbox->on_checked = [&](auto) { set_modified(true); };
m_enable_search_engine_checkbox = find_descendant_of_type_named<GUI::CheckBox>("enable_search_engine_checkbox"); m_enable_search_engine_checkbox = find_descendant_of_type_named<GUI::CheckBox>("enable_search_engine_checkbox");
m_search_engine_combobox_group = find_descendant_of_type_named<GUI::Widget>("search_engine_combobox_group"); m_search_engine_combobox_group = find_descendant_of_type_named<GUI::Widget>("search_engine_combobox_group");
m_search_engine_combobox = find_descendant_of_type_named<GUI::ComboBox>("search_engine_combobox"); m_search_engine_combobox = find_descendant_of_type_named<GUI::ComboBox>("search_engine_combobox");
m_custom_search_engine_group = find_descendant_of_type_named<GUI::Widget>("custom_search_engine_group"); m_custom_search_engine_group = find_descendant_of_type_named<GUI::Widget>("custom_search_engine_group");
m_custom_search_engine_textbox = find_descendant_of_type_named<GUI::TextBox>("custom_search_engine_textbox"); m_custom_search_engine_textbox = find_descendant_of_type_named<GUI::TextBox>("custom_search_engine_textbox");
m_custom_search_engine_textbox->on_change = [&]() { set_modified(true); };
m_enable_search_engine_checkbox->on_checked = [this](bool checked) { m_enable_search_engine_checkbox->on_checked = [this](bool checked) {
m_search_engine_combobox_group->set_enabled(checked); m_search_engine_combobox_group->set_enabled(checked);
m_custom_search_engine_group->set_enabled(checked && m_is_custom_search_engine); m_custom_search_engine_group->set_enabled(checked && m_is_custom_search_engine);
set_modified(true);
}; };
Vector<GUI::JsonArrayModel::FieldSpec> search_engine_fields; Vector<GUI::JsonArrayModel::FieldSpec> search_engine_fields;
@ -99,11 +104,13 @@ BrowserSettingsWidget::BrowserSettingsWidget()
auto url_format = m_search_engine_combobox->model()->index(cursor_index.row(), 1).data().to_string(); auto url_format = m_search_engine_combobox->model()->index(cursor_index.row(), 1).data().to_string();
m_is_custom_search_engine = url_format.is_empty(); m_is_custom_search_engine = url_format.is_empty();
m_custom_search_engine_group->set_enabled(m_is_custom_search_engine); m_custom_search_engine_group->set_enabled(m_is_custom_search_engine);
set_modified(true);
}; };
set_search_engine_url(Config::read_string("Browser", "Preferences", "SearchEngine", default_search_engine)); set_search_engine_url(Config::read_string("Browser", "Preferences", "SearchEngine", default_search_engine));
m_auto_close_download_windows_checkbox = find_descendant_of_type_named<GUI::CheckBox>("auto_close_download_windows_checkbox"); m_auto_close_download_windows_checkbox = find_descendant_of_type_named<GUI::CheckBox>("auto_close_download_windows_checkbox");
m_auto_close_download_windows_checkbox->set_checked(Config::read_bool("Browser", "Preferences", "CloseDownloadWidgetOnFinish", default_auto_close_download_windows), GUI::AllowCallback::No); m_auto_close_download_windows_checkbox->set_checked(Config::read_bool("Browser", "Preferences", "CloseDownloadWidgetOnFinish", default_auto_close_download_windows), GUI::AllowCallback::No);
m_auto_close_download_windows_checkbox->on_checked = [&](auto) { set_modified(true); };
} }
void BrowserSettingsWidget::set_color_scheme(StringView color_scheme) void BrowserSettingsWidget::set_color_scheme(StringView color_scheme)
@ -112,31 +119,31 @@ void BrowserSettingsWidget::set_color_scheme(StringView color_scheme)
for (int item_index = 0; item_index < m_color_scheme_combobox->model()->row_count(); ++item_index) { for (int item_index = 0; item_index < m_color_scheme_combobox->model()->row_count(); ++item_index) {
auto scheme = m_color_scheme_combobox->model()->index(item_index, 1).data().to_string(); auto scheme = m_color_scheme_combobox->model()->index(item_index, 1).data().to_string();
if (scheme == color_scheme) { if (scheme == color_scheme) {
m_color_scheme_combobox->set_selected_index(item_index); m_color_scheme_combobox->set_selected_index(item_index, GUI::AllowCallback::No);
found_color_scheme = true; found_color_scheme = true;
break; break;
} }
} }
if (!found_color_scheme) if (!found_color_scheme)
m_color_scheme_combobox->set_selected_index(0); m_color_scheme_combobox->set_selected_index(0, GUI::AllowCallback::No);
} }
void BrowserSettingsWidget::set_search_engine_url(StringView url) void BrowserSettingsWidget::set_search_engine_url(StringView url)
{ {
if (url.is_empty()) { if (url.is_empty()) {
m_enable_search_engine_checkbox->set_checked(false); m_enable_search_engine_checkbox->set_checked(false, GUI::AllowCallback::No);
m_search_engine_combobox_group->set_enabled(false); m_search_engine_combobox_group->set_enabled(false);
m_custom_search_engine_group->set_enabled(false); m_custom_search_engine_group->set_enabled(false);
m_search_engine_combobox->set_selected_index(0); m_search_engine_combobox->set_selected_index(0, GUI::AllowCallback::No);
} else { } else {
m_enable_search_engine_checkbox->set_checked(true); m_enable_search_engine_checkbox->set_checked(true, GUI::AllowCallback::No);
m_search_engine_combobox_group->set_enabled(true); m_search_engine_combobox_group->set_enabled(true);
bool found_url = false; bool found_url = false;
for (int item_index = 0; item_index < m_search_engine_combobox->model()->row_count(); ++item_index) { for (int item_index = 0; item_index < m_search_engine_combobox->model()->row_count(); ++item_index) {
auto url_format = m_search_engine_combobox->model()->index(item_index, 1).data().to_string(); auto url_format = m_search_engine_combobox->model()->index(item_index, 1).data().to_string();
if (url_format == url) { if (url_format == url) {
m_search_engine_combobox->set_selected_index(item_index); m_search_engine_combobox->set_selected_index(item_index, GUI::AllowCallback::No);
found_url = true; found_url = true;
break; break;
} }
@ -144,9 +151,9 @@ void BrowserSettingsWidget::set_search_engine_url(StringView url)
if (!found_url) { if (!found_url) {
m_is_custom_search_engine = true; m_is_custom_search_engine = true;
m_custom_search_engine_textbox->set_text(url); m_custom_search_engine_textbox->set_text(url, GUI::AllowCallback::No);
// We assume that "Custom" is the last item // We assume that "Custom" is the last item
m_search_engine_combobox->set_selected_index(m_search_engine_combobox->model()->row_count() - 1); m_search_engine_combobox->set_selected_index(m_search_engine_combobox->model()->row_count() - 1, GUI::AllowCallback::No);
m_custom_search_engine_group->set_enabled(true); m_custom_search_engine_group->set_enabled(true);
} else { } else {
m_custom_search_engine_group->set_enabled(false); m_custom_search_engine_group->set_enabled(false);

View file

@ -114,12 +114,15 @@ ContentFilterSettingsWidget::ContentFilterSettingsWidget()
m_domain_list_view = find_descendant_of_type_named<GUI::ListView>("domain_list_view"); m_domain_list_view = find_descendant_of_type_named<GUI::ListView>("domain_list_view");
m_add_new_domain_button = find_descendant_of_type_named<GUI::Button>("add_new_domain_button"); m_add_new_domain_button = find_descendant_of_type_named<GUI::Button>("add_new_domain_button");
m_enable_content_filtering_checkbox->set_checked(Config::read_bool("Browser", "Preferences", "EnableContentFilters")); m_enable_content_filtering_checkbox->set_checked(Config::read_bool("Browser", "Preferences", "EnableContentFilters"), GUI::AllowCallback::No);
m_enable_content_filtering_checkbox->on_checked = [&](auto) { set_modified(true); };
m_add_new_domain_button->on_click = [&](unsigned) { m_add_new_domain_button->on_click = [&](unsigned) {
String text; String text;
if (GUI::InputBox::show(window(), text, "Enter domain name", "Add domain to Content Filter") == GUI::Dialog::ExecOK) if (GUI::InputBox::show(window(), text, "Enter domain name", "Add domain to Content Filter") == GUI::Dialog::ExecOK) {
m_domain_list_model->add_domain(std::move(text)); m_domain_list_model->add_domain(std::move(text));
set_modified(true);
}
}; };
m_domain_list_model = make_ref_counted<DomainListModel>(); m_domain_list_model = make_ref_counted<DomainListModel>();
@ -128,8 +131,10 @@ ContentFilterSettingsWidget::ContentFilterSettingsWidget()
m_domain_list_view->set_model(m_domain_list_model); m_domain_list_view->set_model(m_domain_list_model);
auto delete_action = GUI::CommonActions::make_delete_action([&](GUI::Action const&) { auto delete_action = GUI::CommonActions::make_delete_action([&](GUI::Action const&) {
if (!m_domain_list_view->selection().is_empty()) if (!m_domain_list_view->selection().is_empty()) {
m_domain_list_model->delete_domain(m_domain_list_view->selection().first().row()); m_domain_list_model->delete_domain(m_domain_list_view->selection().first().row());
set_modified(true);
}
}); });
m_entry_context_menu = GUI::Menu::construct(); m_entry_context_menu = GUI::Menu::construct();
m_entry_context_menu->add_action(delete_action); m_entry_context_menu->add_action(delete_action);