]> Creatis software - crea.git/blobdiff - lib/creaDevManagerLib/modelCDMFolder.cpp
Feature #1711
[crea.git] / lib / creaDevManagerLib / modelCDMFolder.cpp
index c1ef911dfd0b9efce843b402adc4529efd1dea1a..3365c099b9adfd64c246ff7b7f04a92636a6df02 100644 (file)
@@ -49,6 +49,7 @@ modelCDMFolder::modelCDMFolder()
 
 modelCDMFolder::modelCDMFolder(const std::string& path, const std::string& name, const int& level)
 {
+  std::cout << "creating folder: " + path + "\n";
   //set attributes
   this->children.clear();
   this->level = level;
@@ -70,7 +71,9 @@ modelCDMFolder::modelCDMFolder(const std::string& path, const std::string& name,
           std::string stdfileName = crea::wx2std(fileName);
 
           //if is an unknown folder, create folder
-          this->children.push_back(new modelCDMFolder(pathFixed + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1));
+          modelCDMFolder* folder = new modelCDMFolder(pathFixed + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
+          this->children.push_back(folder);
+          this->folders.push_back(folder);
 
           cont = dir.GetNext(&fileName);
         }
@@ -96,6 +99,7 @@ modelCDMFolder::modelCDMFolder(const std::string& path, const std::string& name,
     }
 
   this->SortChildren();
+  std::sort(this->folders.begin(), this->folders.end(), CompareNodeItem);
 }
 
 modelCDMFolder::~modelCDMFolder()
@@ -147,6 +151,7 @@ bool modelCDMFolder::OpenCMakeListsFile(std::string*& result)
 
 const bool modelCDMFolder::Refresh(std::string*& result)
 {
+  //std::cout << "refreshing folder " << this->name << std::endl;
   //set attributes
   this->type = wxDIR_DIRS;
 
@@ -163,12 +168,11 @@ const bool modelCDMFolder::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();
@@ -213,7 +217,7 @@ const bool modelCDMFolder::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)
                     {
@@ -255,6 +259,7 @@ const bool modelCDMFolder::Refresh(std::string*& result)
         }
     }
   this->SortChildren();
+  std::sort(this->folders.begin(), this->folders.end(), CompareNodeItem);
   return true;
 }