]> Creatis software - crea.git/blobdiff - lib/creaDevManagerLib/modelCDMLibrary.cpp
Feature #1711
[crea.git] / lib / creaDevManagerLib / modelCDMLibrary.cpp
index e16eeae0d0d32e4f1f053dde796ada9f0276abb3..1964e882c02b6ab3192b5978c7c9139403200db6 100644 (file)
@@ -47,6 +47,7 @@ modelCDMLibrary::modelCDMLibrary()
 
 modelCDMLibrary::modelCDMLibrary(const std::string& path, const std::string& name, const int& level)
 {
+  std::cout << "creating library: " + path + "\n";
   //folder name
   this->name = name;
   //path
@@ -131,6 +132,7 @@ modelCDMLibrary::modelCDMLibrary(const std::string& path, const std::string& nam
         }
     }
   this->SortChildren();
+  std::sort(this->folders.begin(), this->folders.end(), CompareNodeItem);
 }
 
 modelCDMLibrary::~modelCDMLibrary()
@@ -206,6 +208,7 @@ modelCDMFolder* modelCDMLibrary::CreateFolder(const std::string& name, std::stri
 
 const bool modelCDMLibrary::Refresh(std::string*& result)
 {
+  std::cout << "refreshing library: " << this->nameLibrary << std::endl;
   //set attributes
   this->type = wxDIR_DIRS;
 
@@ -256,12 +259,11 @@ const bool modelCDMLibrary::Refresh(std::string*& result)
       while (cont)
         {
           std::string stdfileName = crea::wx2std(fileName);
-          std::string folderName = stdfileName;
           //check if they already exist
           bool found = false;
-          for (int i = 0;!found && i < this->folders.size(); i++)
+          for (int i = 0; !found && i < this->folders.size(); i++)
             {
-              if (this->folders[i]->GetName() == folderName)
+              if (this->folders[i]->GetName() == stdfileName)
                 {
                   found = true;
                   int pos = std::find(this->children.begin(), this->children.end(), this->folders[i]) - this->children.begin();
@@ -301,11 +303,11 @@ const bool modelCDMLibrary::Refresh(std::string*& result)
                     return false;
                 }
             }
-          //if is an unknown file, create file
+          //if is an unknown file, check if exist in children
           else
             {
               bool found = false;
-              for (int i = 0; i <!found && this->children.size(); i++)
+              for (int i = 0; !found && i < this->children.size(); i++)
                 {
                   if (this->children[i]->GetName() == stdfileName)
                     {
@@ -347,5 +349,6 @@ const bool modelCDMLibrary::Refresh(std::string*& result)
         }
     }
   this->SortChildren();
+  std::sort(this->folders.begin(), this->folders.end(), CompareNodeItem);
   return true;
 }