Members of the KDE Community are recommended to subscribe to the kde-community mailing list at to allow them to participate in important discussions and receive other important announcements

Commit 3a02df6e authored by Peter Mühlenpfordt's avatar Peter Mühlenpfordt

Fix context menus for Recent Files / Folders on Start Page

On {nav Start Page > Recent Files} the context menu is missing and
right clicking on an item switches to View Mode.
This patch adds the context menu to {nav Recent Files} tab items
with the entries {nav Add Containing Folder to Places},
{nav Forget This File} and {nav Forget All Files}. The entries on
the {nav Recent Folders} tab are renamed accordingly.

Ref T8194
FIXED-IN: 18.04.0

Test Plan:
* Open some images to populate the recent files/folders lists
* Go to {nav Start Page}
* Right click on file / folder items to show context menu
* Check actions to execute correctly
* Check if clear actions for recent files sync with {nav File > Open Recent}

Reviewers: #gwenview, rkflx

Reviewed By: #gwenview, rkflx

Subscribers: rkflx

Maniphest Tasks: T8194

Differential Revision:
parent 312ab20c
......@@ -342,6 +342,12 @@ struct MainWindow::Private
mStartMainPage = new StartMainPage(parent, mGvCore);
connect(mStartMainPage, SIGNAL(urlSelected(QUrl)),
q, SLOT(slotStartMainPageUrlSelected(QUrl)));
connect(mStartMainPage, &StartMainPage::recentFileRemoved, [this](const QUrl& url) {
connect(mStartMainPage, &StartMainPage::recentFilesCleared, [this]() {
void installDisabledActionShortcutMonitor(QAction* action, const char* slot)
......@@ -41,7 +41,9 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Cambridge, MA 02110-1301, USA
// Local
#include <gvcore.h>
#include <ui_startmainpage.h>
#include <lib/dialogguard.h>
#include <lib/flowlayout.h>
#include <lib/gvdebug.h>
#include <lib/gwenviewconfig.h>
#include <lib/thumbnailview/abstractthumbnailviewhelper.h>
#include <lib/thumbnailview/previewitemdelegate.h>
......@@ -171,12 +173,17 @@ StartMainPage::StartMainPage(QWidget* parent, GvCore* gvCore)
// Tag view
connect(d->mTagView, &QListView::clicked, this, &StartMainPage::slotTagViewClicked);
// Recent folder view
connect(d->mRecentFoldersView, &Gwenview::ThumbnailView::indexActivated, this, &StartMainPage::slotListViewActivated);
// Recent folders view
connect(d->mRecentFoldersView, &Gwenview::ThumbnailView::indexActivated,
this, &StartMainPage::slotListViewActivated);
connect(d->mRecentFoldersView, &Gwenview::ThumbnailView::customContextMenuRequested,
this, &StartMainPage::showContextMenu);
connect(d->mRecentFoldersView, &Gwenview::ThumbnailView::customContextMenuRequested, this, &StartMainPage::showRecentFoldersViewContextMenu);
connect(d->mRecentFilesView, &Gwenview::ThumbnailView::indexActivated, this, &StartMainPage::slotListViewActivated);
// Recent files view
connect(d->mRecentFilesView, &Gwenview::ThumbnailView::indexActivated,
this, &StartMainPage::slotListViewActivated);
connect(d->mRecentFilesView, &Gwenview::ThumbnailView::customContextMenuRequested,
this, &StartMainPage::showContextMenu);
connect(GwenviewConfig::self(), &GwenviewConfig::configChanged, this, &StartMainPage::loadConfig);
......@@ -257,45 +264,60 @@ void StartMainPage::showEvent(QShowEvent* event)
void StartMainPage::showRecentFoldersViewContextMenu(const QPoint& pos)
void StartMainPage::showContextMenu(const QPoint& pos)
QAbstractItemView* view = qobject_cast<QAbstractItemView*>(sender());
QUrl url;
QModelIndex index = view->indexAt(pos);
if (index.isValid()) {
QVariant data =;
url = data.toUrl();
// Create menu
QMenu menu(this);
QAction* addToPlacesAction = menu.addAction(QIcon::fromTheme("bookmark-new"), i18n("Add to Places"));
QAction* removeAction = menu.addAction(QIcon::fromTheme("edit-delete"), i18n("Forget this Folder"));
QAction* clearAction = menu.addAction(QIcon::fromTheme("edit-delete-all"), i18n("Forget All"));
if (!index.isValid()) {
if (addToPlacesAction) {
DialogGuard<QMenu> menu(this);
QAction* addAction = menu->addAction(QIcon::fromTheme("bookmark-new"), QString());
QAction* forgetAction = menu->addAction(QIcon::fromTheme("edit-delete"), QString());
QAction* forgetAllAction = menu->addAction(QIcon::fromTheme("edit-delete-all"), QString());
if (d->mHistoryWidget->currentWidget() == d->mRecentFoldersTab) {
addAction->setText(i18nc("@action Recent Folders view", "Add Folder to Places"));
forgetAction->setText(i18nc("@action Recent Folders view", "Forget This Folder"));
forgetAllAction->setText(i18nc("@action Recent Folders view", "Forget All Folders"));
} else if (d->mHistoryWidget->currentWidget() == d->mRecentFilesTab) {
addAction->setText(i18nc("@action Recent Files view", "Add Containing Folder to Places"));
forgetAction->setText(i18nc("@action Recent Files view", "Forget This File"));
forgetAllAction->setText(i18nc("@action Recent Files view", "Forget All Files"));
} else {
GV_WARN_AND_RETURN("Context menu not implemented on this tab page");
const QAbstractItemView* view = qobject_cast<QAbstractItemView*>(sender());
const QModelIndex index = view->indexAt(pos);
// Handle menu
QAction* action = menu.exec(view->mapToGlobal(pos));
const QAction* action = menu->exec(view->mapToGlobal(pos));
if (!action) {
if (action == addToPlacesAction) {
const QVariant data =;
QUrl url = data.toUrl();
if (action == addAction) {
if (d->mHistoryWidget->currentWidget() == d->mRecentFilesTab) {
url = url.adjusted(QUrl::RemoveFilename);
QString text = url.adjusted(QUrl::StripTrailingSlash).fileName();
if (text.isEmpty()) {
text = url.toDisplayString();
d->mBookmarksModel->addPlace(text, url);
} else if (action == removeAction) {
} else if (action == forgetAction) {
} else if (action == clearAction) {
if (d->mHistoryWidget->currentWidget() == d->mRecentFilesTab) {
emit recentFileRemoved(url);
} else if (action == forgetAllAction) {
view->model()->removeRows(0, view->model()->rowCount());
if (d->mHistoryWidget->currentWidget() == d->mRecentFilesTab) {
emit recentFilesCleared();
......@@ -53,6 +53,8 @@ public:
void urlSelected(const QUrl &url);
void recentFileRemoved(const QUrl& url);
void recentFilesCleared();
public Q_SLOTS:
void loadConfig();
......@@ -62,11 +64,12 @@ protected:
private Q_SLOTS:
void slotListViewActivated(const QModelIndex& index);
void showRecentFoldersViewContextMenu(const QPoint& pos);
void slotTagViewClicked(const QModelIndex& index);
StartMainPagePrivate* const d;
void showContextMenu(const QPoint& pos);
} // namespace
......@@ -46,7 +46,7 @@
<property name="documentMode">
<widget class="QWidget" name="tab">
<widget class="QWidget" name="mRecentFoldersTab">
<attribute name="title">
<string>Recent Folders</string>
......@@ -60,7 +60,7 @@
<widget class="QWidget" name="tab_2">
<widget class="QWidget" name="mRecentFilesTab">
<attribute name="title">
<string>Recent Files</string>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment