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

Browser+BrowserSettings: Add preference for new tab

This commit is contained in:
Xexxa 2022-06-25 21:08:17 +02:00 committed by Linus Groh
parent ef46100fd3
commit 6571455499
6 changed files with 58 additions and 10 deletions

View file

@ -13,6 +13,7 @@
#include <LibGUI/Model.h>
static String default_homepage_url = "file:///res/html/misc/welcome.html";
static String default_new_tab_url = "file:///res/html/misc/welcome.html";
static String default_search_engine = "";
static String default_color_scheme = "auto";
static bool default_show_bookmarks_bar = true;
@ -64,6 +65,10 @@ BrowserSettingsWidget::BrowserSettingsWidget()
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_new_tab_url_textbox = find_descendant_of_type_named<GUI::TextBox>("new_tab_url_textbox");
m_new_tab_url_textbox->set_text(Config::read_string("Browser", "Preferences", "NewTab", default_new_tab_url), GUI::AllowCallback::No);
m_new_tab_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->set_only_allow_values_from_model(true);
m_color_scheme_combobox->set_model(adopt_ref(*new ColorSchemeModel()));
@ -172,6 +177,15 @@ void BrowserSettingsWidget::apply_settings()
}
Config::write_string("Browser", "Preferences", "Home", homepage_url);
auto new_tab_url = m_new_tab_url_textbox->text();
if (!URL(new_tab_url).is_valid()) {
GUI::MessageBox::show_error(this->window(), "The new tab URL you have entered is not valid");
m_new_tab_url_textbox->select_all();
m_new_tab_url_textbox->set_focus(true);
return;
}
Config::write_string("Browser", "Preferences", "NewTab", new_tab_url);
Config::write_bool("Browser", "Preferences", "ShowBookmarksBar", m_show_bookmarks_bar_checkbox->is_checked());
auto color_scheme_index = m_color_scheme_combobox->selected_index();
@ -194,6 +208,7 @@ void BrowserSettingsWidget::apply_settings()
void BrowserSettingsWidget::reset_default_values()
{
m_homepage_url_textbox->set_text(default_homepage_url);
m_new_tab_url_textbox->set_text(default_new_tab_url);
m_show_bookmarks_bar_checkbox->set_checked(default_show_bookmarks_bar);
set_color_scheme(default_color_scheme);
m_auto_close_download_windows_checkbox->set_checked(default_auto_close_download_windows);

View file

@ -9,7 +9,7 @@
title: "Homepage"
fixed_height: 70
layout: @GUI::VerticalBoxLayout {
margins: [16, 8, 8]
margins: [2, 8, 2]
spacing: 2
}
@ -24,15 +24,42 @@
icon: "/res/icons/32x32/home.png"
}
@GUI::Label {
text: "URL:"
text_alignment: "CenterLeft"
fixed_width: 30
}
@GUI::Widget {
layout: @GUI::VerticalBoxLayout {
}
@GUI::TextBox {
name: "homepage_url_textbox"
placeholder: "https://example.com"
@GUI::Widget {
layout: @GUI::HorizontalBoxLayout {
spacing: 16
}
@GUI::Label {
text: "URL:"
text_alignment: "CenterLeft"
fixed_width: 45
}
@GUI::TextBox {
name: "homepage_url_textbox"
placeholder: "https://example.com"
}
}
@GUI::Widget {
layout: @GUI::HorizontalBoxLayout {
spacing: 16
}
@GUI::Label {
text: "New Tab:"
text_alignment: "CenterLeft"
fixed_width: 45
}
@GUI::TextBox {
name: "new_tab_url_textbox"
placeholder: "https://example.com"
}
}
}
}
}

View file

@ -24,6 +24,7 @@ private:
BrowserSettingsWidget();
RefPtr<GUI::TextBox> m_homepage_url_textbox;
RefPtr<GUI::TextBox> m_new_tab_url_textbox;
void set_color_scheme(StringView);
RefPtr<GUI::ComboBox> m_color_scheme_combobox;
RefPtr<GUI::CheckBox> m_show_bookmarks_bar_checkbox;