]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Start autoActivationTimer only if hovering over a directory
authorAkseli Lahtinen <akselmo@akselmo.dev>
Fri, 8 Mar 2024 11:37:20 +0000 (11:37 +0000)
committerAkseli Lahtinen <akselmo@akselmo.dev>
Fri, 8 Mar 2024 11:37:20 +0000 (11:37 +0000)
Before starting autoActivationTimer, check that we're hovering the item on top of a directory.
If we don't check for it, the the autoActivationTimer will try to open the hovered item
in it's default application, which can be distracting and break the actual action
the user was trying to do, like moving the file to a directory.

BUG:479960

src/kitemviews/kfileitemmodel.cpp
src/kitemviews/kfileitemmodel.h
src/kitemviews/kitemlistcontroller.cpp
src/kitemviews/kitemmodelbase.cpp
src/kitemviews/kitemmodelbase.h

index 9ef66d6b8269cd4dd62b92eed32b790e634be41d..c694da9f256f041f91d1ed0712032474db7266c8 100644 (file)
@@ -352,6 +352,17 @@ bool KFileItemModel::supportsDropping(int index) const
     return !item.isNull() && DragAndDropHelper::supportsDropping(item);
 }
 
+bool KFileItemModel::canEnterOnHover(int index) const
+{
+    KFileItem item;
+    if (index == -1) {
+        item = rootItem();
+    } else {
+        item = fileItem(index);
+    }
+    return !item.isNull() && (item.isDir() || item.isDesktopFile());
+}
+
 QString KFileItemModel::roleDescription(const QByteArray &role) const
 {
     static QHash<QByteArray, QString> description;
index ad1b0a1384481029423d638fffcb30067763fba1..ce58f89acc96ff2334dd0cb7f6c99f9601cb3571 100644 (file)
@@ -109,6 +109,8 @@ public:
 
     bool supportsDropping(int index) const override;
 
+    bool canEnterOnHover(int index) const override;
+
     QString roleDescription(const QByteArray &role) const override;
 
     QList<QPair<int, QVariant>> groups() const override;
index aea59c7110b34091d5e5736d81ec7a128a71014e..2a0641aa16d1f8f2c27b8d0f408279b5ca88c818 100644 (file)
@@ -827,11 +827,12 @@ bool KItemListController::dragMoveEvent(QGraphicsSceneDragDropEvent *event, cons
                 Q_EMIT itemHovered(index);
             }
 
-            if (!m_autoActivationTimer->isActive() && m_autoActivationTimer->interval() >= 0) {
+            if (!m_autoActivationTimer->isActive() && m_autoActivationTimer->interval() >= 0 && m_model->canEnterOnHover(index)) {
                 m_autoActivationTimer->setProperty("index", index);
                 m_autoActivationTimer->start();
                 newHoveredWidget->startActivateSoonAnimation(m_autoActivationTimer->remainingTime());
             }
+
         } else {
             m_autoActivationTimer->stop();
             if (newHoveredWidget && newHoveredWidget->isHovered()) {
index b49d4ebb1d4e7df655c709942a3ba7417f4d3f01..9fdecafb864425cc887ca47b1e164b1a04cdb769 100644 (file)
@@ -128,6 +128,12 @@ bool KItemModelBase::supportsDropping(int index) const
     return false;
 }
 
+bool KItemModelBase::canEnterOnHover(int index) const
+{
+    Q_UNUSED(index)
+    return false;
+}
+
 QString KItemModelBase::blacklistItemDropEventMimeType() const
 {
     return QStringLiteral("application/x-dolphin-blacklist-drop");
index 4e1fd8a8fe59b9613705a75645fe58dfbe9ad791..42a9c54c94ca915474a305bffee18c309cd59914 100644 (file)
@@ -159,6 +159,15 @@ public:
     // decision whether it accepts the drop?
     virtual bool supportsDropping(int index) const;
 
+    /**
+     * @return True, if the item with the index \a index can be entered in during hover actions.
+     *         Per default false is returned.
+     *
+     *         This is used to check that if the item
+     *         we're hovering on is either directory or a desktop file.
+     */
+    virtual bool canEnterOnHover(int index) const;
+
     /**
      * @return An internal mimetype to signal that an itemDropEvent() should be rejected by
      *         the receiving model.