disconnect(previous, &KItemListView::maximumItemOffsetChanged,
this, &KItemListContainer::updateItemOffsetScrollBar);
disconnect(previous, &KItemListView::scrollTo, this, &KItemListContainer::scrollTo);
+ disconnect(m_horizontalSmoothScroller, &KItemListSmoothScroller::scrollingStopped, previous, &KItemListView::scrollingStopped);
+ disconnect(m_verticalSmoothScroller, &KItemListSmoothScroller::scrollingStopped, previous, &KItemListView::scrollingStopped);
m_horizontalSmoothScroller->setTargetObject(nullptr);
m_verticalSmoothScroller->setTargetObject(nullptr);
}
connect(current, &KItemListView::maximumItemOffsetChanged,
this, &KItemListContainer::updateItemOffsetScrollBar);
connect(current, &KItemListView::scrollTo, this, &KItemListContainer::scrollTo);
+ connect(m_horizontalSmoothScroller, &KItemListSmoothScroller::scrollingStopped, current, &KItemListView::scrollingStopped);
+ connect(m_verticalSmoothScroller, &KItemListSmoothScroller::scrollingStopped, current, &KItemListView::scrollingStopped);
+
m_horizontalSmoothScroller->setTargetObject(current);
m_verticalSmoothScroller->setTargetObject(current);
updateSmoothScrollers(current->scrollOrientation());
if (newOffset != scrollOffset()) {
Q_EMIT scrollTo(newOffset);
+ return;
}
}
+
+ Q_EMIT scrollingStopped();
}
void KItemListView::beginTransaction()
{
disconnectRoleEditingSignals(index);
- Q_EMIT roleEditingCanceled(index, role, value);
m_editingRole = false;
+ Q_EMIT roleEditingCanceled(index, role, value);
}
void KItemListView::slotRoleEditingFinished(int index, const QByteArray& role, const QVariant& value)
{
disconnectRoleEditingSignals(index);
- Q_EMIT roleEditingFinished(index, role, value);
m_editingRole = false;
+ Q_EMIT roleEditingFinished(index, role, value);
}
void KItemListView::setController(KItemListController* controller)
void roleEditingCanceled(int index, const QByteArray& role, const QVariant& value);
void roleEditingFinished(int index, const QByteArray& role, const QVariant& value);
+ /**
+ * Emitted once scrolling has finished, or immediately if no scrolling was necessary
+ * to get item in view in scrollToItem.
+ */
+ void scrollingStopped();
+
protected:
QVariant itemChange(GraphicsItemChange change, const QVariant &value) override;
void setItemSize(const QSizeF& size);
m_roleEditor = new KItemListRoleEditor(parent);
m_roleEditor->setRole(current);
+ m_roleEditor->setAllowUpDownKeyChainEdit(m_layout != IconsLayout);
m_roleEditor->setFont(styleOption().font);
const QString text = data().value(current).toString();
return m_role;
}
+void KItemListRoleEditor::setAllowUpDownKeyChainEdit(bool allowChainEdit)
+{
+ m_allowUpDownKeyChainEdit = allowChainEdit;
+}
+
bool KItemListRoleEditor::eventFilter(QObject* watched, QEvent* event)
{
if (watched == parentWidget() && event->type() == QEvent::Resize) {
emitRoleEditingFinished();
event->accept();
return;
+ case Qt::Key_Tab:
+ case Qt::Key_Down:
+ if (m_allowUpDownKeyChainEdit || event->key() == Qt::Key_Tab) {
+ emitRoleEditingFinished(EditNext);
+ event->accept();
+ return;
+ }
+ case Qt::Key_Backtab:
+ case Qt::Key_Up:
+ if (m_allowUpDownKeyChainEdit || event->key() == Qt::Key_Backtab) {
+ emitRoleEditingFinished(EditPrevious);
+ event->accept();
+ return;
+ }
case Qt::Key_Left:
case Qt::Key_Right: {
QTextCursor cursor = textCursor();
}
}
-void KItemListRoleEditor::emitRoleEditingFinished()
+void KItemListRoleEditor::emitRoleEditingFinished(EditResultDirection direction)
{
+ QVariant ret;
+ ret.setValue(EditResult {KIO::encodeFileName(toPlainText()), direction});
+
if (!m_blockFinishedSignal) {
- Q_EMIT roleEditingFinished(m_role, KIO::encodeFileName(toPlainText()));
+ Q_EMIT roleEditingFinished(m_role, ret);
}
}
#include <KTextEdit>
+enum EditResultDirection{
+ EditDone,
+ EditNext,
+ EditPrevious,
+};
+Q_DECLARE_METATYPE(EditResultDirection)
+
+struct EditResult
+{
+ QString newName;
+ EditResultDirection direction;
+};
+Q_DECLARE_METATYPE(EditResult)
+
/**
* @brief Editor for renaming roles of a KItemListWidget.
*
* Provides signals when the editing got cancelled (e.g. by
* pressing Escape or when losing the focus) or when the editing
- * got finished (e.g. by pressing Enter or Return).
+ * got finished (e.g. by pressing Enter, Tab or Return).
*
* The size automatically gets increased if the text does not fit.
*/
void setRole(const QByteArray& role);
QByteArray role() const;
+ void setAllowUpDownKeyChainEdit(bool allowChainEdit);
bool eventFilter(QObject* watched, QEvent* event) override;
Q_SIGNALS:
* Emits the signal roleEditingFinished if m_blockFinishedSignal
* is false.
*/
- void emitRoleEditingFinished();
+ void emitRoleEditingFinished(EditResultDirection direction = EditDone);
private:
QByteArray m_role;
bool m_blockFinishedSignal;
+ bool m_allowUpDownKeyChainEdit;
};
#endif
if (newState == QAbstractAnimation::Stopped && m_smoothScrolling && !m_scrollBarPressed) {
m_smoothScrolling = false;
}
+ if (newState == QAbstractAnimation::Stopped) {
+ Q_EMIT scrollingStopped();
+ }
}
void KItemListSmoothScroller::handleWheelEvent(QWheelEvent* event)
*/
void handleWheelEvent(QWheelEvent* event);
+Q_SIGNALS:
+ /**
+ * Emitted when the scrolling animation has finished
+ */
+ void scrollingStopped();
protected:
bool eventFilter(QObject* obj, QEvent* event) override;
#include "kitemviews/kitemlistcontroller.h"
#include "kitemviews/kitemlistheader.h"
#include "kitemviews/kitemlistselectionmanager.h"
+#include "kitemviews/private/kitemlistroleeditor.h"
#include "versioncontrol/versioncontrolobserver.h"
#include "viewproperties.h"
#include "views/tooltips/tooltipmanager.h"
if (items.count() == 1 && GeneralSettings::renameInline()) {
const int index = m_model->index(items.first());
- m_view->editRole(index, "text");
- hideToolTip();
+ QMetaObject::Connection * const connection = new QMetaObject::Connection;
+ *connection = connect(m_view, &KItemListView::scrollingStopped, this, [=](){
+ QObject::disconnect(*connection);
+ delete connection;
+
+ m_view->editRole(index, "text");
+
+ hideToolTip();
+
+ connect(m_view, &DolphinItemListView::roleEditingFinished,
+ this, &DolphinView::slotRoleEditingFinished);
+ });
+ m_view->scrollToItem(index);
- connect(m_view, &DolphinItemListView::roleEditingFinished,
- this, &DolphinView::slotRoleEditingFinished);
} else {
KIO::RenameFileDialog* dialog = new KIO::RenameFileDialog(items, this);
connect(dialog, &KIO::RenameFileDialog::renamingFinished,
disconnect(m_view, &DolphinItemListView::roleEditingFinished,
this, &DolphinView::slotRoleEditingFinished);
- if (index < 0 || index >= m_model->count()) {
+ const KFileItemList items = selectedItems();
+ if (items.count() != 1) {
return;
}
if (role == "text") {
- const KFileItem oldItem = m_model->fileItem(index);
- const QString newName = value.toString();
+ const KFileItem oldItem = items.first();
+ const EditResult retVal = value.value<EditResult>();
+ const QString newName = retVal.newName;
if (!newName.isEmpty() && newName != oldItem.text() && newName != QLatin1Char('.') && newName != QLatin1String("..")) {
const QUrl oldUrl = oldItem.url();
#endif
const bool newNameExistsAlready = (m_model->index(newUrl) >= 0);
- if (!newNameExistsAlready) {
+ if (!newNameExistsAlready && m_model->index(oldUrl) == index) {
// Only change the data in the model if no item with the new name
// is in the model yet. If there is an item with the new name
// already, calling KIO::CopyJob will open a dialog
// asking for a new name, and KFileItemModel will update the
// data when the dir lister signals that the file name has changed.
QHash<QByteArray, QVariant> data;
- data.insert(role, value);
+ data.insert(role, retVal.newName);
m_model->setData(index, data);
}
connect(job, &KJob::result, this, &DolphinView::slotRenamingResult);
}
}
+ if (retVal.direction != EditDone) {
+ const short indexShift = retVal.direction == EditNext ? 1 : -1;
+ m_container->controller()->selectionManager()->setSelected(index, 1, KItemListSelectionManager::Deselect);
+ m_container->controller()->selectionManager()->setSelected(index + indexShift, 1,
+ KItemListSelectionManager::Select);
+ renameSelectedItems();
+ }
}
}