Commit 6db7f8d2 authored by Ahmad Samir's avatar Ahmad Samir
Browse files

[BookmarkMenu] Adapt the code to KBookmarks 5.69 changes

Starting from KBookmarks 5.69 the ctor that took a KActionCollection
parameter has been deprecated, and we need to manually add the various
bookmark actions to the actionCollection so that they show up in the
shortcusts editor.

Move the code that overrides the add bookmark shortcut, Ctrl+B, to the
BookmarkMenu class, so that all the relevant code is in one place.

BUG: 419981
parent 7cfbb8bb
......@@ -21,24 +21,48 @@
// Own
#include "BookmarkMenu.h"
#include "Shortcut_p.h"
// KDE
#include <KActionCollection>
#include <kbookmarks_version.h>
#include <KBookmarkManager>
#include <KBookmark>
// Qt
#include <QAction>
#include <KBookmarkManager>
#include <KBookmark>
#include <QMenu>
#include <algorithm> // std::any_of
BookmarkMenu::BookmarkMenu (KBookmarkManager *mgr, KBookmarkOwner *owner, QMenu *parentMenu, KActionCollection *collec) :
KBookmarkMenu (mgr, owner, parentMenu, collec)
BookmarkMenu::BookmarkMenu (KBookmarkManager *mgr, KBookmarkOwner *owner, QMenu *parentMenu, KActionCollection *collection) :
#if KBOOKMARKS_VERSION < QT_VERSION_CHECK(5, 69, 0)
KBookmarkMenu (mgr, owner, parentMenu, collection)
#else
KBookmarkMenu (mgr, owner, parentMenu)
#endif
{
QAction *bookmarkAction;
#if KBOOKMARKS_VERSION < QT_VERSION_CHECK(5, 69, 0)
bookmarkAction = collection->action(QStringLiteral("add_bookmark"));
#else
collection->addActions(parentMenu->actions());
bookmarkAction = addBookmarkAction();
#endif
Q_ASSERT(bookmarkAction);
// We need to hijack the action - note this only hijacks top-level action
QAction *bookmarkAction = collec->action(QStringLiteral("add_bookmark"));
disconnect(bookmarkAction, nullptr, this, nullptr);
connect(bookmarkAction, &QAction::triggered, this, &BookmarkMenu::maybeAddBookmark);
// replace Ctrl+B shortcut for bookmarks only if user hasn't already
// changed the shortcut; however, if the user changed it to Ctrl+B
// this will still get changed to Ctrl+Shift+B
if (bookmarkAction->shortcut() == QKeySequence(Konsole::ACCEL + Qt::Key_B)) {
collection->setDefaultShortcut(bookmarkAction, Konsole::ACCEL + Qt::SHIFT + Qt::Key_B);
}
}
void BookmarkMenu::maybeAddBookmark()
......
......@@ -39,7 +39,7 @@ class KONSOLEPRIVATE_EXPORT BookmarkMenu : public KBookmarkMenu
Q_OBJECT
public:
BookmarkMenu (KBookmarkManager *mgr, KBookmarkOwner *owner, QMenu *parentMenu, KActionCollection *collec);
BookmarkMenu (KBookmarkManager *mgr, KBookmarkOwner *owner, QMenu *parentMenu, KActionCollection *collection);
private Q_SLOTS:
void maybeAddBookmark();
......
......@@ -193,16 +193,6 @@ void MainWindow::correctStandardShortcuts()
if (helpAction != nullptr) {
actionCollection()->setDefaultShortcut(helpAction, QKeySequence());
}
// replace Ctrl+B shortcut for bookmarks only if user hasn't already
// changed the shortcut; however, if the user changed it to Ctrl+B
// this will still get changed to Ctrl+Shift+B
QAction *bookmarkAction = actionCollection()->action(QStringLiteral("add_bookmark"));
if ((bookmarkAction != nullptr)
&& bookmarkAction->shortcut() == QKeySequence(Konsole::ACCEL + Qt::Key_B)) {
actionCollection()->setDefaultShortcut(bookmarkAction,
Konsole::ACCEL + Qt::SHIFT + Qt::Key_B);
}
}
ViewManager *MainWindow::viewManager() const
......
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