mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 06:07:34 +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
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)
|
if (on_bookmark_change)
|
||||||
on_bookmark_change();
|
on_bookmark_change();
|
||||||
|
|
||||||
if (auto result = edit_bookmark(url, PerformEditOn::NewBookmark); result.is_error()) {
|
values = BookmarkEditor::edit_bookmark(window(), title, url, PerformEditOn::NewBookmark);
|
||||||
(void)remove_bookmark(url);
|
if (values.is_empty())
|
||||||
return Error::copy(result.release_error());
|
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 {};
|
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) {
|
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_title = model()->index(item_index, 0).data().to_deprecated_string();
|
||||||
auto item_url = model()->index(item_index, 1).data().to_deprecated_string();
|
auto item_url = model()->index(item_index, 1).data().to_deprecated_string();
|
||||||
|
|
||||||
if (item_url == url) {
|
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) {
|
TRY(update_model(values, [item_index](auto& model, auto&& values) {
|
||||||
return model.set(item_index, move(values));
|
return model.set(item_index, move(values));
|
||||||
|
|
|
@ -44,7 +44,7 @@ public:
|
||||||
bool contains_bookmark(StringView url);
|
bool contains_bookmark(StringView url);
|
||||||
ErrorOr<void> remove_bookmark(StringView url);
|
ErrorOr<void> remove_bookmark(StringView url);
|
||||||
ErrorOr<void> add_bookmark(StringView url, StringView title);
|
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
|
virtual Optional<GUI::UISize> calculated_min_size() const override
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue