diff options
-rw-r--r-- | lib/bookmarks/bookmarkswidget.cpp | 11 | ||||
-rw-r--r-- | lib/bookmarks/bookmarkswidget.h | 1 | ||||
-rw-r--r-- | src/browser.cpp | 31 |
3 files changed, 43 insertions, 0 deletions
diff --git a/lib/bookmarks/bookmarkswidget.cpp b/lib/bookmarks/bookmarkswidget.cpp index 2949b44..c57af57 100644 --- a/lib/bookmarks/bookmarkswidget.cpp +++ b/lib/bookmarks/bookmarkswidget.cpp @@ -73,6 +73,17 @@ BookmarksWidget::BookmarksWidget(const QString &path, QWidget *parent) m_isChanged = true; }); + ui->treeView->setContextMenuPolicy(Qt::CustomContextMenu); + connect(ui->treeView, &QTreeView::customContextMenuRequested, this, [this](const QPoint &pos) { + const QModelIndex idx = ui->treeView->indexAt(pos); + if(idx.isValid()) { + const QUrl url = model->data(idx, 1, Qt::DisplayRole).toUrl(); + const QPoint pos = ui->treeView->viewport()->mapToGlobal(pos); + + emit showContextMenu(url, pos); + } + }); + // addBookmark connect(ui->addBookmark_toolButton, &QToolButton::clicked, this, [this]() { const QModelIndex idx = model->parentFolder(ui->treeView->currentIndex()); diff --git a/lib/bookmarks/bookmarkswidget.h b/lib/bookmarks/bookmarkswidget.h index 73628df..e293f65 100644 --- a/lib/bookmarks/bookmarkswidget.h +++ b/lib/bookmarks/bookmarkswidget.h @@ -33,6 +33,7 @@ protected: void editBookmark(const QModelIndex &index); signals: + void showContextMenu(const QUrl &url, const QPoint &pos); void openUrl(const QUrl &url); public slots: diff --git a/src/browser.cpp b/src/browser.cpp index 0422a4e..8c1dcf1 100644 --- a/src/browser.cpp +++ b/src/browser.cpp @@ -34,6 +34,7 @@ #include <plugininterface.h> #include <version.h> #include "mainwindow/menubar.h" +#include "webengine/webview.h" Browser::Browser(int &argc, char *argv[], bool allowSecondary) : SingleApplication(argc, argv, allowSecondary, SingleApplication::User | SingleApplication::SecondaryNotification | SingleApplication::ExcludeAppVersion) @@ -185,6 +186,36 @@ void Browser::setup(QVector<QPluginLoader *> plugins) // bookmarks m_bookmarks = std::make_shared<BookmarksWidget>(QString::fromStdString(m_config->value<std::string>("bookmarks.path").value())); + connect(m_bookmarks.get(), &BookmarksWidget::showContextMenu, this, [this](const QUrl &url, const QPoint &pos) { + auto *menu = new QMenu(m_windows.last()); + auto *subwindow = m_windows.last()->currentSubWindow(); + if(subwindow == nullptr) + return; + + menu->addAction(tr("Open link in current tab"), subwindow, [url, subwindow]() { + subwindow->currentView()->load(url); + }); + + auto *openInCurrentTabWithProfile = m_profileManager->createProfileMenu([url, subwindow](WebProfile *profile) { + subwindow->currentView()->setProfile(profile); + subwindow->currentView()->load(url); + }, nullptr); + openInCurrentTabWithProfile->setTitle(tr("Open link in current tab with profile")); + menu->addMenu(openInCurrentTabWithProfile); + + menu->addAction(tr("Open link in new tab"), subwindow, [url, subwindow]() { + subwindow->addTab(url); + }); + + auto *openInNewTabWithProfile = m_profileManager->createProfileMenu([url, subwindow](WebProfile *profile) { + subwindow->addTab(url, profile); + }, nullptr); + openInNewTabWithProfile->setTitle(tr("Open link in new tab with profile")); + menu->addMenu(openInNewTabWithProfile); + + menu->exec(pos); + }); + connect(m_bookmarks.get(), &BookmarksWidget::openUrl, this, [this](const QUrl &url) { m_windows.last()->createTab(url); }); |