summaryrefslogtreecommitdiff
path: root/Userland/Applications
diff options
context:
space:
mode:
authorKemal Zebari <kemalzebra@gmail.com>2023-05-03 15:01:52 -0700
committerAndreas Kling <kling@serenityos.org>2023-05-23 06:03:13 +0200
commit8f5cc613d22e6cb1a66d3d2bcc8b140813558d24 (patch)
treec7e64ee1ebe936b51998c3fc1e13a88269e20e07 /Userland/Applications
parent0ad131e13de00945bc3ddbacab3990b0e228963b (diff)
downloadserenity-8f5cc613d22e6cb1a66d3d2bcc8b140813558d24.zip
Browser: Don't show error message box when canceling editor dialog
Currently, an error message box appears when a user tries to cancel the editor dialog while editing or adding a bookmark. This snapshot resolves this by having `add_bookmark()` and `BookmarksBarWidget::edit_bookmark()` perform an if check on the result of `BookmarkEditor::edit_bookmark()` to see if the dialog was canceled.
Diffstat (limited to 'Userland/Applications')
-rw-r--r--Userland/Applications/Browser/BookmarksBarWidget.cpp30
-rw-r--r--Userland/Applications/Browser/BookmarksBarWidget.h2
2 files changed, 26 insertions, 6 deletions
diff --git a/Userland/Applications/Browser/BookmarksBarWidget.cpp b/Userland/Applications/Browser/BookmarksBarWidget.cpp
index ec30449564..ec38aa44a2 100644
--- a/Userland/Applications/Browser/BookmarksBarWidget.cpp
+++ b/Userland/Applications/Browser/BookmarksBarWidget.cpp
@@ -321,22 +321,42 @@ ErrorOr<void> BookmarksBarWidget::add_bookmark(StringView url, StringView title)
if (on_bookmark_change)
on_bookmark_change();
- if (auto result = edit_bookmark(url, PerformEditOn::NewBookmark); result.is_error()) {
- (void)remove_bookmark(url);
- return Error::copy(result.release_error());
+ values = BookmarkEditor::edit_bookmark(window(), title, url, PerformEditOn::NewBookmark);
+ if (values.is_empty())
+ return remove_bookmark(url);
+
+ auto model_has_updated = false;
+ for (int item_index = 0; item_index < model()->row_count(); item_index++) {
+ auto item_url = model()->index(item_index, 1).data().to_deprecated_string();
+
+ if (item_url == url) {
+ TRY(update_model(values, [item_index](auto& model, auto&& values) {
+ return model.set(item_index, move(values));
+ }));
+ model_has_updated = true;
+ break;
+ }
}
+ if (!model_has_updated)
+ return Error::from_string_view("Bookmark not found"sv);
+
+ if (on_bookmark_change)
+ on_bookmark_change();
+
return {};
}
-ErrorOr<void> BookmarksBarWidget::edit_bookmark(StringView url, PerformEditOn perform_edit_on)
+ErrorOr<void> BookmarksBarWidget::edit_bookmark(StringView url)
{
for (int item_index = 0; item_index < model()->row_count(); ++item_index) {
auto item_title = model()->index(item_index, 0).data().to_deprecated_string();
auto item_url = model()->index(item_index, 1).data().to_deprecated_string();
if (item_url == url) {
- auto values = BookmarkEditor::edit_bookmark(window(), item_title, item_url, perform_edit_on);
+ auto values = BookmarkEditor::edit_bookmark(window(), item_title, item_url, PerformEditOn::ExistingBookmark);
+ if (values.is_empty())
+ return {};
TRY(update_model(values, [item_index](auto& model, auto&& values) {
return model.set(item_index, move(values));
diff --git a/Userland/Applications/Browser/BookmarksBarWidget.h b/Userland/Applications/Browser/BookmarksBarWidget.h
index c4bc426cfe..cd12af5715 100644
--- a/Userland/Applications/Browser/BookmarksBarWidget.h
+++ b/Userland/Applications/Browser/BookmarksBarWidget.h
@@ -44,7 +44,7 @@ public:
bool contains_bookmark(StringView url);
ErrorOr<void> remove_bookmark(StringView url);
ErrorOr<void> add_bookmark(StringView url, StringView title);
- ErrorOr<void> edit_bookmark(StringView url, PerformEditOn perform_edit_on = PerformEditOn::ExistingBookmark);
+ ErrorOr<void> edit_bookmark(StringView url);
virtual Optional<GUI::UISize> calculated_min_size() const override
{