Skip to content

Commit

Permalink
Added Context Menu to Docsets
Browse files Browse the repository at this point in the history
  • Loading branch information
Roshni committed Dec 5, 2024
1 parent 48289b9 commit e8cbe75
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/libs/ui/searchsidebar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <registry/listmodel.h>
#include <registry/searchmodel.h>
#include <registry/searchquery.h>
#include <ui/mainwindow.h>

#include <QCoreApplication>
#include <QEvent>
Expand All @@ -27,6 +28,7 @@
#include <QTimer>
#include <QTreeView>
#include <QVBoxLayout>
#include <QMenu>

using namespace Zeal;
using namespace Zeal::WidgetUi;
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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));
}
2 changes: 2 additions & 0 deletions src/libs/ui/searchsidebar.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -73,6 +74,7 @@ private slots:

QSplitter *m_splitter = nullptr;
QTimer *m_delayedNavigationTimer = nullptr;
QMenu *m_contextMenu = nullptr;

Check failure on line 77 in src/libs/ui/searchsidebar.h

View workflow job for this annotation

GitHub Actions / Analyze

‘QMenu’ does not name a type

Check failure on line 77 in src/libs/ui/searchsidebar.h

View workflow job for this annotation

GitHub Actions / Ubuntu 20.04 / Qt 5

‘QMenu’ does not name a type

Check failure on line 77 in src/libs/ui/searchsidebar.h

View workflow job for this annotation

GitHub Actions / Windows Server 2019 / Qt 5

syntax error: missing ';' before '*'

Check failure on line 77 in src/libs/ui/searchsidebar.h

View workflow job for this annotation

GitHub Actions / Windows Server 2019 / Qt 5

missing type specifier - int assumed. Note: C++ does not support default-int

Check failure on line 77 in src/libs/ui/searchsidebar.h

View workflow job for this annotation

GitHub Actions / Windows Server 2019 / Qt 5

unexpected token(s) preceding ';'

Check failure on line 77 in src/libs/ui/searchsidebar.h

View workflow job for this annotation

GitHub Actions / Ubuntu 20.04 / Qt 5 / Portable

‘QMenu’ does not name a type

Check failure on line 77 in src/libs/ui/searchsidebar.h

View workflow job for this annotation

GitHub Actions / Windows Server 2019 / Qt 5 / Portable

syntax error: missing ';' before '*'

Check failure on line 77 in src/libs/ui/searchsidebar.h

View workflow job for this annotation

GitHub Actions / Windows Server 2019 / Qt 5 / Portable

missing type specifier - int assumed. Note: C++ does not support default-int

Check failure on line 77 in src/libs/ui/searchsidebar.h

View workflow job for this annotation

GitHub Actions / Windows Server 2019 / Qt 5 / Portable

unexpected token(s) preceding ';'

Check failure on line 77 in src/libs/ui/searchsidebar.h

View workflow job for this annotation

GitHub Actions / Ubuntu 22.04 / Qt 6

‘QMenu’ does not name a type

Check failure on line 77 in src/libs/ui/searchsidebar.h

View workflow job for this annotation

GitHub Actions / Ubuntu 22.04 / Qt 6 / Portable

‘QMenu’ does not name a type
};

} // namespace WidgetUi
Expand Down

0 comments on commit e8cbe75

Please sign in to comment.