summaryrefslogtreecommitdiffstats
path: root/source/kde/kde/patch/plasma-desktop/b893a37fd9b3b5c28173c68ba963fb866a5ac0ed.patch
blob: c602e70461cd97f7f61607a4b6f3e91db9c6a209 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
From b893a37fd9b3b5c28173c68ba963fb866a5ac0ed Mon Sep 17 00:00:00 2001
From: Fabio Bas <fabio.bas@officineinformatiche.net>
Date: Mon, 18 Oct 2021 21:41:17 +0200
Subject: [PATCH] Desktop as folder: restore functionality of the "delete"
 action

MR552 introduced RemoveAction but broke functionality of the "delete" action
when both the "trash" and "delete" actions are shown in the menu by requiring
the "shift" key being pressed for the action to work.

BUG: 442765
---
 .../desktop/plugins/folder/foldermodel.cpp    | 52 ++++++++++++-------
 .../desktop/plugins/folder/foldermodel.h      |  1 +
 2 files changed, 34 insertions(+), 19 deletions(-)

diff --git a/containments/desktop/plugins/folder/foldermodel.cpp b/containments/desktop/plugins/folder/foldermodel.cpp
index ee03f6de9..68f404fad 100644
--- a/containments/desktop/plugins/folder/foldermodel.cpp
+++ b/containments/desktop/plugins/folder/foldermodel.cpp
@@ -1599,6 +1599,7 @@ void FolderModel::createActions()
 
     QAction *rename = KStandardAction::renameFile(this, &FolderModel::requestRename, this);
     QAction *trash = KStandardAction::moveToTrash(this, &FolderModel::moveSelectedToTrash, this);
+    QAction *del = KStandardAction::deleteFile(this, &FolderModel::deleteSelected, this);
     RemoveAction *remove = new RemoveAction(&m_actionCollection, this);
 
     QAction *emptyTrash = new QAction(QIcon::fromTheme(QStringLiteral("trash-empty")), i18n("&Empty Trash"), this);
@@ -1607,8 +1608,6 @@ void FolderModel::createActions()
     QAction *restoreFromTrash = new QAction(i18nc("Restore from trash", "Restore"), this);
     connect(restoreFromTrash, &QAction::triggered, this, &FolderModel::restoreSelectedFromTrash);
 
-    QAction *del = KStandardAction::deleteFile(this, &FolderModel::deleteSelected, this);
-
     QAction *actOpen = new QAction(QIcon::fromTheme(QStringLiteral("window-new")), i18n("&Open"), this);
     connect(actOpen, &QAction::triggered, this, &FolderModel::openSelected);
 
@@ -1803,20 +1802,20 @@ void FolderModel::openContextMenu(QQuickItem *visualParent, Qt::KeyboardModifier
         menu->addSeparator();
         menu->addAction(m_actionCollection.action(QStringLiteral("restoreFromTrash")));
 
-        KConfigGroup cg(KSharedConfig::openConfig(), "KDE");
-        bool showDeleteCommand = cg.readEntry("ShowDeleteCommand", false);
-
-        if (showDeleteCommand) {
+        if (isDeleteCommandShown()) {
             QAction *trashAction = m_actionCollection.action(QStringLiteral("trash"));
             QAction *deleteAction = m_actionCollection.action(QStringLiteral("del"));
-            deleteAction->setVisible(showDeleteCommand);
-            trashAction->setVisible(showDeleteCommand);
             menu->addAction(trashAction);
             menu->addAction(deleteAction);
         } else {
             if (RemoveAction *removeAction = qobject_cast<RemoveAction *>(m_actionCollection.action(QStringLiteral("remove")))) {
                 removeAction->update();
                 menu->addAction(removeAction);
+
+                // Used to monitor Shift modifier usage while the menu is open, to
+                // swap the Trash and Delete actions.
+                menu->installEventFilter(removeAction);
+                QCoreApplication::instance()->installEventFilter(removeAction);
             }
         }
 
@@ -1852,13 +1851,6 @@ void FolderModel::openContextMenu(QQuickItem *visualParent, Qt::KeyboardModifier
         menu->windowHandle()->setTransientParent(visualParent->window());
     }
 
-    // Used to monitor Shift modifier usage while the menu is open, to
-    // swap the Trash and Delete actions.
-    if (RemoveAction *removeAction = qobject_cast<RemoveAction *>(m_actionCollection.action(QStringLiteral("remove")))) {
-        menu->installEventFilter(removeAction);
-        QCoreApplication::instance()->installEventFilter(removeAction);
-    }
-
     menu->popup(m_menuPosition);
     connect(menu, &QMenu::aboutToHide, [menu]() {
         menu->deleteLater();
@@ -2007,8 +1999,16 @@ void FolderModel::moveSelectedToTrash()
         return;
     }
 
-    if (RemoveAction *action = qobject_cast<RemoveAction *>(m_actionCollection.action(QStringLiteral("remove")))) {
-        if (action->proxyAction() != m_actionCollection.action(QStringLiteral("trash"))) {
+    if (!isDeleteCommandShown()) {
+        if (RemoveAction *action = qobject_cast<RemoveAction *>(m_actionCollection.action(QStringLiteral("remove")))) {
+            if (action->proxyAction() != m_actionCollection.action(QStringLiteral("trash"))) {
+                return;
+            }
+        }
+    }
+
+    if (QAction *action = m_actionCollection.action(QStringLiteral("trash"))) {
+        if (!action->isEnabled()) {
             return;
         }
     }
@@ -2029,8 +2029,16 @@ void FolderModel::deleteSelected()
         return;
     }
 
-    if (RemoveAction *action = qobject_cast<RemoveAction *>(m_actionCollection.action(QStringLiteral("remove")))) {
-        if (action->proxyAction() != m_actionCollection.action(QStringLiteral("del"))) {
+    if (!isDeleteCommandShown()) {
+        if (RemoveAction *action = qobject_cast<RemoveAction *>(m_actionCollection.action(QStringLiteral("remove")))) {
+            if (action->proxyAction() != m_actionCollection.action(QStringLiteral("del"))) {
+                return;
+            }
+        }
+    }
+
+    if (QAction *action = m_actionCollection.action(QStringLiteral("del"))) {
+        if (!action->isEnabled()) {
             return;
         }
     }
@@ -2107,3 +2115,9 @@ void FolderModel::createFolder()
     m_newMenu->setPopupFiles(QList<QUrl>() << m_dirModel->dirLister()->url());
     m_newMenu->createDirectory();
 }
+
+bool FolderModel::isDeleteCommandShown()
+{
+    KConfigGroup cg(KSharedConfig::openConfig(), "KDE");
+    return cg.readEntry("ShowDeleteCommand", false);
+}
diff --git a/containments/desktop/plugins/folder/foldermodel.h b/containments/desktop/plugins/folder/foldermodel.h
index e6a908624..74fdaaec0 100644
--- a/containments/desktop/plugins/folder/foldermodel.h
+++ b/containments/desktop/plugins/folder/foldermodel.h
@@ -301,6 +301,7 @@ private:
     void addDragImage(QDrag *drag, int x, int y);
     void setStatus(Status status);
     static bool isTrashEmpty();
+    static bool isDeleteCommandShown();
     QList<QUrl> selectedUrls() const;
     KDirModel *m_dirModel;
     KDirWatch *m_dirWatch;
-- 
GitLab