]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/kitemviews/kitemlistcontroller.cpp
Adjust to changes in KToolBarPopupAction
[dolphin.git] / src / kitemviews / kitemlistcontroller.cpp
index 54a856fb8052d1ce2bc145c698494852e0d6a248..5598e77bd8f54458fea7ea35de874904a11c58dc 100644 (file)
@@ -228,25 +228,43 @@ bool KItemListController::selectionMode() const
     return m_selectionMode;
 }
 
+bool KItemListController::isSearchAsYouTypeActive() const
+{
+    return m_keyboardManager->isSearchAsYouTypeActive();
+}
+
 bool KItemListController::keyPressEvent(QKeyEvent *event)
 {
     int index = m_selectionManager->currentItem();
     int key = event->key();
+    const bool shiftPressed = event->modifiers() & Qt::ShiftModifier;
 
     // Handle the expanding/collapsing of items
-    if (m_view->supportsItemExpanding() && m_model->isExpandable(index)) {
-        if (key == Qt::Key_Right) {
-            if (m_model->setExpanded(index, true)) {
-                return true;
+    // expand / collapse all selected directories
+    if (m_view->supportsItemExpanding() && m_model->isExpandable(index) && (key == Qt::Key_Right || key == Qt::Key_Left)) {
+        const bool expandOrCollapse = key == Qt::Key_Right ? true : false;
+        bool shouldReturn = m_model->setExpanded(index, expandOrCollapse);
+
+        // edit in reverse to preserve index of the first handled items
+        const auto selectedItems = m_selectionManager->selectedItems();
+        for (auto it = selectedItems.rbegin(); it != selectedItems.rend(); ++it) {
+            shouldReturn |= m_model->setExpanded(*it, expandOrCollapse);
+            if (!shiftPressed) {
+                m_selectionManager->setSelected(*it);
             }
-        } else if (key == Qt::Key_Left) {
-            if (m_model->setExpanded(index, false)) {
-                return true;
+        }
+        if (shouldReturn) {
+            // update keyboard anchors
+            if (shiftPressed) {
+                m_keyboardAnchorIndex = selectedItems.count() > 0 ? qMin(index, selectedItems.last()) : index;
+                m_keyboardAnchorPos = keyboardAnchorPos(m_keyboardAnchorIndex);
             }
+
+            event->ignore();
+            return true;
         }
     }
 
-    const bool shiftPressed = event->modifiers() & Qt::ShiftModifier;
     const bool controlPressed = event->modifiers() & Qt::ControlModifier;
     const bool shiftOrControlPressed = shiftPressed || controlPressed;
     const bool navigationPressed = key == Qt::Key_Home || key == Qt::Key_End || key == Qt::Key_PageUp || key == Qt::Key_PageDown || key == Qt::Key_Up
@@ -322,11 +340,17 @@ bool KItemListController::keyPressEvent(QKeyEvent *event)
 
     case Qt::Key_Up:
         updateKeyboardAnchor();
+        if (shiftPressed && !m_selectionManager->isAnchoredSelectionActive() && m_selectionManager->isSelected(index)) {
+            m_selectionManager->beginAnchoredSelection(index);
+        }
         index = previousRowIndex(index);
         break;
 
     case Qt::Key_Down:
         updateKeyboardAnchor();
+        if (shiftPressed && !m_selectionManager->isAnchoredSelectionActive() && m_selectionManager->isSelected(index)) {
+            m_selectionManager->beginAnchoredSelection(index);
+        }
         index = nextRowIndex(index);
         break;
 
@@ -439,10 +463,13 @@ bool KItemListController::keyPressEvent(QKeyEvent *event)
                 m_selectionManager->setSelected(index, 1, KItemListSelectionManager::Toggle);
                 m_selectionManager->beginAnchoredSelection(index);
                 break;
-            } else if (m_keyboardManager->addKeyBeginsNewSearch()) { // File names shouldn't start with a space,
-                // so we can use this press as a keyboard shortcut instead.
-                Q_EMIT selectionModeChangeRequested(!m_selectionMode);
-                break;
+            } else {
+                // Select the current item if it is not selected yet.
+                const int current = m_selectionManager->currentItem();
+                if (!m_selectionManager->isSelected(current)) {
+                    m_selectionManager->setSelected(current);
+                    break;
+                }
             }
         }
         Q_FALLTHROUGH(); // fall through to the default case and add the Space to the current search string.
@@ -534,7 +561,7 @@ void KItemListController::slotAutoActivationTimeout()
      *
      * See Bug 293200 and 305783
      */
-    if (m_model->supportsDropping(index) && m_view->isUnderMouse()) {
+    if (m_view->isUnderMouse()) {
         if (m_view->supportsItemExpanding() && m_model->isExpandable(index)) {
             const bool expanded = m_model->isExpanded(index);
             m_model->setExpanded(index, !expanded);
@@ -738,6 +765,7 @@ bool KItemListController::dragMoveEvent(QGraphicsSceneDragDropEvent *event, cons
 
     const QPointF pos = transform.map(event->pos());
     KItemListWidget *newHoveredWidget = widgetForDropPos(pos);
+    int index = -1;
 
     if (oldHoveredWidget != newHoveredWidget) {
         m_autoActivationTimer->stop();
@@ -755,25 +783,23 @@ bool KItemListController::dragMoveEvent(QGraphicsSceneDragDropEvent *event, cons
             droppingBetweenItems = (m_view->showDropIndicator(pos) >= 0);
         }
 
-        const int index = newHoveredWidget->index();
+        index = newHoveredWidget->index();
 
         if (m_model->isDir(index)) {
             hoveredDir = m_model->url(index);
         }
 
         if (!droppingBetweenItems) {
-            if (m_model->supportsDropping(index)) {
-                // Something has been dragged on an item.
-                m_view->hideDropIndicator();
-                if (!newHoveredWidget->isHovered()) {
-                    newHoveredWidget->setHovered(true);
-                    Q_EMIT itemHovered(index);
-                }
+            // Something has been dragged on an item.
+            m_view->hideDropIndicator();
+            if (!newHoveredWidget->isHovered()) {
+                newHoveredWidget->setHovered(true);
+                Q_EMIT itemHovered(index);
+            }
 
-                if (!m_autoActivationTimer->isActive() && m_autoActivationTimer->interval() >= 0) {
-                    m_autoActivationTimer->setProperty("index", index);
-                    m_autoActivationTimer->start();
-                }
+            if (!m_autoActivationTimer->isActive() && m_autoActivationTimer->interval() >= 0) {
+                m_autoActivationTimer->setProperty("index", index);
+                m_autoActivationTimer->start();
             }
         } else {
             m_autoActivationTimer->stop();
@@ -790,8 +816,13 @@ bool KItemListController::dragMoveEvent(QGraphicsSceneDragDropEvent *event, cons
         event->setDropAction(Qt::IgnoreAction);
         event->ignore();
     } else {
-        event->setDropAction(event->proposedAction());
-        event->accept();
+        if (m_model->supportsDropping(index)) {
+            event->setDropAction(event->proposedAction());
+            event->accept();
+        } else {
+            event->setDropAction(Qt::IgnoreAction);
+            event->ignore();
+        }
     }
     return false;
 }
@@ -1800,3 +1831,5 @@ void KItemListController::slotStateChanged(QScroller::State newState)
         m_scrollerIsScrolling = false;
     }
 }
+
+#include "moc_kitemlistcontroller.cpp"