summaryrefslogtreecommitdiff
path: root/src/panels/bookmarkspanel.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/panels/bookmarkspanel.cpp')
-rw-r--r--src/panels/bookmarkspanel.cpp35
1 files changed, 30 insertions, 5 deletions
diff --git a/src/panels/bookmarkspanel.cpp b/src/panels/bookmarkspanel.cpp
index ee7ae717..5eda1c67 100644
--- a/src/panels/bookmarkspanel.cpp
+++ b/src/panels/bookmarkspanel.cpp
@@ -7,14 +7,15 @@
#include "bookmarkspanel.hpp"
#include "bookmarks/bookmarkstreemodel.hpp"
+#include <QMenu>
BookmarksPanel::BookmarksPanel(QWidget *parent) : QTreeView(parent)
{
- connect(this, &QTreeView::activated, this, [this](const QModelIndex &index) {
- auto *item = model()->item(index);
- const auto url = item->data(BookmarksTreeItem::Href).toUrl();
- emit loadUrl(url, rekonq::CurrentTab);
- });
+ setEditTriggers(QAbstractItemView::NoEditTriggers);
+ setContextMenuPolicy(Qt::CustomContextMenu);
+
+ connect(this, &QTreeView::activated, this, [this](const QModelIndex &index) { open(index); });
+ connect(this, &QTreeView::customContextMenuRequested, this, &BookmarksPanel::customContextMenu);
}
BookmarkModel *BookmarksPanel::model() const
@@ -23,3 +24,27 @@ BookmarkModel *BookmarksPanel::model() const
Q_CHECK_PTR(m);
return m;
}
+
+void BookmarksPanel::customContextMenu(const QPoint &pos)
+{
+ const auto index = indexAt(pos);
+ auto *item = model()->item(indexAt(pos));
+ Q_CHECK_PTR(item);
+
+ auto *menu = new QMenu(this);
+ menu->addAction(tr("Open in current tab"), this, [this, index]() { open(index); });
+ menu->addAction(tr("Open in new tab"), this, [this, index]() { open(index, rekonq::NewTab); });
+ menu->addAction(tr("Edit"));
+ menu->addAction(tr("Remove"), this, [this, index]() { remove(index); });
+
+ menu->popup(mapToGlobal(pos));
+}
+
+void BookmarksPanel::open(const QModelIndex &index, rekonq::OpenType type)
+{
+ auto *item = model()->item(index);
+ const auto url = item->data(BookmarksTreeItem::Href).toUrl();
+ emit loadUrl(url, type);
+}
+
+void BookmarksPanel::remove(const QModelIndex &index) { model()->removeRow(index.row(), index.parent()); }