mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 15:40:19 +00:00
Browser+BrowserSettings: Add preference for new tab
This commit is contained in:
parent
ef46100fd3
commit
6571455499
Notes:
sideshowbarker
2024-07-17 09:57:27 +09:00
Author: https://github.com/Xexxa Commit: https://github.com/SerenityOS/serenity/commit/6571455499 Pull-request: https://github.com/SerenityOS/serenity/pull/14389 Reviewed-by: https://github.com/linusg ✅ Reviewed-by: https://github.com/networkException
6 changed files with 58 additions and 10 deletions
|
@ -12,6 +12,7 @@
|
|||
namespace Browser {
|
||||
|
||||
extern String g_home_url;
|
||||
extern String g_new_tab_url;
|
||||
extern String g_search_engine;
|
||||
extern Vector<String> g_content_filters;
|
||||
extern Vector<String> g_proxies;
|
||||
|
|
|
@ -100,7 +100,7 @@ BrowserWindow::BrowserWindow(CookieJar& cookie_jar, URL url)
|
|||
};
|
||||
|
||||
m_window_actions.on_create_new_tab = [this] {
|
||||
create_new_tab(Browser::url_from_user_input(Browser::g_home_url), true);
|
||||
create_new_tab(Browser::url_from_user_input(Browser::g_new_tab_url), true);
|
||||
};
|
||||
|
||||
m_window_actions.on_next_tab = [this] {
|
||||
|
@ -606,6 +606,8 @@ void BrowserWindow::config_string_did_change(String const& domain, String const&
|
|||
Browser::g_search_engine = value;
|
||||
else if (key == "Home")
|
||||
Browser::g_home_url = value;
|
||||
else if (key == "NewTab")
|
||||
Browser::g_new_tab_url = value;
|
||||
} else if (group.starts_with("Proxy:")) {
|
||||
dbgln("Proxy mapping changed: {}/{} = {}", group, key, value);
|
||||
auto proxy_spec = group.substring_view(6);
|
||||
|
|
|
@ -31,6 +31,7 @@ namespace Browser {
|
|||
|
||||
String g_search_engine;
|
||||
String g_home_url;
|
||||
String g_new_tab_url;
|
||||
Vector<String> g_content_filters;
|
||||
bool g_content_filters_enabled { true };
|
||||
Vector<String> g_proxies;
|
||||
|
@ -94,6 +95,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
auto app_icon = GUI::Icon::default_icon("app-browser");
|
||||
|
||||
Browser::g_home_url = Config::read_string("Browser", "Preferences", "Home", "file:///res/html/misc/welcome.html");
|
||||
Browser::g_new_tab_url = Config::read_string("Browser", "Preferences", "NewTab", "file:///res/html/misc/welcome.html");
|
||||
Browser::g_search_engine = Config::read_string("Browser", "Preferences", "SearchEngine", {});
|
||||
Browser::g_content_filters_enabled = Config::read_bool("Browser", "Preferences", "EnableContentFilters", true);
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue