- } else {
- // TODO: check how this can be integrated into KIO::FileUndoManager/KonqOperations
- // as one operation instead of n rename operations like it is done now...
- Q_ASSERT(newName.contains('#'));
-
- // iterate through all selected items and rename them...
- int index = 1;
- foreach (const KFileItem &item, items) {
- const KUrl& oldUrl = item.url();
- QString number;
- number.setNum(index++);
-
- QString name = newName;
- name.replace('#', number);
-
- if (oldUrl.fileName() != name) {
- KUrl newUrl = oldUrl;
- newUrl.setFileName(name);
- KonqOperations::rename(this, oldUrl, newUrl);
- }
+ return;
+ }
+
+ // TODO: check how this can be integrated into KIO::FileUndoManager/KonqOperations
+ // as one operation instead of n rename operations like it is done now...
+ Q_ASSERT(newName.contains('#'));
+
+ // currently the items are sorted by the selection order, resort
+ // them by the file name
+ qSort(items.begin(), items.end(), lessThan);
+
+ // iterate through all selected items and rename them...
+ int index = 1;
+ foreach (const KFileItem& item, items) {
+ const KUrl& oldUrl = item.url();
+ QString number;
+ number.setNum(index++);
+
+ QString name = newName;
+ name.replace('#', number);
+
+ if (oldUrl.fileName() != name) {
+ KUrl newUrl = oldUrl;
+ newUrl.setFileName(name);
+ KonqOperations::rename(this, oldUrl, newUrl);