1
0
mirror of https://invent.kde.org/system/dolphin synced 2024-07-02 16:31:23 +00:00

Start autoActivationTimer only if hovering over a directory

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
This commit is contained in:
Akseli Lahtinen 2024-03-08 11:37:20 +00:00
parent 599ddb3c0d
commit 803bbd1ae1
5 changed files with 30 additions and 1 deletions

View 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;

View 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;

View 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()) {

View 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");

View 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.