Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Context Menu to Docsets #1673

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
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 @@

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
Loading