Skip to content

Commit d1b13fc

Browse files
committed
[ADD] : add linux sorting for directory starting by a dot (.xxx) (jackm97@bf40515)
1 parent 9c61f6b commit d1b13fc

1 file changed

Lines changed: 30 additions & 1 deletion

File tree

ImGuiFileDialog.cpp

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -989,6 +989,17 @@ namespace IGFD
989989
if (!a.use_count() || !b.use_count())
990990
return false;
991991

992+
// use code from https://github.com/jackm97/ImGuiFileDialog/commit/bf40515f5a1de3043e60562dc1a494ee7ecd3571
993+
// strict ordering for file/directory types beginning in '.'
994+
// common on Linux platforms
995+
if (a->fileName[0] == '.' && b->fileName[0] != '.')
996+
return false;
997+
if (a->fileName[0] != '.' && b->fileName[0] == '.')
998+
return true;
999+
if (a->fileName[0] == '.' && b->fileName[0] == '.')
1000+
{
1001+
return (stricmp(a->fileName.c_str(), b->fileName.c_str()) < 0); // sort in insensitive case
1002+
}
9921003
if (a->fileType != b->fileType) return (a->fileType == 'd'); // directory in first
9931004
return (stricmp(a->fileName.c_str(), b->fileName.c_str()) < 0); // sort in insensitive case
9941005
});
@@ -1004,7 +1015,25 @@ namespace IGFD
10041015
if (!a.use_count() || !b.use_count())
10051016
return false;
10061017

1007-
if (a->fileType != b->fileType) return (a->fileType != 'd'); // directory in last
1018+
// use code from https://github.com/jackm97/ImGuiFileDialog/commit/bf40515f5a1de3043e60562dc1a494ee7ecd3571
1019+
// strict ordering for file/directory types beginning in '.'
1020+
// common on Linux platforms
1021+
if (a->fileName[0] == '.' && b->fileName[0] != '.')
1022+
return false;
1023+
if (a->fileName[0] != '.' && b->fileName[0] == '.')
1024+
return true;
1025+
if (a->fileName[0] == '.' && b->fileName[0] == '.')
1026+
{
1027+
return (stricmp(a->fileName.c_str(), b->fileName.c_str()) > 0); // sort in insensitive case
1028+
}
1029+
if (a->fileType != b->fileType)
1030+
{
1031+
// this code fail in c:^^Userd with the link "All users". got a invalid comparator
1032+
// but dont know why...
1033+
// if i comment that all is ok..
1034+
bool res = (b->fileType != 'd'); // directory in last
1035+
return res; // directory in last
1036+
}
10081037
return (stricmp(a->fileName.c_str(), b->fileName.c_str()) > 0); // sort in insensitive case
10091038
});
10101039
}

0 commit comments

Comments
 (0)