summaryrefslogtreecommitdiff
path: root/src/panels
diff options
context:
space:
mode:
authoraqua <aqua@iserlohn-fortress.net>2022-09-24 21:48:39 +0300
committeraqua <aqua@iserlohn-fortress.net>2022-09-24 21:48:39 +0300
commitfee55330b612721e0098b93445a533e95865a779 (patch)
tree88616e3c5b8e2e29700a3345a59e70b63767ac8d /src/panels
parentAdd validate_xml script (diff)
downloadrekonq-fee55330b612721e0098b93445a533e95865a779.tar.xz
Add BookmarksContextMenustagingRKNQ-2-bookmarks
Diffstat (limited to 'src/panels')
-rw-r--r--src/panels/bookmarkscontextmenu.cpp39
-rw-r--r--src/panels/bookmarkscontextmenu.hpp21
-rw-r--r--src/panels/bookmarkspanel.cpp15
-rw-r--r--src/panels/bookmarkspanel.hpp1
4 files changed, 62 insertions, 14 deletions
diff --git a/src/panels/bookmarkscontextmenu.cpp b/src/panels/bookmarkscontextmenu.cpp
new file mode 100644
index 00000000..cfd0c41b
--- /dev/null
+++ b/src/panels/bookmarkscontextmenu.cpp
@@ -0,0 +1,39 @@
+/* ============================================================
+ * The rekonq project
+ * ============================================================
+ * SPDX-License-Identifier: GPL-3.0-only
+ * Copyright (C) 2022 aqua <aqua@iserlohn-fortress.net>
+ * ============================================================ */
+
+#include "bookmarkscontextmenu.hpp"
+#include "bookmarks/bookmarkstreemodel.hpp"
+#include "rekonqwindow.hpp"
+
+BookmarksContextMenu::BookmarksContextMenu(const QModelIndex &index, BookmarksTreeModel *model, QWidget *parent)
+ : QMenu(parent)
+{
+ auto *w = qobject_cast<RekonqWindow *>(parent->window());
+ Q_CHECK_PTR(w);
+
+ auto *item = model->item(index);
+ Q_CHECK_PTR(item);
+
+ addAction(tr("Open in current tab"), this,
+ [item, w]() { w->loadRequestedUrl(item->data(BookmarksTreeItem::Href).toUrl()); });
+ addAction(tr("Open in new tab"), this,
+ [item, w]() { w->loadRequestedUrl(item->data(BookmarksTreeItem::Href).toUrl(), rekonq::NewTab); });
+ // TODO Open in new window
+
+ addSeparator();
+
+ addAction(tr("Edit"));
+ addAction(tr("Remove"), this, [index, model]() { model->removeRow(index.row(), index.parent()); });
+
+ addSeparator();
+
+ addAction(tr("New Bookmark"), this,
+ [index, model]() { model->appendItem(BookmarksTreeItem::Bookmark, {}, model->parentFolder(index)); });
+ addAction(tr("New Folder"), this, [index, model]() { model->appendItem(BookmarksTreeItem::Folder, {}, index); });
+ addAction(tr("New Separator"), this,
+ [index, model]() { model->appendItem(BookmarksTreeItem::Separator, {}, index); });
+}
diff --git a/src/panels/bookmarkscontextmenu.hpp b/src/panels/bookmarkscontextmenu.hpp
new file mode 100644
index 00000000..b2ea1ffa
--- /dev/null
+++ b/src/panels/bookmarkscontextmenu.hpp
@@ -0,0 +1,21 @@
+/* ============================================================
+ * The rekonq project
+ * ============================================================
+ * SPDX-License-Identifier: GPL-3.0-only
+ * Copyright (C) 2022 aqua <aqua@iserlohn-fortress.net>
+ * ============================================================ */
+
+#pragma once
+
+#include <QMenu>
+
+class BookmarksTreeModel;
+class RekonqWindow;
+
+class BookmarksContextMenu : public QMenu {
+ Q_OBJECT
+
+public:
+ explicit BookmarksContextMenu(const QModelIndex &index, BookmarksTreeModel *model, QWidget *parent = nullptr);
+ ~BookmarksContextMenu() override = default;
+};
diff --git a/src/panels/bookmarkspanel.cpp b/src/panels/bookmarkspanel.cpp
index dab99203..dc55954a 100644
--- a/src/panels/bookmarkspanel.cpp
+++ b/src/panels/bookmarkspanel.cpp
@@ -7,6 +7,7 @@
#include "bookmarkspanel.hpp"
#include "bookmarks/bookmarkstreemodel.hpp"
+#include "bookmarkscontextmenu.hpp"
#include <QMenu>
BookmarksPanel::BookmarksPanel(QWidget *parent) : QTreeView(parent)
@@ -27,17 +28,7 @@ BookmarksTreeModel *BookmarksPanel::model() const
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));
+ (new BookmarksContextMenu(indexAt(pos), model(), this))->popup(mapToGlobal(pos));
}
void BookmarksPanel::open(const QModelIndex &index, rekonq::OpenType type)
@@ -46,5 +37,3 @@ void BookmarksPanel::open(const QModelIndex &index, rekonq::OpenType type)
const auto url = item->data(BookmarksTreeItem::Href).toUrl();
emit loadUrl(url, type);
}
-
-void BookmarksPanel::remove(const QModelIndex &index) { model()->removeRow(index.row(), index.parent()); }
diff --git a/src/panels/bookmarkspanel.hpp b/src/panels/bookmarkspanel.hpp
index 9dc969a7..ab2a2a7d 100644
--- a/src/panels/bookmarkspanel.hpp
+++ b/src/panels/bookmarkspanel.hpp
@@ -29,7 +29,6 @@ private slots:
void customContextMenu(const QPoint &pos);
void open(const QModelIndex &index, rekonq::OpenType type = rekonq::CurrentTab);
- void remove(const QModelIndex &index);
private:
[[nodiscard]] BookmarksTreeModel *model() const;