summaryrefslogtreecommitdiff
path: root/Userland/Applications
diff options
context:
space:
mode:
authorXexxa <93391300+Xexxa@users.noreply.github.com>2022-06-25 21:08:17 +0200
committerLinus Groh <mail@linusgroh.de>2022-06-26 22:18:30 +0100
commit65714554997bacb6fdcc09da0b763defe252b435 (patch)
treef13729aeda72564952f5fa76165ea02e6bc7749b /Userland/Applications
parentef46100fd39bdeb7d590f29e1a7cc5f2d6fc0b47 (diff)
downloadserenity-65714554997bacb6fdcc09da0b763defe252b435.zip
Browser+BrowserSettings: Add preference for new tab
Diffstat (limited to 'Userland/Applications')
-rw-r--r--Userland/Applications/Browser/Browser.h1
-rw-r--r--Userland/Applications/Browser/BrowserWindow.cpp4
-rw-r--r--Userland/Applications/Browser/main.cpp2
-rw-r--r--Userland/Applications/BrowserSettings/BrowserSettingsWidget.cpp15
-rw-r--r--Userland/Applications/BrowserSettings/BrowserSettingsWidget.gml47
-rw-r--r--Userland/Applications/BrowserSettings/BrowserSettingsWidget.h1
6 files changed, 59 insertions, 11 deletions
diff --git a/Userland/Applications/Browser/Browser.h b/Userland/Applications/Browser/Browser.h
index b9d186e4ae..14d7e7d304 100644
--- a/Userland/Applications/Browser/Browser.h
+++ b/Userland/Applications/Browser/Browser.h
@@ -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;
diff --git a/Userland/Applications/Browser/BrowserWindow.cpp b/Userland/Applications/Browser/BrowserWindow.cpp
index 52a74eb20c..bc2b96ca28 100644
--- a/Userland/Applications/Browser/BrowserWindow.cpp
+++ b/Userland/Applications/Browser/BrowserWindow.cpp
@@ -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);
diff --git a/Userland/Applications/Browser/main.cpp b/Userland/Applications/Browser/main.cpp
index 65c9cd5aab..afcad266db 100644
--- a/Userland/Applications/Browser/main.cpp
+++ b/Userland/Applications/Browser/main.cpp
@@ -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);
diff --git a/Userland/Applications/BrowserSettings/BrowserSettingsWidget.cpp b/Userland/Applications/BrowserSettings/BrowserSettingsWidget.cpp
index a294cb04cc..fdffade119 100644
--- a/Userland/Applications/BrowserSettings/BrowserSettingsWidget.cpp
+++ b/Userland/Applications/BrowserSettings/BrowserSettingsWidget.cpp
@@ -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);
diff --git a/Userland/Applications/BrowserSettings/BrowserSettingsWidget.gml b/Userland/Applications/BrowserSettings/BrowserSettingsWidget.gml
index da4fabd1d1..97a76dc1cf 100644
--- a/Userland/Applications/BrowserSettings/BrowserSettingsWidget.gml
+++ b/Userland/Applications/BrowserSettings/BrowserSettingsWidget.gml
@@ -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::TextBox {
- name: "homepage_url_textbox"
- placeholder: "https://example.com"
+ @GUI::Widget {
+ layout: @GUI::VerticalBoxLayout {
+ }
+
+ @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"
+ }
+ }
}
}
}
diff --git a/Userland/Applications/BrowserSettings/BrowserSettingsWidget.h b/Userland/Applications/BrowserSettings/BrowserSettingsWidget.h
index a13bbe5077..2743fe2336 100644
--- a/Userland/Applications/BrowserSettings/BrowserSettingsWidget.h
+++ b/Userland/Applications/BrowserSettings/BrowserSettingsWidget.h
@@ -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;