Commit befaaa02 authored by Martin Tobias Holmedahl Sandsmark's avatar Martin Tobias Holmedahl Sandsmark Committed by Kurt Hindenburg

Do not allow adding duplicates in bookmarks

This currently only catches bookmarks in top-level (ie not sub-folders)

Original code by Tomaz Canabrava <tcanabrava@kde.org>

BUG: 408939
FIXED-IN: 19.12

kde/konsole!8
parent 23046310
......@@ -31,11 +31,11 @@
// KDE
#include <KShell>
#include <KBookmarkMenu>
#include <KBookmarkOwner>
#include <KLocalizedString>
// Konsole
#include "BookmarkMenu.h"
#include "ViewProperties.h"
using namespace Konsole;
......@@ -45,7 +45,6 @@ BookmarkHandler::BookmarkHandler(KActionCollection *collection, QMenu *menu, boo
QObject(parent),
KBookmarkOwner(),
_menu(menu),
_bookmarkMenu(nullptr),
_file(QString()),
_toplevel(toplevel),
_activeView(nullptr),
......@@ -64,14 +63,14 @@ BookmarkHandler::BookmarkHandler(KActionCollection *collection, QMenu *menu, boo
}
KBookmarkManager *manager = KBookmarkManager::managerForFile(_file, QStringLiteral("konsole"));
manager->setUpdate(true);
_bookmarkMenu = new KBookmarkMenu(manager, this, _menu, toplevel ? collection : nullptr);
BookmarkMenu *bookmarkMenu = new BookmarkMenu(manager, this, _menu, toplevel ? collection : nullptr);
bookmarkMenu->setParent(this);
}
BookmarkHandler::~BookmarkHandler()
{
delete _bookmarkMenu;
}
void BookmarkHandler::openBookmark(const KBookmark &bm, Qt::MouseButtons, Qt::KeyboardModifiers)
......
......@@ -33,7 +33,6 @@
#include "konsoleprivate_export.h"
class QMenu;
class KBookmarkMenu;
class KActionCollection;
namespace Konsole {
......@@ -121,7 +120,6 @@ private:
QString iconForView(ViewProperties *view) const;
QMenu *_menu;
KBookmarkMenu *_bookmarkMenu;
QString _file;
bool _toplevel;
ViewProperties *_activeView;
......
/* This file was part of the KDE libraries
Copyright 2019 by Tomaz Canabrava <tcanabrava@kde.org>
Copyright 2019 by Martin Sandsmark <martin.sandsmark@kde.org>
library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation, version 2
or ( at your option ), any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
// Own
#include "BookmarkMenu.h"
// KDE
#include <KActionCollection>
// Qt
#include <QAction>
#include <KBookmarkManager>
#include <KBookmark>
BookmarkMenu::BookmarkMenu (KBookmarkManager *mgr, KBookmarkOwner *owner, QMenu *parentMenu, KActionCollection *collec) :
KBookmarkMenu (mgr, owner, parentMenu, collec)
{
// We need to hijack the action
QAction *bookmarkAction = collec->action(QStringLiteral("add_bookmark"));
disconnect(bookmarkAction, nullptr, this, nullptr);
connect(bookmarkAction, &QAction::triggered, this, &BookmarkMenu::maybeAddBookmark);
}
void BookmarkMenu::maybeAddBookmark()
{
// Check for duplicates first
const KBookmarkGroup rootGroup = manager()->root();
const QUrl currUrl = owner()->currentUrl();
for (const QUrl &url : rootGroup.groupUrlList()) {
if (url == currUrl) {
return;
}
}
slotAddBookmark();
}
/* This file was part of the KDE libraries
Copyright 2019 by Tomaz Canabrava <tcanabrava@kde.org>
Copyright 2019 by Martin Sandsmark <martin.sandsmark@kde.org>
library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation, version 2
or ( at your option ), any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef BOOKMARKMENU_H
#define BOOKMARKMENU_H
// KDE
#include <KBookmarkMenu>
// Konsole
#include "konsoleprivate_export.h"
/* Hackish hack to mitigate a broken behavior of KBookmarkMenu.
* slotAddBookmark accepts duplicates and it's fragile code,
* that thing really deserves a rewrite.
* the easiest way is to "hijack" it's protected method to public
* and just cast around.
*/
class KONSOLEPRIVATE_EXPORT BookmarkMenu : public KBookmarkMenu
{
Q_OBJECT
public:
BookmarkMenu (KBookmarkManager *mgr, KBookmarkOwner *owner, QMenu *parentMenu, KActionCollection *collec);
private Q_SLOTS:
void maybeAddBookmark();
};
#endif//BOOKMARKMENU_H
......@@ -53,6 +53,7 @@ set(konsoleprivate_SRCS ${sessionadaptors_SRCS}
${windowadaptors_SRCS}
hsluv.c
BookmarkHandler.cpp
BookmarkMenu.cpp
ColorScheme.cpp
ColorSchemeManager.cpp
ColorSchemeEditor.cpp
......
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