@@ -322,21 +322,22 @@ namespace IGFD
322322
323323 IGFD::FileStyle::FileStyle () : color(0 , 0 , 0 , 0 )
324324 {
325- prEmpty = true ;
325+
326+ }
327+
328+ IGFD::FileStyle::FileStyle (const FileStyle& vStyle)
329+ {
330+ color = vStyle.color ;
331+ icon = vStyle.icon ;
332+ font = vStyle.font ;
333+ flags = vStyle.flags ;
326334 }
327335
328336 IGFD::FileStyle::FileStyle (const ImVec4& vColor, const std::string& vIcon, ImFont* vFont)
329337 {
330338 color = vColor;
331339 icon = vIcon;
332340 font = vFont;
333-
334- prEmpty = false ;
335- }
336-
337- bool IGFD::FileStyle::empty () const
338- {
339- return prEmpty;
340341 }
341342
342343 // ///////////////////////////////////////////////////////////////////////////////////
@@ -827,83 +828,164 @@ namespace IGFD
827828 }
828829 }
829830
830- void IGFD::FilterManager::SetFileStyle (const IGFD_FileStyleFlags& vFlags, const std::string& vCriteria, const FileStyle& vInfos)
831+ void IGFD::FilterManager::SetFileStyle (const IGFD_FileStyleFlags& vFlags, const char * vCriteria, const FileStyle& vInfos)
831832 {
832- prFilesStyle[vFlags][vCriteria] = vInfos;
833- prFilesStyle[vFlags][vCriteria].flags = vFlags;
833+ std::string _criteria;
834+ if (vCriteria)
835+ _criteria = std::string (vCriteria);
836+ prFilesStyle[vFlags][_criteria] = std::make_shared<FileStyle>(vInfos);
837+ prFilesStyle[vFlags][_criteria]->flags = vFlags;
834838 }
835839
836- // todo : to refactor this fucking function
837- bool IGFD::FilterManager::GetFileStyle (
838- const IGFD_FileStyleFlags& vFlags,
839- const std::string& vCriteria,
840- FileStyle& vFileStyle) const
840+ // will be called internally
841+ // will not been exposed to IGFD API
842+ bool IGFD::FilterManager::prFillFileStyle (std::shared_ptr<FileInfos> vFileInfos) const
841843 {
842- if (!prFilesStyle.empty ())
844+ if (vFileInfos. use_count () && !prFilesStyle.empty ())
843845 {
844- if (prFilesStyle. find (vFlags) != prFilesStyle. end ()) // found
846+ for ( const auto & _flag : prFilesStyle)
845847 {
846- if (vFlags & IGFD_FileStyleByContainedInFullName )
848+ for ( const auto & _file : _flag. second )
847849 {
848- // search for vCriteria who are containing the criteria
849- const auto & _files = prFilesStyle.at (vFlags);
850- for (const auto & _file : _files)
850+ if (_flag.first & IGFD_FileStyleByTypeDir && vFileInfos->fileType == ' d' )
851851 {
852- if (vCriteria. find ( _file.first ) != std::string::npos)
852+ if (_file.first . empty ()) // for all dirs
853853 {
854- vFileStyle = prFilesStyle.at (vFlags).at (_file.first );
855- return true ;
854+ vFileInfos->fileStyle = _file.second ;
855+ }
856+ else if (_file.first == vFileInfos->fileNameExt ) // for dirs who are equal to style criteria
857+ {
858+ vFileInfos->fileStyle = _file.second ;
856859 }
857860 }
858- }
859- else
860- {
861- if (prFilesStyle.at (vFlags).find (vCriteria) != prFilesStyle.at (vFlags).end ()) // found
861+ else if (_flag.first & IGFD_FileStyleByTypeFile && vFileInfos->fileType == ' f' )
862862 {
863- vFileStyle = prFilesStyle.at (vFlags).at (vCriteria);
864- return true ;
863+ if (_file.first .empty ()) // for all files
864+ {
865+ vFileInfos->fileStyle = _file.second ;
866+ }
867+ else if (_file.first == vFileInfos->fileNameExt ) // for files who are equal to style criteria
868+ {
869+ vFileInfos->fileStyle = _file.second ;
870+ }
865871 }
866- }
867- }
868- else
869- {
870- // search for flag composition
871- for (const auto & _flag : prFilesStyle)
872- {
873- if (_flag.first & vFlags)
872+ else if (_flag.first & IGFD_FileStyleByTypeLink && vFileInfos->fileType == ' l' )
873+ {
874+ if (_file.first .empty ()) // for all links
875+ {
876+ vFileInfos->fileStyle = _file.second ;
877+ }
878+ else if (_file.first == vFileInfos->fileNameExt ) // for links who are equal to style criteria
879+ {
880+ vFileInfos->fileStyle = _file.second ;
881+ }
882+ }
883+
884+ if (_flag.first & IGFD_FileStyleByExtention)
874885 {
875- if (_flag.first & IGFD_FileStyleByContainedInFullName)
886+ if (_file.first == vFileInfos->fileExt )
887+ {
888+ vFileInfos->fileStyle = _file.second ;
889+ }
890+
891+ // can make sense for some dirs like the hidden by ex ".git"
892+ if (_flag.first & IGFD_FileStyleByTypeDir && vFileInfos->fileType == ' d' )
876893 {
877- // search for vCriteria who are containing the criteria
878- for (const auto & _file : _flag.second )
894+ if (_file.first == vFileInfos->fileExt )
879895 {
880- if (vCriteria.find (_file.first ) != std::string::npos)
881- {
882- vFileStyle = prFilesStyle.at (_flag.first ).at (_file.first );
883- return true ;
884- }
896+ vFileInfos->fileStyle = _file.second ;
885897 }
886898 }
887- else
899+ else if (_flag.first & IGFD_FileStyleByTypeFile && vFileInfos->fileType == ' f' )
900+ {
901+ if (_file.first == vFileInfos->fileExt )
902+ {
903+ vFileInfos->fileStyle = _file.second ;
904+ }
905+ }
906+ else if (_flag.first & IGFD_FileStyleByTypeLink && vFileInfos->fileType == ' l' )
888907 {
889- if (prFilesStyle. at (_flag. first ). find (vCriteria) != prFilesStyle. at (_flag. first ). end ()) // found
908+ if (_file. first == vFileInfos-> fileExt )
890909 {
891- vFileStyle = prFilesStyle.at (_flag.first ).at (vCriteria);
892- return true ;
910+ vFileInfos->fileStyle = _file.second ;
893911 }
894912 }
895913 }
914+ if (_flag.first & IGFD_FileStyleByFullName)
915+ {
916+ if (_file.first == vFileInfos->fileNameExt )
917+ {
918+ vFileInfos->fileStyle = _file.second ;
919+ }
920+
921+ if (_flag.first & IGFD_FileStyleByTypeDir && vFileInfos->fileType == ' d' )
922+ {
923+ if (_file.first == vFileInfos->fileNameExt )
924+ {
925+ vFileInfos->fileStyle = _file.second ;
926+ }
927+ }
928+ else if (_flag.first & IGFD_FileStyleByTypeFile && vFileInfos->fileType == ' f' )
929+ {
930+ if (_file.first == vFileInfos->fileNameExt )
931+ {
932+ vFileInfos->fileStyle = _file.second ;
933+ }
934+ }
935+ else if (_flag.first & IGFD_FileStyleByTypeLink && vFileInfos->fileType == ' l' )
936+ {
937+ if (_file.first == vFileInfos->fileNameExt )
938+ {
939+ vFileInfos->fileStyle = _file.second ;
940+ }
941+ }
942+ }
943+ if (_flag.first & IGFD_FileStyleByContainedInFullName)
944+ {
945+ if (vFileInfos->fileNameExt .find (_file.first ) != std::string::npos)
946+ {
947+ vFileInfos->fileStyle = _file.second ;
948+ }
949+
950+ if (_flag.first & IGFD_FileStyleByTypeDir && vFileInfos->fileType == ' d' )
951+ {
952+ if (vFileInfos->fileNameExt .find (_file.first ) != std::string::npos)
953+ {
954+ vFileInfos->fileStyle = _file.second ;
955+ }
956+ }
957+ else if (_flag.first & IGFD_FileStyleByTypeFile && vFileInfos->fileType == ' f' )
958+ {
959+ if (vFileInfos->fileNameExt .find (_file.first ) != std::string::npos)
960+ {
961+ vFileInfos->fileStyle = _file.second ;
962+ }
963+ }
964+ else if (_flag.first & IGFD_FileStyleByTypeLink && vFileInfos->fileType == ' l' )
965+ {
966+ if (vFileInfos->fileNameExt .find (_file.first ) != std::string::npos)
967+ {
968+ vFileInfos->fileStyle = _file.second ;
969+ }
970+ }
971+ }
972+
973+ if (vFileInfos->fileStyle .use_count ())
974+ return true ;
896975 }
897976 }
898977 }
899978
900979 return false ;
901980 }
902981
903- void IGFD::FilterManager::SetFileStyle (const IGFD_FileStyleFlags& vFlags, const std::string& vCriteria, const ImVec4& vColor, const std::string& vIcon, ImFont* vFont)
982+ void IGFD::FilterManager::SetFileStyle (const IGFD_FileStyleFlags& vFlags, const char * vCriteria, const ImVec4& vColor, const std::string& vIcon, ImFont* vFont)
904983 {
905- prFilesStyle[vFlags][vCriteria] = FileStyle (vColor, vIcon, vFont);
906- prFilesStyle[vFlags][vCriteria].flags = vFlags;
984+ std::string _criteria;
985+ if (vCriteria)
986+ _criteria = std::string (vCriteria);
987+ prFilesStyle[vFlags][_criteria] = std::make_shared<FileStyle>(vColor, vIcon, vFont);
988+ prFilesStyle[vFlags][_criteria]->flags = vFlags;
907989 }
908990
909991 // todo : to refactor this fucking function
@@ -922,24 +1004,27 @@ namespace IGFD
9221004 {
9231005 if (vCriteria.find (_file.first ) != std::string::npos)
9241006 {
925- *vOutColor = prFilesStyle[vFlags][_file.first ].color ;
926- if (vOutIcon)
927- *vOutIcon = prFilesStyle[vFlags][_file.first ].icon ;
928- if (vOutFont)
929- *vOutFont = prFilesStyle[vFlags][_file.first ].font ;
930- return true ;
1007+ if (_file.second .use_count ())
1008+ {
1009+ *vOutColor = _file.second ->color ;
1010+ if (vOutIcon)
1011+ *vOutIcon = _file.second ->icon ;
1012+ if (vOutFont)
1013+ *vOutFont = _file.second ->font ;
1014+ return true ;
1015+ }
9311016 }
9321017 }
9331018 }
9341019 else
9351020 {
9361021 if (prFilesStyle.at (vFlags).find (vCriteria) != prFilesStyle.at (vFlags).end ()) // found
9371022 {
938- *vOutColor = prFilesStyle[vFlags][vCriteria]. color ;
1023+ *vOutColor = prFilesStyle[vFlags][vCriteria]-> color ;
9391024 if (vOutIcon)
940- *vOutIcon = prFilesStyle[vFlags][vCriteria]. icon ;
1025+ *vOutIcon = prFilesStyle[vFlags][vCriteria]-> icon ;
9411026 if (vOutFont)
942- *vOutFont = prFilesStyle[vFlags][vCriteria]. font ;
1027+ *vOutFont = prFilesStyle[vFlags][vCriteria]-> font ;
9431028 return true ;
9441029 }
9451030 }
@@ -958,24 +1043,27 @@ namespace IGFD
9581043 {
9591044 if (vCriteria.find (_file.first ) != std::string::npos)
9601045 {
961- *vOutColor = prFilesStyle[vFlags][_file.first ].color ;
962- if (vOutIcon)
963- *vOutIcon = prFilesStyle[vFlags][_file.first ].icon ;
964- if (vOutFont)
965- *vOutFont = prFilesStyle[vFlags][_file.first ].font ;
966- return true ;
1046+ if (_file.second .use_count ())
1047+ {
1048+ *vOutColor = _file.second ->color ;
1049+ if (vOutIcon)
1050+ *vOutIcon = _file.second ->icon ;
1051+ if (vOutFont)
1052+ *vOutFont = _file.second ->font ;
1053+ return true ;
1054+ }
9671055 }
9681056 }
9691057 }
9701058 else
9711059 {
9721060 if (prFilesStyle.at (_flag.first ).find (vCriteria) != prFilesStyle.at (_flag.first ).end ()) // found
9731061 {
974- *vOutColor = prFilesStyle[vFlags ][vCriteria]. color ;
1062+ *vOutColor = prFilesStyle[_flag. first ][vCriteria]-> color ;
9751063 if (vOutIcon)
976- *vOutIcon = prFilesStyle[vFlags ][vCriteria]. icon ;
1064+ *vOutIcon = prFilesStyle[_flag. first ][vCriteria]-> icon ;
9771065 if (vOutFont)
978- *vOutFont = prFilesStyle[vFlags ][vCriteria]. font ;
1066+ *vOutFont = prFilesStyle[_flag. first ][vCriteria]-> font ;
9791067 return true ;
9801068 }
9811069 }
@@ -1367,28 +1455,6 @@ namespace IGFD
13671455 infos->fileNameExt_optimized = prOptimizeFilenameForSearchOperations (infos->fileNameExt );
13681456 infos->fileType = vFileType;
13691457
1370- // file style
1371-
1372- static std::string emptyString;
1373-
1374- if (infos->fileType == ' d' )
1375- vFileDialogInternal.puFilterManager .GetFileStyle (IGFD_FileStyleByTypeDir, emptyString, infos->fileStyle );
1376- else if (infos->fileType == ' f' )
1377- vFileDialogInternal.puFilterManager .GetFileStyle (IGFD_FileStyleByTypeFile, emptyString, infos->fileStyle );
1378- else if (infos->fileType == ' l' )
1379- vFileDialogInternal.puFilterManager .GetFileStyle (IGFD_FileStyleByTypeLink, emptyString, infos->fileStyle );
1380-
1381- vFileDialogInternal.puFilterManager .GetFileStyle (IGFD_FileStyleByExtention, infos->fileExt , infos->fileStyle );
1382- vFileDialogInternal.puFilterManager .GetFileStyle (IGFD_FileStyleByFullName, infos->fileNameExt , infos->fileStyle );
1383- vFileDialogInternal.puFilterManager .GetFileStyle (IGFD_FileStyleByContainedInFullName, infos->fileNameExt , infos->fileStyle );
1384-
1385- if (infos->fileType == ' d' )
1386- vFileDialogInternal.puFilterManager .GetFileStyle (IGFD_FileStyleByTypeDir | IGFD_FileStyleByContainedInFullName, infos->fileNameExt , infos->fileStyle );
1387- else if (infos->fileType == ' f' )
1388- vFileDialogInternal.puFilterManager .GetFileStyle (IGFD_FileStyleByTypeFile | IGFD_FileStyleByContainedInFullName, infos->fileNameExt , infos->fileStyle );
1389- else if (infos->fileType == ' l' )
1390- vFileDialogInternal.puFilterManager .GetFileStyle (IGFD_FileStyleByTypeLink | IGFD_FileStyleByContainedInFullName, infos->fileNameExt , infos->fileStyle );
1391-
13921458 if (infos->fileNameExt .empty () || (infos->fileNameExt == " ." && !vFileDialogInternal.puFilterManager .puDLGFilters .empty ())) return ; // filename empty or filename is the current dir '.'
13931459 if (infos->fileNameExt != " .." && (vFileDialogInternal.puDLGflags & ImGuiFileDialogFlags_DontShowHiddenFiles) && infos->fileNameExt [0 ] == ' .' ) // dont show hidden files
13941460 if (!vFileDialogInternal.puFilterManager .puDLGFilters .empty () || (vFileDialogInternal.puFilterManager .puDLGFilters .empty () && infos->fileNameExt != " ." )) // except "." if in directory mode
@@ -1409,6 +1475,8 @@ namespace IGFD
14091475 }
14101476 }
14111477
1478+ vFileDialogInternal.puFilterManager .prFillFileStyle (infos);
1479+
14121480 prCompleteFileInfos (infos);
14131481 prFileList.push_back (infos);
14141482 }
@@ -3842,21 +3910,22 @@ namespace IGFD
38423910 vOutStr.clear ();
38433911 vOutShowColor = false ;
38443912
3845- // Directory and Link infos override the one specified by extension
3846-
3847- vOutShowColor = !vFileInfos-> fileStyle . empty () ;
3913+ if (vFileInfos-> fileStyle . use_count ())
3914+ {
3915+ vOutShowColor = true ;
38483916
3849- *vOutFont = vFileInfos->fileStyle .font ;
3917+ *vOutFont = vFileInfos->fileStyle ->font ;
3918+ }
38503919
3851- if (vOutShowColor && !vFileInfos->fileStyle . icon .empty ()) vOutStr = vFileInfos->fileStyle . icon ;
3920+ if (vOutShowColor && !vFileInfos->fileStyle -> icon .empty ()) vOutStr = vFileInfos->fileStyle -> icon ;
38523921 else if (vFileInfos->fileType == ' d' ) vOutStr = dirEntryString;
38533922 else if (vFileInfos->fileType == ' l' ) vOutStr = linkEntryString;
38543923 else if (vFileInfos->fileType == ' f' ) vOutStr = fileEntryString;
38553924
38563925 vOutStr += " " + vFileInfos->fileNameExt ;
38573926
38583927 if (vOutShowColor)
3859- ImGui::PushStyleColor (ImGuiCol_Text, vFileInfos->fileStyle . color );
3928+ ImGui::PushStyleColor (ImGuiCol_Text, vFileInfos->fileStyle -> color );
38603929 if (*vOutFont)
38613930 ImGui::PushFont (*vOutFont);
38623931 }
@@ -4287,12 +4356,12 @@ namespace IGFD
42874356 return prFileDialogInternal.puIsOk ;
42884357 }
42894358
4290- void IGFD::FileDialog::SetFileStyle (const IGFD_FileStyleFlags& vFlags, const std::string& vCriteria, const FileStyle& vInfos)
4359+ void IGFD::FileDialog::SetFileStyle (const IGFD_FileStyleFlags& vFlags, const char * vCriteria, const FileStyle& vInfos)
42914360 {
42924361 prFileDialogInternal.puFilterManager .SetFileStyle (vFlags, vCriteria, vInfos);
42934362 }
42944363
4295- void IGFD::FileDialog::SetFileStyle (const IGFD_FileStyleFlags& vFlags, const std::string& vCriteria, const ImVec4& vColor, const std::string& vIcon, ImFont* vFont)
4364+ void IGFD::FileDialog::SetFileStyle (const IGFD_FileStyleFlags& vFlags, const char * vCriteria, const ImVec4& vColor, const std::string& vIcon, ImFont* vFont)
42964365 {
42974366 prFileDialogInternal.puFilterManager .SetFileStyle (vFlags, vCriteria, vColor, vIcon, vFont);
42984367 }
0 commit comments