Commit f121ecd2 authored by Kurt Hindenburg's avatar Kurt Hindenburg

Use std::any_of instead of loop

parent 616f5554
...@@ -30,10 +30,12 @@ ...@@ -30,10 +30,12 @@
#include <KBookmarkManager> #include <KBookmarkManager>
#include <KBookmark> #include <KBookmark>
#include <algorithm> // std::any_of
BookmarkMenu::BookmarkMenu (KBookmarkManager *mgr, KBookmarkOwner *owner, QMenu *parentMenu, KActionCollection *collec) : BookmarkMenu::BookmarkMenu (KBookmarkManager *mgr, KBookmarkOwner *owner, QMenu *parentMenu, KActionCollection *collec) :
KBookmarkMenu (mgr, owner, parentMenu, collec) KBookmarkMenu (mgr, owner, parentMenu, collec)
{ {
// We need to hijack the action // We need to hijack the action - note this only hijacks top-level action
QAction *bookmarkAction = collec->action(QStringLiteral("add_bookmark")); QAction *bookmarkAction = collec->action(QStringLiteral("add_bookmark"));
disconnect(bookmarkAction, nullptr, this, nullptr); disconnect(bookmarkAction, nullptr, this, nullptr);
connect(bookmarkAction, &QAction::triggered, this, &BookmarkMenu::maybeAddBookmark); connect(bookmarkAction, &QAction::triggered, this, &BookmarkMenu::maybeAddBookmark);
...@@ -42,13 +44,14 @@ BookmarkMenu::BookmarkMenu (KBookmarkManager *mgr, KBookmarkOwner *owner, QMenu ...@@ -42,13 +44,14 @@ BookmarkMenu::BookmarkMenu (KBookmarkManager *mgr, KBookmarkOwner *owner, QMenu
void BookmarkMenu::maybeAddBookmark() void BookmarkMenu::maybeAddBookmark()
{ {
// Check for duplicates first // Check for duplicates first
// This only catches duplicates in top-level (ie not sub-folders) // This only catches duplicates in top-level (ie not sub-folders);
// this is due to only the top-level add_bookmark is hijacked.
const KBookmarkGroup rootGroup = manager()->root(); const KBookmarkGroup rootGroup = manager()->root();
const QUrl currUrl = owner()->currentUrl(); const QUrl currUrl = owner()->currentUrl();
for (const QUrl &url : rootGroup.groupUrlList()) { const auto urlList = rootGroup.groupUrlList();
if (url == currUrl) { if (std::any_of(urlList.constBegin(), urlList.constEnd(),
return; [currUrl] (const QUrl &url) { return url == currUrl; })) {
} return;
} }
slotAddBookmark(); slotAddBookmark();
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment