@@ -837,6 +837,27 @@ bool IGFD::Utils::ReplaceString(std::string& str, const ::std::string& oldStr, c
837837 return false ;
838838}
839839
840+ std::vector<std::string> IGFD::Utils::SplitStringToVector (const std::string& vText, const std::string& vDelimiterPattern, const bool & vPushEmpty) {
841+ std::vector<std::string> arr;
842+ if (!vText.empty ()) {
843+ size_t start = 0 ;
844+ size_t end = vText.find (vDelimiterPattern, start);
845+ while (end != std::string::npos) {
846+ auto token = vText.substr (start, end - start);
847+ if (!token.empty () || (token.empty () && vPushEmpty)) { // -V728
848+ arr.push_back (token);
849+ }
850+ start = end + vDelimiterPattern.size ();
851+ end = vText.find (vDelimiterPattern, start);
852+ }
853+ auto token = vText.substr (start);
854+ if (!token.empty () || (token.empty () && vPushEmpty)) { // -V728
855+ arr.push_back (token);
856+ }
857+ }
858+ return arr;
859+ }
860+
840861std::vector<std::string> IGFD::Utils::SplitStringToVector (const std::string& vText, const char & vDelimiter, const bool & vPushEmpty) {
841862 std::vector<std::string> arr;
842863 if (!vText.empty ()) {
@@ -3071,45 +3092,52 @@ bool IGFD::PlacesFeature::m_DrawPlacesPane(FileDialogInternal& vFileDialogIntern
30713092}
30723093
30733094std::string IGFD::PlacesFeature::SerializePlaces (const bool & vForceSerialisationForAll) {
3074- // todo : do the code
30753095 std::string res;
3076- /* size_t idx = 0;
3077- for (auto& it : m_Groups) {
3078- if (vForceSerialisationForAll && it.canBeSaved) continue;
3079- if (idx++ != 0) res += "##"; // ## because reserved by imgui, so an input text cant have ##
3080- res += it.name + "##" + it.path;
3081- }*/
3096+ size_t idx = 0 ;
3097+ for (const auto & group : m_Groups) {
3098+ if (group.second ->canBeSaved ) {
3099+ // ## is used because reserved by imgui, so an input text cannot have ##
3100+ res += " ###" + group.first + " ###" ;
3101+ for (const auto & place : group.second ->places ) {
3102+ if (place.canBeSaved ) {
3103+ if (idx++ != 0 ) res += " ##" ;
3104+ res += place.name + " ##" + place.path ;
3105+ }
3106+ }
3107+ }
3108+ }
30823109 return res;
30833110}
30843111
30853112void IGFD::PlacesFeature::DeserializePlaces (const std::string& vPlaces) {
3086- // todo : do the code
3087- /* if (!vPlaces.empty()) {
3088- m_Groups.clear();
3089- auto arr = IGFD::Utils::SplitStringToVector(vPlaces, '#', false);
3090- for (size_t i = 0; i < arr.size(); i += 2) {
3091- if (i + 1 < arr.size()) { // for avoid crash if arr size is impair due to user mistake after edition
3092- PlaceStruct place;
3093- place.name = arr[i];
3094- // if bad format we jump this place
3095- place.path = arr[i + 1];
3096- m_Bookmarks.push_back(place);
3113+ if (!vPlaces.empty ()) {
3114+ const auto & groups = IGFD::Utils::SplitStringToVector (vPlaces, " ###" , false );
3115+ if (groups.size () > 1 ) {
3116+ for (size_t i = 0 ; i < groups.size (); i += 2 ) {
3117+ auto group_ptr = GetPlacesGroupPtr (groups[i]);
3118+ if (group_ptr != nullptr ) {
3119+ const auto & places = IGFD::Utils::SplitStringToVector (groups[i + 1 ], " ##" , false );
3120+ if (places.size () > 1 ) {
3121+ for (size_t j = 0 ; j < places.size (); j += 2 ) {
3122+ group_ptr->AddPlace (places[j], places[j + 1 ], true ); // was saved so we set canBeSaved to true
3123+ }
3124+ }
3125+ }
30973126 }
30983127 }
3099- }*/
3128+ }
31003129}
31013130
31023131bool IGFD::PlacesFeature::AddPlacesGroup (const std::string& vGroupName, const size_t & vDisplayOrder, const bool & vCanBeEdited) {
31033132 if (vGroupName.empty ()) {
31043133 return false ;
31053134 }
3106- auto group_ptr = std::make_shared<GroupStruct>();
3107- group_ptr->displayOrder = vDisplayOrder;
3135+ auto group_ptr = std::make_shared<GroupStruct>();
3136+ group_ptr->displayOrder = vDisplayOrder;
31083137 group_ptr->name = vGroupName;
3109- group_ptr->canBeEdited = vCanBeEdited;
3138+ group_ptr->canBeSaved = group_ptr-> canBeEdited = vCanBeEdited; // can be user edited mean can be saved
31103139 m_Groups[vGroupName] = group_ptr;
3111- // tofix the set of existing order number
3112- m_OrderedGroups[group_ptr->displayOrder ] = group_ptr;
3140+ m_OrderedGroups[group_ptr->displayOrder ] = group_ptr; // an exisitng display order will be overwrote for code simplicity
31133141 return true ;
31143142}
31153143
@@ -3131,7 +3159,10 @@ IGFD::PlacesFeature::GroupStruct* IGFD::PlacesFeature::GetPlacesGroupPtr(const s
31313159}
31323160
31333161bool IGFD::PlacesFeature::GroupStruct::AddPlace (const std::string& vPlaceName, const std::string& vPlacePath, const bool & vCanBeSaved, const FileStyle& vStyle) {
3134- if (vPlaceName.empty () || vPlacePath.empty ()) return false ;
3162+ if (vPlaceName.empty () || vPlacePath.empty ()) {
3163+ return false ;
3164+ }
3165+ canBeSaved |= vCanBeSaved; // if one place must be saved so we mark the group to be saved
31353166 PlaceStruct place;
31363167 place.name = vPlaceName;
31373168 place.path = vPlacePath;
@@ -3141,7 +3172,9 @@ bool IGFD::PlacesFeature::GroupStruct::AddPlace(const std::string& vPlaceName, c
31413172}
31423173
31433174bool IGFD::PlacesFeature::GroupStruct::RemovePlace (const std::string& vPlaceName) {
3144- if (vPlaceName.empty ()) return false ;
3175+ if (vPlaceName.empty ()) {
3176+ return false ;
3177+ }
31453178 for (auto places_it = places.begin (); places_it != places.end (); ++places_it) {
31463179 if ((*places_it).name == vPlaceName) {
31473180 places.erase (places_it);
@@ -4931,20 +4964,42 @@ IGFD_C_API void IGFD_DeserializePlaces(ImGuiFileDialog* vContextPtr, const char*
49314964 }
49324965}
49334966
4934- IGFD_C_API void IGFD_AddPlace (ImGuiFileDialog* vContextPtr, const char * vPlaceName, const char * vPlacePath) {
4967+ IGFD_C_API bool IGFD_AddPlacesGroup (ImGuiFileDialog* vContextPtr, const char * vGroupName, size_t vDisplayOrder, bool vCanBeEdited) {
4968+ if (vContextPtr != nullptr ) {
4969+ return vContextPtr->AddPlacesGroup (vGroupName, vDisplayOrder, vCanBeEdited);
4970+ }
4971+ return false ;
4972+ }
4973+
4974+ IGFD_C_API bool IGFD_RemovePlacesGroup (ImGuiFileDialog* vContextPtr, const char * vGroupName) {
49354975 if (vContextPtr != nullptr ) {
4936- // todo : do the code
4937- // vContextPtr->AddPlace(vPlaceName, vPlacePath);
4976+ return vContextPtr->RemovePlacesGroup (vGroupName);
49384977 }
4978+ return false ;
49394979}
49404980
4941- IGFD_C_API void IGFD_RemovePlace (ImGuiFileDialog* vContextPtr, const char * vPlaceName) {
4981+ IGFD_C_API bool IGFD_AddPlace (ImGuiFileDialog* vContextPtr, const char * vGroupName, const char * vPlaceName, const char * vPlacePath, bool vCanBeSaved, const char * vIconText ) {
49424982 if (vContextPtr != nullptr ) {
4943- // todo : do the code
4944- // vContextPtr->RemovePlace(vPlaceName);
4983+ auto group_ptr = vContextPtr->GetPlacesGroupPtr (vGroupName);
4984+ if (group_ptr != nullptr ) {
4985+ IGFD::FileStyle style;
4986+ style.icon = vIconText;
4987+ return group_ptr->AddPlace (vPlaceName, vPlacePath, vCanBeSaved, style);
4988+ }
49454989 }
4990+ return false ;
49464991}
49474992
4993+ IGFD_C_API bool IGFD_RemovePlace (ImGuiFileDialog* vContextPtr, const char * vGroupName, const char * vPlaceName) {
4994+ if (vContextPtr != nullptr ) {
4995+ auto group_ptr = vContextPtr->GetPlacesGroupPtr (vGroupName);
4996+ if (group_ptr != nullptr ) {
4997+ return group_ptr->RemovePlace (vPlaceName);
4998+ }
4999+ }
5000+ return false ;
5001+ }
5002+
49485003#endif
49495004
49505005#ifdef USE_THUMBNAILS
0 commit comments