From 5d7331b4ed76b1dff6681964ce534d64cf986ac3 Mon Sep 17 00:00:00 2001 From: Kemal Zebari Date: Fri, 20 Jan 2023 11:21:40 -0800 Subject: [PATCH] Browser: Disallow empty URLs in the bookmark editor When an empty URL is given to `BookmarkEditor`, it will now disable the button that saves the bookmark change since an empty URL is an invalid URL. --- Userland/Applications/Browser/BookmarksBarWidget.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Userland/Applications/Browser/BookmarksBarWidget.cpp b/Userland/Applications/Browser/BookmarksBarWidget.cpp index efaef4a5f6..e3e02a2bd1 100644 --- a/Userland/Applications/Browser/BookmarksBarWidget.cpp +++ b/Userland/Applications/Browser/BookmarksBarWidget.cpp @@ -58,15 +58,19 @@ private: m_title_textbox->set_focus(true); m_title_textbox->select_all(); - m_url_textbox = *widget->find_descendant_of_type_named("url_textbox"); - m_url_textbox->set_text(url); - auto& ok_button = *widget->find_descendant_of_type_named("ok_button"); ok_button.on_click = [this](auto) { done(ExecResult::OK); }; ok_button.set_default(true); + m_url_textbox = *widget->find_descendant_of_type_named("url_textbox"); + m_url_textbox->set_text(url); + m_url_textbox->on_change = [this, &ok_button]() { + auto has_url = !m_url_textbox->text().is_empty(); + ok_button.set_enabled(has_url); + }; + auto& cancel_button = *widget->find_descendant_of_type_named("cancel_button"); cancel_button.on_click = [this](auto) { done(ExecResult::Cancel);