]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Fix paste on row while in details view mode
authorFelix Ernst <fe.a.ernst@gmail.com>
Tue, 24 May 2022 12:46:45 +0000 (14:46 +0200)
committerFelix Ernst <fe.a.ernst@gmail.com>
Fri, 27 May 2022 10:00:05 +0000 (10:00 +0000)
Before this change, right-clicking the row of an unselected item
in details view mode would be in a weird state:
- It didn't really count as a click on the item because the item
    didn't get selected by this click before opening the context
    menu.
- It didn't really count as a click on the view background either
    because the actions that showed up depended on the item in
    that row.

This commit fixes this by considering a right-click in the same row
as an unselected item as a click on the view background.
The behaviour of right-clicking the icon or name of a file directly
is unchanged.

This fixes the following bugs:
- The Paste action that shows up when right-clicking in the
    unselected row of a folder now works (instead of doing
    nothing). It now pastes the clipboard contents onto the view
    background.
- When right-clicking the unselected row of a file (not a folder)
    a Paste action once again shows up.

src/kitemviews/kitemlistcontroller.cpp

index 994812b1fc575424dba7a7f0c953c3f85f06adb1..4d926474be451ab93e0e34b0888e6d5f1128f336 100644 (file)
@@ -1579,6 +1579,7 @@ bool KItemListController::onPress(const QPoint& screenPos, const QPointF& pos, c
     }
 
     if (m_pressedIndex.has_value()) {
+        // The hover highlight area of an item is being pressed.
         m_selectionManager->setCurrentItem(m_pressedIndex.value());
         const auto row = m_view->m_visibleItems.value(m_pressedIndex.value()); // anything outside of row.contains() will be the empty region of the row rect
         const bool hitTargetIsRowEmptyRegion = !row->contains(row->mapFromItem(m_view, pos));
@@ -1587,8 +1588,14 @@ bool KItemListController::onPress(const QPoint& screenPos, const QPointF& pos, c
         bool createRubberBand = (hitTargetIsRowEmptyRegion && m_selectionManager->selectedItems().isEmpty());
 
         if (rightClick && hitTargetIsRowEmptyRegion) {
-            // we got a right click outside the text rect, default to action on the current url and not the pressed item
-            Q_EMIT itemContextMenuRequested(m_pressedIndex.value(), screenPos);
+            // We have a right click outside the icon and text rect but within the hover highlight area
+            // but it is unclear if this means that a selection rectangle for an item was clicked or the background of the view.
+            if (m_selectionManager->selectedItems().contains(m_pressedIndex.value())) {
+                // The selection rectangle for an item was clicked
+                Q_EMIT itemContextMenuRequested(m_pressedIndex.value(), screenPos);
+            } else {
+                Q_EMIT viewContextMenuRequested(screenPos);
+            }
             return true;
         }