diff --git a/src/libs/ui/searchsidebar.cpp b/src/libs/ui/searchsidebar.cpp index ab4355bd..cba2e18c 100644 --- a/src/libs/ui/searchsidebar.cpp +++ b/src/libs/ui/searchsidebar.cpp @@ -16,6 +16,7 @@ #include #include #include +#include #include #include @@ -27,6 +28,7 @@ #include #include #include +#include using namespace Zeal; using namespace Zeal::WidgetUi; @@ -245,6 +247,13 @@ SearchSidebar::SearchSidebar(const SearchSidebar *other, QWidget *parent) connect(registry, &DocsetRegistry::docsetLoaded, this, [this](const QString &) { setupSearchBoxCompletions(); }); + + // Set Context Menu on Docset + m_treeView->setContextMenuPolicy(Qt::CustomContextMenu); + + connect(m_treeView, SIGNAL(customContextMenuRequested(QPoint)), + this, SLOT(setContextMenu(const QPoint&))); + } void SearchSidebar::setTreeViewModel(QAbstractItemModel *model, bool isRootDecorated) @@ -400,3 +409,26 @@ void SearchSidebar::showEvent(QShowEvent *event) m_pendingSearchEditFocus = false; } } + +void SearchSidebar::setContextMenu(const QPoint &pos) +{ + if (m_contextMenu) { + m_contextMenu->deleteLater(); + } + + m_contextMenu = new QMenu(this); + + QModelIndex index = m_treeView->indexAt(pos); + if (index.isValid()) + { + m_contextMenu->addAction("Open in New Tab", this, [this](){ + Core::Application::instance()->mainWindow()->createTab(); + }); + } + + if (m_contextMenu->isEmpty()) { + return; + } + + m_contextMenu->exec(mapToGlobal(pos)); +} diff --git a/src/libs/ui/searchsidebar.h b/src/libs/ui/searchsidebar.h index e462b4ea..4a7ae2c5 100644 --- a/src/libs/ui/searchsidebar.h +++ b/src/libs/ui/searchsidebar.h @@ -49,6 +49,7 @@ private slots: void navigateToIndexAndActivate(const QModelIndex &index); void navigateToSelectionWithDelay(const QItemSelection &selection); void setupSearchBoxCompletions(); + void setContextMenu(const QPoint &pos); protected: bool eventFilter(QObject *object, QEvent *event) override; @@ -73,6 +74,7 @@ private slots: QSplitter *m_splitter = nullptr; QTimer *m_delayedNavigationTimer = nullptr; + QMenu *m_contextMenu = nullptr; }; } // namespace WidgetUi