mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-04 05:20:30 +00:00
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.
This commit is contained in:
parent
0ad131e13d
commit
8f5cc613d2
Notes:
sideshowbarker
2024-07-17 05:02:42 +09:00
Author: https://github.com/kemzeb Commit: https://github.com/SerenityOS/serenity/commit/8f5cc613d2 Pull-request: https://github.com/SerenityOS/serenity/pull/18630 Reviewed-by: https://github.com/gmta ✅
2 changed files with 26 additions and 6 deletions
|
@ -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));
|
||||
|
|
|
@ -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
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue