@@ -823,6 +823,7 @@ void IGFD::FilterManager::ParseFilters(const char* vFilters) {
823823 collection_started = true ;
824824 prParsedFilters.emplace_back ();
825825 prParsedFilters.back ().filter = filter_name;
826+ prParsedFilters.back ().filter_optimized = Utils::LowerCaseString (filter_name);
826827 filter_name.clear ();
827828 word.clear ();
828829 }
@@ -857,9 +858,11 @@ void IGFD::FilterManager::ParseFilters(const char* vFilters) {
857858 if (collection_started) {
858859 prParsedFilters.back ().collectionfilters .emplace (word);
859860 prParsedFilters.back ().collectionfilters_regex .emplace_back (rx);
861+ prParsedFilters.back ().collectionfilters_optimized .emplace (Utils::LowerCaseString (word));
860862 } else {
861863 prParsedFilters.emplace_back ();
862- prParsedFilters.back ().filter = word;
864+ prParsedFilters.back ().filter = word;
865+ prParsedFilters.back ().filter_optimized = Utils::LowerCaseString (word);
863866 prParsedFilters.back ().filter_regex = rx;
864867 }
865868 } catch (std::exception&) {}
@@ -894,13 +897,15 @@ void IGFD::FilterManager::ParseFilters(const char* vFilters) {
894897 if (collection_started) {
895898 if (word.size () > 1U && word[0 ] == ' .' ) {
896899 prParsedFilters.back ().collectionfilters .emplace (word);
900+ prParsedFilters.back ().collectionfilters_optimized .emplace (Utils::LowerCaseString (word));
897901 word.clear ();
898902 filter_name.clear ();
899903 }
900904 } else {
901905 if (word.size () > 1U && word[0 ] == ' .' ) {
902906 prParsedFilters.emplace_back ();
903- prParsedFilters.back ().filter = word;
907+ prParsedFilters.back ().filter = word;
908+ prParsedFilters.back ().filter_optimized = Utils::LowerCaseString (word);
904909 word.clear ();
905910 filter_name.clear ();
906911 }
@@ -921,7 +926,8 @@ void IGFD::FilterManager::ParseFilters(const char* vFilters) {
921926 }
922927 } else if (word.size () > 1U && word[0 ] == ' .' ) {
923928 prParsedFilters.emplace_back ();
924- prParsedFilters.back ().filter = word;
929+ prParsedFilters.back ().filter = word;
930+ prParsedFilters.back ().filter_optimized = Utils::LowerCaseString (word);
925931 word.clear ();
926932 }
927933
@@ -981,42 +987,46 @@ bool IGFD::FilterManager::prFillFileStyle(std::shared_ptr<FileInfos> vFileInfos)
981987 (_flag.first & IGFD_FileStyleByTypeFile && _flag.first & IGFD_FileStyleByTypeLink && vFileInfos->fileType .isFile () && vFileInfos->fileType .isSymLink ()) ||
982988 (_flag.first & IGFD_FileStyleByTypeLink && vFileInfos->fileType .isSymLink ()) || (_flag.first & IGFD_FileStyleByTypeDir && vFileInfos->fileType .isDir ()) ||
983989 (_flag.first & IGFD_FileStyleByTypeFile && vFileInfos->fileType .isFile ())) {
984- if (_file.first .empty ()) // for all links
985- {
990+ if (_file.first .empty ()) { // for all links
986991 vFileInfos->fileStyle = _file.second ;
987- } else if (_file.first .find (' (' ) != std::string::npos && std::regex_search (vFileInfos->fileNameExt , std::regex (_file.first ))) // for links who are equal to style criteria
988- {
992+ } else if (_file.first .find (" ((" ) != std::string::npos && std::regex_search (vFileInfos->fileNameExt , std::regex (_file.first ))) { // for links who are equal to style criteria
989993 vFileInfos->fileStyle = _file.second ;
990- } else if (_file.first == vFileInfos->fileNameExt ) // for links who are equal to style criteria
991- {
994+ } else if (_file.first == vFileInfos->fileNameExt ) { // for links who are equal to style criteria
992995 vFileInfos->fileStyle = _file.second ;
993996 }
994997 }
995998
996999 if (_flag.first & IGFD_FileStyleByExtention) {
997- if (_file.first .find (' ( ' ) != std::string::npos && std::regex_search (vFileInfos->fileExt , std::regex (_file.first ))) {
1000+ if (_file.first .find (" (( " ) != std::string::npos && std::regex_search (vFileInfos->fileExt , std::regex (_file.first ))) {
9981001 vFileInfos->fileStyle = _file.second ;
9991002 } else if (_file.first == vFileInfos->fileExt ) {
10001003 vFileInfos->fileStyle = _file.second ;
10011004 }
10021005 }
10031006
10041007 if (_flag.first & IGFD_FileStyleByFullName) {
1005- if (_file.first .find (' ( ' ) != std::string::npos && std::regex_search (vFileInfos->fileNameExt , std::regex (_file.first ))) {
1008+ if (_file.first .find (" (( " ) != std::string::npos && std::regex_search (vFileInfos->fileNameExt , std::regex (_file.first ))) {
10061009 vFileInfos->fileStyle = _file.second ;
10071010 } else if (_file.first == vFileInfos->fileNameExt ) {
10081011 vFileInfos->fileStyle = _file.second ;
10091012 }
10101013 }
10111014
10121015 if (_flag.first & IGFD_FileStyleByContainedInFullName) {
1013- if (_file.first .find (' ( ' ) != std::string::npos && std::regex_search (vFileInfos->fileNameExt , std::regex (_file.first ))) {
1016+ if (_file.first .find (" (( " ) != std::string::npos && std::regex_search (vFileInfos->fileNameExt , std::regex (_file.first ))) {
10141017 vFileInfos->fileStyle = _file.second ;
10151018 } else if (vFileInfos->fileNameExt .find (_file.first ) != std::string::npos) {
10161019 vFileInfos->fileStyle = _file.second ;
10171020 }
10181021 }
10191022
1023+ for (auto & functor : prFilesStyleFunctors) {
1024+ if (functor) {
1025+ auto ptr = functor (*(vFileInfos.get ()));
1026+ if (ptr) { vFileInfos->fileStyle = std::move (ptr); }
1027+ }
1028+ }
1029+
10201030 if (vFileInfos->fileStyle .use_count ()) return true ;
10211031 }
10221032 }
@@ -1032,12 +1042,15 @@ void IGFD::FilterManager::SetFileStyle(const IGFD_FileStyleFlags& vFlags, const
10321042 prFilesStyle[vFlags][_criteria]->flags = vFlags;
10331043}
10341044
1035- // todo : to refactor this fucking function
1045+ void IGFD::FilterManager::SetFileStyle (FileStyle::FileStyleFunctor vFunctor) {
1046+ if (vFunctor) { prFilesStyleFunctors.push_back (vFunctor); }
1047+ }
1048+
1049+ // todo : refactor this fucking function
10361050bool IGFD::FilterManager::GetFileStyle (const IGFD_FileStyleFlags& vFlags, const std::string& vCriteria, ImVec4* vOutColor, std::string* vOutIcon, ImFont** vOutFont) {
10371051 if (vOutColor) {
10381052 if (!prFilesStyle.empty ()) {
1039- if (prFilesStyle.find (vFlags) != prFilesStyle.end ()) // found
1040- {
1053+ if (prFilesStyle.find (vFlags) != prFilesStyle.end ()) { // found
10411054 if (vFlags & IGFD_FileStyleByContainedInFullName) {
10421055 // search for vCriteria who are containing the criteria
10431056 for (const auto & _file : prFilesStyle.at (vFlags)) {
@@ -1051,8 +1064,7 @@ bool IGFD::FilterManager::GetFileStyle(const IGFD_FileStyleFlags& vFlags, const
10511064 }
10521065 }
10531066 } else {
1054- if (prFilesStyle.at (vFlags).find (vCriteria) != prFilesStyle.at (vFlags).end ()) // found
1055- {
1067+ if (prFilesStyle.at (vFlags).find (vCriteria) != prFilesStyle.at (vFlags).end ()) { // found
10561068 *vOutColor = prFilesStyle[vFlags][vCriteria]->color ;
10571069 if (vOutIcon) *vOutIcon = prFilesStyle[vFlags][vCriteria]->icon ;
10581070 if (vOutFont) *vOutFont = prFilesStyle[vFlags][vCriteria]->font ;
@@ -1076,8 +1088,7 @@ bool IGFD::FilterManager::GetFileStyle(const IGFD_FileStyleFlags& vFlags, const
10761088 }
10771089 }
10781090 } else {
1079- if (prFilesStyle.at (_flag.first ).find (vCriteria) != prFilesStyle.at (_flag.first ).end ()) // found
1080- {
1091+ if (prFilesStyle.at (_flag.first ).find (vCriteria) != prFilesStyle.at (_flag.first ).end ()) { // found
10811092 *vOutColor = prFilesStyle[_flag.first ][vCriteria]->color ;
10821093 if (vOutIcon) *vOutIcon = prFilesStyle[_flag.first ][vCriteria]->icon ;
10831094 if (vOutFont) *vOutFont = prFilesStyle[_flag.first ][vCriteria]->font ;
@@ -1105,13 +1116,11 @@ bool IGFD::FilterManager::IsCoveredByFilters(const std::string& vNameExt, const
11051116 return false ;
11061117}
11071118
1119+ // combobox of filters
11081120bool IGFD::FilterManager::DrawFilterComboBox (FileDialogInternal& vFileDialogInternal) {
1109- // combobox of filters
11101121 if (!puDLGFilters.empty ()) {
11111122 ImGui::SameLine ();
1112-
11131123 bool needToApllyNewFilter = false ;
1114-
11151124 ImGui::PushItemWidth (FILTER_COMBO_WIDTH);
11161125 if (IMGUI_BEGIN_COMBO (" ##Filters" , prSelectedFilter.filter .c_str (), ImGuiComboFlags_None)) {
11171126 intptr_t i = 0 ;
@@ -1124,41 +1133,35 @@ bool IGFD::FilterManager::DrawFilterComboBox(FileDialogInternal& vFileDialogInte
11241133 }
11251134 ImGui::PopID ();
11261135 }
1127-
11281136 ImGui::EndCombo ();
11291137 }
11301138 ImGui::PopItemWidth ();
1131-
11321139 if (needToApllyNewFilter) { vFileDialogInternal.puFileManager .OpenCurrentPath (vFileDialogInternal); }
1133-
11341140 return needToApllyNewFilter;
11351141 }
1136-
11371142 return false ;
11381143}
11391144
11401145IGFD::FilterManager::FilterInfos IGFD::FilterManager::GetSelectedFilter () { return prSelectedFilter; }
11411146
11421147std::string IGFD::FilterManager::ReplaceExtentionWithCurrentFilter (const std::string& vFile) const {
11431148 auto result = vFile;
1144-
11451149 if (!result.empty ()) {
11461150 // if not a collection we can replace the filter by the extention we want
11471151 if (prSelectedFilter.collectionfilters .empty () && prSelectedFilter.filter != " .*" && prSelectedFilter.filter != " *.*" ) {
11481152 size_t lastPoint = vFile.find_last_of (' .' );
11491153 if (lastPoint != std::string::npos) { result = result.substr (0 , lastPoint); }
1150-
11511154 result += prSelectedFilter.filter ;
11521155 }
11531156 }
1154-
11551157 return result;
11561158}
11571159
11581160void IGFD::FilterManager::SetDefaultFilterIfNotDefined () {
11591161 if (prSelectedFilter.empty () && // no filter selected
1160- !prParsedFilters.empty ()) // filter exist
1162+ !prParsedFilters.empty ()) { // filter exist
11611163 prSelectedFilter = *prParsedFilters.begin (); // we take the first filter
1164+ }
11621165}
11631166
11641167// ///////////////////////////////////////////////////////////////////////////////////
@@ -1171,10 +1174,11 @@ void IGFD::FileManager::OpenCurrentPath(const FileDialogInternal& vFileDialogInt
11711174 puShowDrives = false ;
11721175 ClearComposer ();
11731176 ClearFileLists ();
1174- if (puDLGDirectoryMode) // directory mode
1177+ if (puDLGDirectoryMode) { // directory mode
11751178 SetDefaultFileName (" ." );
1176- else
1179+ } else {
11771180 SetDefaultFileName (puDLGDefaultFileName);
1181+ }
11781182 ScanDir (vFileDialogInternal, GetCurrentPath ());
11791183}
11801184
@@ -1190,16 +1194,14 @@ void IGFD::FileManager::SortFields(const FileDialogInternal& vFileDialogInternal
11901194 puHeaderFileThumbnails = tableHeaderFileThumbnailsString;
11911195#endif // #ifdef USE_THUMBNAILS
11921196 }
1193-
11941197 if (puSortingField == SortingFieldEnum::FIELD_FILENAME) {
11951198 if (puSortingDirection[0 ]) {
11961199#ifdef USE_CUSTOM_SORTING_ICON
11971200 puHeaderFileName = tableHeaderAscendingIcon + puHeaderFileName;
11981201#endif // USE_CUSTOM_SORTING_ICON
11991202 std::sort (vFileInfosList.begin (), vFileInfosList.end (), [](const std::shared_ptr<FileInfos>& a, const std::shared_ptr<FileInfos>& b) -> bool {
12001203 if (!a.use_count () || !b.use_count ()) return false ;
1201-
1202- // this code fail in c:\\Users with the link "All users". got a invalid comparator
1204+ // tofix : this code fail in c:\\Users with the link "All users". got a invalid comparator
12031205 /*
12041206 // use code from https://github.com/jackm97/ImGuiFileDialog/commit/bf40515f5a1de3043e60562dc1a494ee7ecd3571
12051207 // strict ordering for file/directory types beginning in '.'
@@ -1222,8 +1224,7 @@ void IGFD::FileManager::SortFields(const FileDialogInternal& vFileDialogInternal
12221224#endif // USE_CUSTOM_SORTING_ICON
12231225 std::sort (vFileInfosList.begin (), vFileInfosList.end (), [](const std::shared_ptr<FileInfos>& a, const std::shared_ptr<FileInfos>& b) -> bool {
12241226 if (!a.use_count () || !b.use_count ()) return false ;
1225-
1226- // this code fail in c:\\Users with the link "All users". got a invalid comparator
1227+ // tofix : this code fail in c:\\Users with the link "All users". got a invalid comparator
12271228 /*
12281229 // use code from https://github.com/jackm97/ImGuiFileDialog/commit/bf40515f5a1de3043e60562dc1a494ee7ecd3571
12291230 // strict ordering for file/directory types beginning in '.'
@@ -1248,7 +1249,6 @@ void IGFD::FileManager::SortFields(const FileDialogInternal& vFileDialogInternal
12481249#endif // USE_CUSTOM_SORTING_ICON
12491250 std::sort (vFileInfosList.begin (), vFileInfosList.end (), [](const std::shared_ptr<FileInfos>& a, const std::shared_ptr<FileInfos>& b) -> bool {
12501251 if (!a.use_count () || !b.use_count ()) return false ;
1251-
12521252 if (a->fileType != b->fileType ) return (a->fileType < b->fileType ); // directory in first
12531253 return (a->fileExt < b->fileExt ); // else
12541254 });
@@ -1258,7 +1258,6 @@ void IGFD::FileManager::SortFields(const FileDialogInternal& vFileDialogInternal
12581258#endif // USE_CUSTOM_SORTING_ICON
12591259 std::sort (vFileInfosList.begin (), vFileInfosList.end (), [](const std::shared_ptr<FileInfos>& a, const std::shared_ptr<FileInfos>& b) -> bool {
12601260 if (!a.use_count () || !b.use_count ()) return false ;
1261-
12621261 if (a->fileType != b->fileType ) return (a->fileType > b->fileType ); // directory in last
12631262 return (a->fileExt > b->fileExt ); // else
12641263 });
@@ -1270,7 +1269,6 @@ void IGFD::FileManager::SortFields(const FileDialogInternal& vFileDialogInternal
12701269#endif // USE_CUSTOM_SORTING_ICON
12711270 std::sort (vFileInfosList.begin (), vFileInfosList.end (), [](const std::shared_ptr<FileInfos>& a, const std::shared_ptr<FileInfos>& b) -> bool {
12721271 if (!a.use_count () || !b.use_count ()) return false ;
1273-
12741272 if (a->fileType != b->fileType ) return (a->fileType < b->fileType ); // directory in first
12751273 return (a->fileSize < b->fileSize ); // else
12761274 });
@@ -1280,7 +1278,6 @@ void IGFD::FileManager::SortFields(const FileDialogInternal& vFileDialogInternal
12801278#endif // USE_CUSTOM_SORTING_ICON
12811279 std::sort (vFileInfosList.begin (), vFileInfosList.end (), [](const std::shared_ptr<FileInfos>& a, const std::shared_ptr<FileInfos>& b) -> bool {
12821280 if (!a.use_count () || !b.use_count ()) return false ;
1283-
12841281 if (a->fileType != b->fileType ) return (a->fileType > b->fileType ); // directory in last
12851282 return (a->fileSize > b->fileSize ); // else
12861283 });
@@ -1292,7 +1289,6 @@ void IGFD::FileManager::SortFields(const FileDialogInternal& vFileDialogInternal
12921289#endif // USE_CUSTOM_SORTING_ICON
12931290 std::sort (vFileInfosList.begin (), vFileInfosList.end (), [](const std::shared_ptr<FileInfos>& a, const std::shared_ptr<FileInfos>& b) -> bool {
12941291 if (!a.use_count () || !b.use_count ()) return false ;
1295-
12961292 if (a->fileType != b->fileType ) return (a->fileType < b->fileType ); // directory in first
12971293 return (a->fileModifDate < b->fileModifDate ); // else
12981294 });
@@ -1302,7 +1298,6 @@ void IGFD::FileManager::SortFields(const FileDialogInternal& vFileDialogInternal
13021298#endif // USE_CUSTOM_SORTING_ICON
13031299 std::sort (vFileInfosList.begin (), vFileInfosList.end (), [](const std::shared_ptr<FileInfos>& a, const std::shared_ptr<FileInfos>& b) -> bool {
13041300 if (!a.use_count () || !b.use_count ()) return false ;
1305-
13061301 if (a->fileType != b->fileType ) return (a->fileType > b->fileType ); // directory in last
13071302 return (a->fileModifDate > b->fileModifDate ); // else
13081303 });
@@ -1320,7 +1315,6 @@ void IGFD::FileManager::SortFields(const FileDialogInternal& vFileDialogInternal
13201315#endif // USE_CUSTOM_SORTING_ICON
13211316 std::sort (vFileInfosList.begin (), vFileInfosList.end (), [](const std::shared_ptr<FileInfos>& a, const std::shared_ptr<FileInfos>& b) -> bool {
13221317 if (!a.use_count () || !b.use_count ()) return false ;
1323-
13241318 if (a->fileType != b->fileType ) return (a->fileType .isDir ()); // directory in first
13251319 if (a->thumbnailInfo .textureWidth == b->thumbnailInfo .textureWidth ) return (a->thumbnailInfo .textureHeight < b->thumbnailInfo .textureHeight );
13261320 return (a->thumbnailInfo .textureWidth < b->thumbnailInfo .textureWidth );
@@ -1333,7 +1327,6 @@ void IGFD::FileManager::SortFields(const FileDialogInternal& vFileDialogInternal
13331327#endif // USE_CUSTOM_SORTING_ICON
13341328 std::sort (vFileInfosList.begin (), vFileInfosList.end (), [](const std::shared_ptr<FileInfos>& a, const std::shared_ptr<FileInfos>& b) -> bool {
13351329 if (!a.use_count () || !b.use_count ()) return false ;
1336-
13371330 if (a->fileType != b->fileType ) return (!a->fileType .isDir ()); // directory in last
13381331 if (a->thumbnailInfo .textureWidth == b->thumbnailInfo .textureWidth ) return (a->thumbnailInfo .textureHeight > b->thumbnailInfo .textureHeight );
13391332 return (a->thumbnailInfo .textureWidth > b->thumbnailInfo .textureWidth );
@@ -1368,8 +1361,7 @@ void IGFD::FileManager::AddFile(const FileDialogInternal& vFileDialogInternal, c
13681361 if (!vFileDialogInternal.puFilterManager .puDLGFilters .empty () || (vFileDialogInternal.puFilterManager .puDLGFilters .empty () && infos->fileNameExt != " ." )) // except "." if in directory mode //-V728
13691362 return ;
13701363
1371- if (infos->fileType .isFile () || infos->fileType .isLinkToUnknown ()) // link can have the same extention of a file
1372- {
1364+ if (infos->fileType .isFile () || infos->fileType .isLinkToUnknown ()) { // link can have the same extention of a file
13731365 size_t lpt = infos->fileNameExt .find_last_of (' .' );
13741366 if (lpt != std::string::npos) { infos->fileExt = infos->fileNameExt .substr (lpt); }
13751367
@@ -1397,8 +1389,7 @@ void IGFD::FileManager::AddPath(const FileDialogInternal& vFileDialogInternal, c
13971389 if (!vFileDialogInternal.puFilterManager .puDLGFilters .empty () || (vFileDialogInternal.puFilterManager .puDLGFilters .empty () && infos->fileNameExt != " ." )) // except "." if in directory mode //-V728
13981390 return ;
13991391
1400- if (infos->fileType .isFile () || infos->fileType .isLinkToUnknown ()) // link can have the same extention of a file
1401- {
1392+ if (infos->fileType .isFile () || infos->fileType .isLinkToUnknown ()) { // link can have the same extention of a file
14021393 size_t lpt = infos->fileNameExt .find_last_of (' .' );
14031394 if (lpt != std::string::npos) { infos->fileExt = infos->fileNameExt .substr (lpt); }
14041395
@@ -4024,6 +4015,10 @@ void IGFD::FileDialog::SetFileStyle(const IGFD_FileStyleFlags& vFlags, const cha
40244015 prFileDialogInternal.puFilterManager .SetFileStyle (vFlags, vCriteria, vColor, vIcon, vFont);
40254016}
40264017
4018+ void IGFD::FileDialog::SetFileStyle (FileStyle::FileStyleFunctor vFunctor) {
4019+ prFileDialogInternal.puFilterManager .SetFileStyle (vFunctor);
4020+ }
4021+
40274022bool IGFD::FileDialog::GetFileStyle (const IGFD_FileStyleFlags& vFlags, const std::string& vCriteria, ImVec4* vOutColor, std::string* vOutIcon, ImFont** vOutFont) {
40284023 return prFileDialogInternal.puFilterManager .GetFileStyle (vFlags, vCriteria, vOutColor, vOutIcon, vOutFont);
40294024}
0 commit comments