Commit 5bee1889 authored by Andreas Krutzler's avatar Andreas Krutzler Committed by Nathaniel Graham

Fix scrolling during inline renaming causes rename of wrong file

Summary:
Scrolling during inline renaming accepts the renaming now, like if one would hit Return for example. I chose this approach because it seems the easiest way to fix this.
This also fixes the “possible” Ui glitch where the renaming KTextField doesn’t move along with the list item. Possible glitch, because I don’t know if this is intentional, but for me it looks broken.

BUG: 378786
Fixes T7443

Test Plan:
* Enable "Rename inline" in dolphin settings
* Go to a folder where you have to scroll through items (many files, big zoom,…)
* Start to rename a file (context menu, F2, …)
* Scroll with mouse wheel
* Rename  accepted -> file is renamed

Reviewers: ngraham, rkflx, #dolphin, elvisangelaccio

Reviewed By: ngraham, rkflx, #dolphin, elvisangelaccio

Subscribers: anthonyfieroni, elvisangelaccio, #dolphin

Maniphest Tasks: T7443

Differential Revision: https://phabricator.kde.org/D8822
parent e60e3f07
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
#include "kitemlistcontroller.h" #include "kitemlistcontroller.h"
#include "kitemlistheader.h" #include "kitemlistheader.h"
#include "kitemlistselectionmanager.h" #include "kitemlistselectionmanager.h"
#include "kitemlistwidget.h" #include "kstandarditemlistwidget.h"
#include "private/kitemlistheaderwidget.h" #include "private/kitemlistheaderwidget.h"
#include "private/kitemlistrubberband.h" #include "private/kitemlistrubberband.h"
...@@ -642,7 +642,7 @@ QPixmap KItemListView::createDragPixmap(const KItemSet& indexes) const ...@@ -642,7 +642,7 @@ QPixmap KItemListView::createDragPixmap(const KItemSet& indexes) const
void KItemListView::editRole(int index, const QByteArray& role) void KItemListView::editRole(int index, const QByteArray& role)
{ {
KItemListWidget* widget = m_visibleItems.value(index); KStandardItemListWidget* widget = qobject_cast<KStandardItemListWidget *>(m_visibleItems.value(index));
if (!widget || m_editingRole) { if (!widget || m_editingRole) {
return; return;
} }
...@@ -654,6 +654,9 @@ void KItemListView::editRole(int index, const QByteArray& role) ...@@ -654,6 +654,9 @@ void KItemListView::editRole(int index, const QByteArray& role)
this, &KItemListView::slotRoleEditingCanceled); this, &KItemListView::slotRoleEditingCanceled);
connect(widget, &KItemListWidget::roleEditingFinished, connect(widget, &KItemListWidget::roleEditingFinished,
this, &KItemListView::slotRoleEditingFinished); this, &KItemListView::slotRoleEditingFinished);
connect(this, &KItemListView::scrollOffsetChanged,
widget, &KStandardItemListWidget::finishRoleEditing);
} }
void KItemListView::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) void KItemListView::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
...@@ -2639,13 +2642,14 @@ bool KItemListView::hasSiblingSuccessor(int index) const ...@@ -2639,13 +2642,14 @@ bool KItemListView::hasSiblingSuccessor(int index) const
void KItemListView::disconnectRoleEditingSignals(int index) void KItemListView::disconnectRoleEditingSignals(int index)
{ {
KItemListWidget* widget = m_visibleItems.value(index); KStandardItemListWidget* widget = qobject_cast<KStandardItemListWidget *>(m_visibleItems.value(index));
if (!widget) { if (!widget) {
return; return;
} }
disconnect(widget, &KItemListWidget::roleEditingCanceled, this, nullptr); disconnect(widget, &KItemListWidget::roleEditingCanceled, this, nullptr);
disconnect(widget, &KItemListWidget::roleEditingFinished, this, nullptr); disconnect(widget, &KItemListWidget::roleEditingFinished, this, nullptr);
disconnect(this, &KItemListView::scrollOffsetChanged, widget, nullptr);
} }
int KItemListView::calculateAutoScrollingIncrement(int pos, int range, int oldInc) int KItemListView::calculateAutoScrollingIncrement(int pos, int range, int oldInc)
......
...@@ -860,6 +860,13 @@ bool KStandardItemListWidget::event(QEvent *event) ...@@ -860,6 +860,13 @@ bool KStandardItemListWidget::event(QEvent *event)
return KItemListWidget::event(event); return KItemListWidget::event(event);
} }
void KStandardItemListWidget::finishRoleEditing()
{
if (!editedRole().isEmpty() && m_roleEditor) {
slotRoleEditingFinished(editedRole(), KIO::encodeFileName(m_roleEditor->toPlainText()));
}
}
void KStandardItemListWidget::slotCutItemsChanged() void KStandardItemListWidget::slotCutItemsChanged()
{ {
const QUrl itemUrl = data().value("url").toUrl(); const QUrl itemUrl = data().value("url").toUrl();
......
...@@ -185,6 +185,9 @@ protected: ...@@ -185,6 +185,9 @@ protected:
virtual void hideEvent(QHideEvent* event) Q_DECL_OVERRIDE; virtual void hideEvent(QHideEvent* event) Q_DECL_OVERRIDE;
bool event(QEvent *event) Q_DECL_OVERRIDE; bool event(QEvent *event) Q_DECL_OVERRIDE;
public slots:
void finishRoleEditing();
private slots: private slots:
void slotCutItemsChanged(); void slotCutItemsChanged();
void slotRoleEditingCanceled(const QByteArray& role, const QVariant& value); void slotRoleEditingCanceled(const QByteArray& role, const QVariant& value);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment