Skip to content

Commit

Permalink
UI/Qt: Show search engine name in location bar
Browse files Browse the repository at this point in the history
The placeholder text shows "Search or enter web address" which doesn't
tell the user about *how* the search will be performed. Other popular
open source browsers show the search engine that will be used. For
example:

	Chromium: "Search **engine** or type a URL"
	Firefox: "Search with **engine** or enter address"

This change changes the placeholder text of the location bar to show
"Search with **engine** or enter web address".

(cherry picked from commit 637ccbec3524727e22d07da5331f627165759791)
  • Loading branch information
Hugh Davenport authored and nico committed Nov 1, 2024
1 parent 716bf5c commit 2e36e12
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 4 deletions.
18 changes: 14 additions & 4 deletions Ladybird/Qt/LocationEdit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ namespace Ladybird {
LocationEdit::LocationEdit(QWidget* parent)
: QLineEdit(parent)
{
if (Settings::the()->enable_search())
setPlaceholderText("Search or enter web address");
else
setPlaceholderText("Enter web address");
update_placeholder();
QObject::connect(Settings::the(), &Settings::enable_search_changed, this, &LocationEdit::update_placeholder);
QObject::connect(Settings::the(), &Settings::search_engine_changed, this, &LocationEdit::update_placeholder);

m_autocomplete = make<AutoComplete>(this);
this->setCompleter(m_autocomplete);

Expand Down Expand Up @@ -76,6 +76,16 @@ void LocationEdit::focusOutEvent(QFocusEvent* event)
highlight_location();
}

void LocationEdit::update_placeholder()
{
if (Settings::the()->enable_search())
setPlaceholderText(qstring_from_ak_string(
MUST(String::formatted("Search with {} or enter web address",
Settings::the()->search_engine().name))));
else
setPlaceholderText("Enter web address");
}

void LocationEdit::highlight_location()
{
auto url = ak_string_from_qstring(text());
Expand Down
1 change: 1 addition & 0 deletions Ladybird/Qt/LocationEdit.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class LocationEdit final : public QLineEdit {
virtual void focusInEvent(QFocusEvent* event) override;
virtual void focusOutEvent(QFocusEvent* event) override;

void update_placeholder();
void highlight_location();
AK::OwnPtr<AutoComplete> m_autocomplete;

Expand Down
2 changes: 2 additions & 0 deletions Ladybird/Qt/Settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ void Settings::set_search_engine(WebView::SearchEngine search_engine)
{
m_qsettings->setValue("search_engine_name", qstring_from_ak_string(search_engine.name));
m_search_engine = move(search_engine);
emit search_engine_changed(m_search_engine);
}

Settings::EngineProvider Settings::autocomplete_engine()
Expand Down Expand Up @@ -109,6 +110,7 @@ bool Settings::enable_search()
void Settings::set_enable_search(bool enable)
{
m_qsettings->setValue("enable_search", enable);
emit enable_search_changed(enable);
}

bool Settings::show_menubar()
Expand Down
2 changes: 2 additions & 0 deletions Ladybird/Qt/Settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ class Settings : public QObject {

signals:
void show_menubar_changed(bool show_menubar);
void enable_search_changed(bool enable);
void search_engine_changed(WebView::SearchEngine engine);

protected:
Settings();
Expand Down

0 comments on commit 2e36e12

Please sign in to comment.