mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-28 20:29:03 +00:00
LibWebView+UI: Introduce a persistent settings object
This adds a WebView::Settings class to own persistent browser settings. In this first pass, it now owns the new tab page URL and search engine settings. For simplicitly, we currently use a JSON format for these settings. They are stored alongside the cookie database. As of this commit, the saved JSON will have the form: { "newTabPageURL": "about:blank", "searchEngine": { "name": "Google" } } (The search engine is an object to allow room for a future patch to implement custom search engine URLs.) For Qt, this replaces the management of these particular settings in the Qt settings UI. We will have an internal browser page to control these settings instead. In the future, we will want to port all settings to this new class. We will also want to allow UI-specific settings (such as whether the hamburger menu is displayed in Qt).
This commit is contained in:
parent
b4fde1ef64
commit
e084a86861
Notes:
github-actions[bot]
2025-03-22 16:28:56 +00:00
Author: https://github.com/trflynn89
Commit: e084a86861
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/4036
28 changed files with 313 additions and 246 deletions
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2023-2024, Tim Flynn <trflynn89@serenityos.org>
|
||||
* Copyright (c) 2023-2025, Tim Flynn <trflynn89@ladybird.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
@ -628,15 +628,15 @@ static void copy_data_to_clipboard(StringView data, NSPasteboardType pasteboard_
|
|||
}
|
||||
auto* search_selected_text_menu_item = [self.page_context_menu itemWithTag:CONTEXT_MENU_SEARCH_SELECTED_TEXT_TAG];
|
||||
|
||||
auto selected_text = self.observer
|
||||
auto const& search_engine = WebView::Application::settings().search_engine();
|
||||
|
||||
auto selected_text = self.observer && search_engine.has_value()
|
||||
? m_web_view_bridge->selected_text_with_whitespace_collapsed()
|
||||
: OptionalNone {};
|
||||
TemporaryChange change_url { m_context_menu_search_text, move(selected_text) };
|
||||
|
||||
if (m_context_menu_search_text.has_value()) {
|
||||
auto* delegate = (ApplicationDelegate*)[NSApp delegate];
|
||||
auto action_text = WebView::format_search_query_for_display([delegate searchEngine].query_url, *m_context_menu_search_text);
|
||||
|
||||
auto action_text = WebView::format_search_query_for_display(search_engine->query_url, *m_context_menu_search_text);
|
||||
[search_selected_text_menu_item setTitle:Ladybird::string_to_ns_string(action_text)];
|
||||
[search_selected_text_menu_item setHidden:NO];
|
||||
} else {
|
||||
|
@ -1136,9 +1136,11 @@ static void copy_data_to_clipboard(StringView data, NSPasteboardType pasteboard_
|
|||
|
||||
- (void)searchSelectedText:(id)sender
|
||||
{
|
||||
auto* delegate = (ApplicationDelegate*)[NSApp delegate];
|
||||
auto const& search_engine = WebView::Application::settings().search_engine();
|
||||
if (!search_engine.has_value())
|
||||
return;
|
||||
|
||||
auto url_string = MUST(String::formatted([delegate searchEngine].query_url, URL::percent_encode(*m_context_menu_search_text)));
|
||||
auto url_string = MUST(String::formatted(search_engine->query_url, URL::percent_encode(*m_context_menu_search_text)));
|
||||
auto url = URL::Parser::basic_parse(url_string);
|
||||
VERIFY(url.has_value());
|
||||
[self.observer onCreateNewTab:url.release_value() activateTab:Web::HTML::ActivateTab::Yes];
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue