]> cloud.milkyroute.net Git - dolphin.git/commitdiff
Show hidden files and folders last
authorGastón Haro <harogaston@gmail.com>
Tue, 27 Apr 2021 05:40:35 +0000 (02:40 -0300)
committerMéven Car <meven29@gmail.com>
Mon, 10 May 2021 06:13:56 +0000 (06:13 +0000)
Hidden files and folders are always displayed after
not hidden files.

BUG: 241227

Revision: https://phabricator.kde.org/D29115

src/kitemviews/kfileitemmodel.cpp
src/tests/kfileitemmodeltest.cpp

index fa101f89a2a2a6524b3f838e15e4e0528c65dc5e..2ffb219a0ac15ec05534890a670b1a648706b219 100644 (file)
@@ -1733,6 +1733,15 @@ bool KFileItemModel::lessThan(const ItemData* a, const ItemData* b, const QColla
         }
     }
 
+    // Show hidden files and folders last
+    const bool isHiddenA = a->item.isHidden();
+    const bool isHiddenB = b->item.isHidden();
+    if (isHiddenA && !isHiddenB) {
+        return false;
+    } else if (!isHiddenA && isHiddenB) {
+        return true;
+    }
+
     if (m_sortDirsFirst || (DetailsModeSettings::directorySizeCount() && m_sortRole == SizeRole)) {
         const bool isDirA = a->item.isDir();
         const bool isDirB = b->item.isDir();
index 558a00ab592475fb2b30a6a295967d2913221943..f527fbc61b2043bd7d45bed1e44bbe7add949652 100644 (file)
@@ -812,6 +812,19 @@ void KFileItemModelTest::testRemoveFilteredExpandedItems()
 
 void KFileItemModelTest::testSorting()
 {
+    // testDir structure is as follows
+    // ./
+    // ├─ a
+    // ├─ b
+    // ├─ c/
+    // │  ├─ c-2/
+    // │  │  ├─ c-3
+    // │  ├─ c-1
+    // ├─ d
+    // ├─ e
+    // ├─ .f
+    // ├─ .g/
+
     QSignalSpy itemsInsertedSpy(m_model, &KFileItemModel::itemsInserted);
     QSignalSpy itemsMovedSpy(m_model, &KFileItemModel::itemsMoved);
     QVERIFY(itemsMovedSpy.isValid());
@@ -836,17 +849,27 @@ void KFileItemModelTest::testSorting()
     m_testDir->createFile("d", "The largest file in this directory", now.addDays(-1));
     m_testDir->createFile("e", "An even larger file", now.addDays(-4));
     m_testDir->createFile(".f");
+    m_testDir->createDir(".g");
 
     m_model->loadDirectory(m_testDir->url());
     QVERIFY(itemsInsertedSpy.wait());
+    QCOMPARE(itemsInsertedSpy.count(), 1);
+    KItemRangeList itemRangeList = itemsInsertedSpy.takeFirst().at(0).value<KItemRangeList>();
+    QCOMPARE(itemRangeList, KItemRangeList() << KItemRange(0, 5));
 
     int index = m_model->index(QUrl(m_testDir->url().url() + "/c"));
     m_model->setExpanded(index, true);
     QVERIFY(itemsInsertedSpy.wait());
+    QCOMPARE(itemsInsertedSpy.count(), 1);
+    itemRangeList = itemsInsertedSpy.takeFirst().at(0).value<KItemRangeList>();
+    QCOMPARE(itemRangeList, KItemRangeList() << KItemRange(1, 2));
 
     index = m_model->index(QUrl(m_testDir->url().url() + "/c/c-2"));
     m_model->setExpanded(index, true);
     QVERIFY(itemsInsertedSpy.wait());
+    QCOMPARE(itemsInsertedSpy.count(), 1);
+    itemRangeList = itemsInsertedSpy.takeFirst().at(0).value<KItemRangeList>();
+    QCOMPARE(itemRangeList, KItemRangeList() << KItemRange(2, 1));
 
     // Default: Sort by Name, ascending
     QCOMPARE(m_model->sortRole(), QByteArray("text"));
@@ -942,7 +965,36 @@ void KFileItemModelTest::testSorting()
     QCOMPARE(itemsMovedSpy.first().at(0).value<KItemRange>(), KItemRange(4, 4));
     QCOMPARE(itemsMovedSpy.takeFirst().at(1).value<QList<int> >(), QList<int>() << 7 << 6 << 5 << 4);
 
-    // TODO: Sort by other roles; show/hide hidden files
+    // 'Show Hidden Files' enabled
+    m_model->setShowHiddenFiles(true);
+    QVERIFY(m_model->showHiddenFiles());
+    QCOMPARE(itemsInModel(), QStringList() << "c" << "c-2" << "c-3" << "c-1" << "d" << "e" << "b" << "a" << ".g" << ".f");
+    QCOMPARE(itemsMovedSpy.count(), 0);
+    QCOMPARE(itemsInsertedSpy.count(), 1);
+    QCOMPARE(itemsInsertedSpy.takeFirst().at(0).value<KItemRangeList>(), KItemRangeList() << KItemRange(8, 2));
+
+    // Sort by Name
+    m_model->setSortRole("text");
+    QCOMPARE(itemsInModel(), QStringList() << "c" << "c-2" << "c-3" << "c-1" << "e" << "d" << "b" << "a" << ".g" << ".f");
+    QCOMPARE(itemsMovedSpy.count(), 1);
+    QCOMPARE(itemsMovedSpy.first().at(0).value<KItemRange>(), KItemRange(4, 2));
+    QCOMPARE(itemsMovedSpy.takeFirst().at(1).value<QList<int> >(), QList<int>() << 5 << 4);
+
+    // Sort ascending
+    m_model->setSortOrder(Qt::AscendingOrder);
+    QCOMPARE(itemsInModel(), QStringList() << "c" << "c-2" << "c-3" << "c-1" << "a" << "b" << "d" << "e" << ".g" << ".f");
+    QCOMPARE(itemsMovedSpy.count(), 1);
+    QCOMPARE(itemsMovedSpy.first().at(0).value<KItemRange>(), KItemRange(4, 4));
+    QCOMPARE(itemsMovedSpy.takeFirst().at(1).value<QList<int> >(), QList<int>() << 7 << 6 << 5 << 4);
+
+    // 'Sort Folders First' disabled
+    m_model->setSortDirectoriesFirst(false);
+    QVERIFY(!m_model->sortDirectoriesFirst());
+    QCOMPARE(itemsInModel(), QStringList() << "a" << "b" << "c" << "c-1" << "c-2" << "c-3" << "d" << "e" << ".f" << ".g");
+    QCOMPARE(itemsMovedSpy.count(), 1);
+    QCOMPARE(itemsMovedSpy.first().at(0).value<KItemRange>(), KItemRange(0, 10));
+    QCOMPARE(itemsMovedSpy.takeFirst().at(1).value<QList<int> >(), QList<int>() << 2 << 4 << 5 << 3 << 0 << 1 << 6 << 7 << 9 << 8);
+
 }
 
 void KFileItemModelTest::testIndexForKeyboardSearch()
@@ -1099,7 +1151,7 @@ void KFileItemModelTest::testRemoveHiddenItems()
     m_model->setShowHiddenFiles(true);
     m_model->loadDirectory(m_testDir->url());
     QVERIFY(itemsInsertedSpy.wait());
-    QCOMPARE(itemsInModel(), QStringList() << ".a" << ".b" << "c" << "d" <<".f" << ".g" << "h" << "i");
+    QCOMPARE(itemsInModel(), QStringList() << "c" << "d" << "h" << "i" << ".a" << ".b" <<".f" << ".g");
     QCOMPARE(itemsInsertedSpy.count(), 1);
     QCOMPARE(itemsRemovedSpy.count(), 0);
     KItemRangeList itemRangeList = itemsInsertedSpy.takeFirst().at(0).value<KItemRangeList>();
@@ -1110,14 +1162,14 @@ void KFileItemModelTest::testRemoveHiddenItems()
     QCOMPARE(itemsInsertedSpy.count(), 0);
     QCOMPARE(itemsRemovedSpy.count(), 1);
     itemRangeList = itemsRemovedSpy.takeFirst().at(0).value<KItemRangeList>();
-    QCOMPARE(itemRangeList, KItemRangeList() << KItemRange(0, 2) << KItemRange(4, 2));
+    QCOMPARE(itemRangeList, KItemRangeList() << KItemRange(4, 4));
 
     m_model->setShowHiddenFiles(true);
-    QCOMPARE(itemsInModel(), QStringList() << ".a" << ".b" << "c" << "d" <<".f" << ".g" << "h" << "i");
+    QCOMPARE(itemsInModel(), QStringList() << "c" << "d" << "h" << "i" << ".a" << ".b" <<".f" << ".g");
     QCOMPARE(itemsInsertedSpy.count(), 1);
     QCOMPARE(itemsRemovedSpy.count(), 0);
     itemRangeList = itemsInsertedSpy.takeFirst().at(0).value<KItemRangeList>();
-    QCOMPARE(itemRangeList, KItemRangeList() << KItemRange(0, 2) << KItemRange(2, 2));
+    QCOMPARE(itemRangeList, KItemRangeList() << KItemRange(4, 4));
 
     m_model->clear();
     QCOMPARE(itemsInModel(), QStringList());