]> Creatis software - crea.git/blobdiff - lib/creaDevManagerLib/modelCDMLib.cpp
Feature #1711
[crea.git] / lib / creaDevManagerLib / modelCDMLib.cpp
index 416c1ff5230050f9bbf21726e2358c6929db00f9..16211eed4ade6c269d87e23b93971cda679d397a 100644 (file)
@@ -47,6 +47,7 @@ modelCDMLib::modelCDMLib()
 
 modelCDMLib::modelCDMLib(const std::string& path, const std::string& name, const int& level)
 {
+  std::cout << "creating lib\n";
   this->type = wxDIR_DIRS;
   this->name = name;
   this->level = level;
@@ -69,9 +70,17 @@ modelCDMLib::modelCDMLib(const std::string& path, const std::string& name, const
         {
           std::string stdfileName = crea::wx2std(fileName);
 
-          modelCDMLibrary* library = new modelCDMLibrary(pathFixed + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
-          this->libraries.push_back(library);
-          this->children.push_back(library);
+          if(stdfileName != "template_lib")
+            {
+              modelCDMLibrary* library = new modelCDMLibrary(pathFixed + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
+              this->libraries.push_back(library);
+              this->children.push_back(library);
+            }
+          else
+            {
+              modelCDMFolder* folder = new modelCDMFolder(pathFixed + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
+              this->children.push_back(folder);
+            }
 
           cont = dir.GetNext(&fileName);
         }
@@ -97,6 +106,7 @@ modelCDMLib::modelCDMLib(const std::string& path, const std::string& name, const
         }
     }
   this->SortChildren();
+  std::sort(this->libraries.begin(), this->libraries.end(), CompareNodeItem);
 }
 
 modelCDMLib::~modelCDMLib()
@@ -175,26 +185,50 @@ const bool modelCDMLib::Refresh(std::string*& result)
       while (cont)
         {
           std::string stdfileName = crea::wx2std(fileName);
-          std::string libraryName = stdfileName;
-          //check if they already exist
-          bool found = false;
-          for (int i = 0;!found && i < this->libraries.size(); i++)
+
+          if(stdfileName != "template_lib")
             {
-              if (this->libraries[i]->GetName() == libraryName)
+              std::string libraryName = stdfileName;
+              //check if library already exist
+              bool found = false;
+              for (int i = 0; !found && i < this->libraries.size(); i++)
                 {
-                  found = true;
-                  int pos = std::find(this->children.begin(), this->children.end(), this->libraries[i]) - this->children.begin();
-                  checked[pos] = true;
-                  checkedLibraries[i] = true;
-                  if(!this->libraries[i]->Refresh(result))
-                    return false;
+                  if (this->libraries[i]->GetName() == libraryName)
+                    {
+                      found = true;
+                      int pos = std::find(this->children.begin(), this->children.end(), this->libraries[i]) - this->children.begin();
+                      checked[pos] = true;
+                      checkedLibraries[i] = true;
+                      if(!this->libraries[i]->Refresh(result))
+                        return false;
+                    }
+                }
+              if(!found)
+                {
+                  modelCDMLibrary* library = new modelCDMLibrary(this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
+                  this->libraries.push_back(library);
+                  this->children.push_back(library);
                 }
             }
-          if(!found)
+          else
             {
-              modelCDMLibrary* library = new modelCDMLibrary(this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
-              this->libraries.push_back(library);
-              this->children.push_back(library);
+              //check if folder already exist
+              bool found = false;
+              for (int i = 0; !found && i < this->children.size(); i++)
+                {
+                  if (this->children[i]->GetName() == stdfileName)
+                    {
+                      found = true;
+                      checked[i] = true;
+                      if(!this->children[i]->Refresh(result))
+                        return false;
+                    }
+                }
+              if(!found)
+                {
+                  modelCDMFolder* folder= new modelCDMFolder(this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
+                  this->children.push_back(folder);
+                }
             }
           cont = dir.GetNext(&fileName);
         }
@@ -224,7 +258,7 @@ const bool modelCDMLib::Refresh(std::string*& result)
           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)
                     {
@@ -266,5 +300,6 @@ const bool modelCDMLib::Refresh(std::string*& result)
         }
     }
   this->SortChildren();
+  std::sort(this->libraries.begin(), this->libraries.end(), CompareNodeItem);
   return true;
 }