fix(model): keep the selection while the context menu is open

main
reionwong 3 weeks ago
parent 36686ab228
commit 16bf341407

@ -858,6 +858,13 @@ void FolderModel::updateSelection(const QVariantList &rows, bool toggle)
void FolderModel::clearSelection()
{
// Keep the selection while our own context menu is open: the menu is a
// separate window, so showing it makes the view lose focus, and the desktop
// clears the selection on focus loss. Without this the menu would be built
// from the selection and then act on an empty one.
if (m_contextMenu)
return;
if (m_selectionModel->hasSelection())
m_selectionModel->clear();
}
@ -1335,7 +1342,10 @@ void FolderModel::openContextMenu(QQuickItem *visualParent, Qt::KeyboardModifier
menu->installEventFilter(this);
menu->setAttribute(Qt::WA_TranslucentBackground);
menu->winId();
m_contextMenu = menu;
menu->popup(position);
connect(menu, &QMenu::aboutToHide, [menu]() {
menu->deleteLater();
});

@ -41,6 +41,8 @@
#include <KDirWatch>
#include <KActionCollection>
class QMenu;
class QDrag;
class CFileSizeJob;
class FolderModel : public QSortFilterProxyModel, public QQmlParserStatus
@ -309,6 +311,12 @@ private:
QString m_selectedItemSize;
// The context menu is a window of its own, so opening it takes the focus
// away from the view. The desktop reacts to losing focus by clearing the
// selection, which would leave every menu entry acting on nothing, so the
// selection is held for as long as this menu is up.
QPointer<QMenu> m_contextMenu;
KActionCollection m_actionCollection;
QHash<int, DragImage *> m_dragImages;
QModelIndexList m_dragIndexes;

Loading…
Cancel
Save