From 718df1363dc1ecac2d3376d3e288947549aeb42f Mon Sep 17 00:00:00 2001 From: Peter Penz Date: Fri, 14 Nov 2008 17:49:30 +0000 Subject: [PATCH] when renaming a variable number of items, it is important that the selection order does not define the new sort order -> the sort order with the renamed files should stay similar with the old sort order svn path=/trunk/KDE/kdebase/apps/; revision=884344 --- src/dolphinview.cpp | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/dolphinview.cpp b/src/dolphinview.cpp index 31b9de785..9eadcecb2 100644 --- a/src/dolphinview.cpp +++ b/src/dolphinview.cpp @@ -33,6 +33,7 @@ #include #include #include +#include #include #include #include @@ -44,6 +45,7 @@ #include #include #include +#include #include #include @@ -64,6 +66,15 @@ #include "viewproperties.h" #include "zoomlevelinfo.h" +/** + * Helper function for sorting items with qSort() in + * DolphinView::renameSelectedItems(). + */ +bool lessThan(const KFileItem& item1, const KFileItem& item2) +{ + return KStringHandler::naturalCompare(item1.name(), item2.name()) < 0; +} + DolphinView::DolphinView(QWidget* parent, const KUrl& url, KDirLister* dirLister, @@ -594,7 +605,7 @@ void DolphinView::changeSelection(const KFileItemList& selection) void DolphinView::renameSelectedItems() { - const KFileItemList items = selectedItems(); + KFileItemList items = selectedItems(); const int itemCount = items.count(); if (itemCount < 1) { return; @@ -615,10 +626,14 @@ void DolphinView::renameSelectedItems() // 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) { + foreach (const KFileItem& item, items) { const KUrl& oldUrl = item.url(); QString number; number.setNum(index++); -- 2.47.3