Files
konsole/src/BookmarkMenu.cpp
Georg Gadinger 7f41a38371 Improve usability on macOS including altering shortcuts
This change removes some application attributes that are not necessary anymore (like disabling the global menu bar) or make Konsole behave slightly different when used from a KPart (e.g. inside Kate), and changes some keyboard shortcuts around (mainly using Command instead of Ctrl+Shift now.)

Unfortunately this does not resolve the requirement for the special keytab file for macOS; it looks like Qt does something funny with the QKeyEvents here: on Linux these have a `text` attribute set to e.g. `\u0003` for `^C`, that attribute is empty on macOS.

Note this could impact shortcut changes on non-macOS systems.
2022-06-21 00:10:44 +00:00

65 lines
2.0 KiB
C++

/* This file was part of the KDE libraries
SPDX-FileCopyrightText: 2019 Tomaz Canabrava <tcanabrava@kde.org>
SPDX-FileCopyrightText: 2019 Martin Sandsmark <martin.sandsmark@kde.org>
SPDX-License-Identifier: GPL-2.0-or-later
*/
// Own
#include "BookmarkMenu.h"
#include "Shortcut_p.h"
// KDE
#include <KActionCollection>
#include <KBookmark>
#include <KBookmarkManager>
#include <KBookmarkOwner>
// Qt
#include <QAction>
#include <QMenu>
#include <algorithm> // std::any_of
BookmarkMenu::BookmarkMenu(KBookmarkManager *mgr, KBookmarkOwner *owner, QMenu *parentMenu, KActionCollection *collection)
: KBookmarkMenu(mgr, owner, parentMenu)
{
QAction *bookmarkAction;
collection->addActions(parentMenu->actions());
bookmarkAction = addBookmarkAction();
Q_ASSERT(bookmarkAction);
// We need to hijack the action - note this only hijacks top-level action
disconnect(bookmarkAction, nullptr, this, nullptr);
connect(bookmarkAction, &QAction::triggered, this, &BookmarkMenu::maybeAddBookmark);
#ifndef Q_OS_MACOS // not needed on this platform, Cmd+B (shortcut) is different to Ctrl+B (^B in terminal)
// 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(Qt::CTRL | Qt::Key_B)) {
collection->setDefaultShortcut(bookmarkAction, Qt::CTRL | Qt::SHIFT | Qt::Key_B);
}
#endif
}
void BookmarkMenu::maybeAddBookmark()
{
// Check for duplicates first
// 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 QUrl currUrl = owner()->currentUrl();
const auto urlList = rootGroup.groupUrlList();
if (std::any_of(urlList.constBegin(), urlList.constEnd(), [currUrl](const QUrl &url) {
return url == currUrl;
})) {
return;
}
slotAddBookmark();
}