]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Do not show an incorrect file name after a failed rename operation
authorFrank Reininghaus <frank78ac@googlemail.com>
Wed, 31 Oct 2012 22:06:39 +0000 (23:06 +0100)
committerFrank Reininghaus <frank78ac@googlemail.com>
Wed, 31 Oct 2012 22:06:39 +0000 (23:06 +0100)
BUG: 303742
FIXED-IN: 4.9.3

src/views/dolphinview.cpp

index 624aa185db8971a5341b506f0fcb4084827293ce..8e1a191082dece7997388f05469b434a589fcded 100644 (file)
@@ -1348,9 +1348,18 @@ void DolphinView::slotRoleEditingFinished(int index, const QByteArray& role, con
         if (!newName.isEmpty() && newName != oldItem.text() && newName != QLatin1String(".") && newName != QLatin1String("..")) {
             const KUrl oldUrl = oldItem.url();
 
-            QHash<QByteArray, QVariant> data;
-            data.insert(role, value);
-            m_model->setData(index, data);
+            const KUrl newUrl(url().path(KUrl::AddTrailingSlash) + newName);
+            const bool newNameExistsAlready = (m_model->index(newUrl) >= 0);
+            if (!newNameExistsAlready) {
+                // 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 KonqOperations::rename() 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);
+                m_model->setData(index, data);
+            }
 
             KonqOperations::rename(this, oldUrl, newName);
         }