]> Creatis software - crea.git/blobdiff - lib/creaDevManagerLib/modelCDMFolder.cpp
Feature #1711
[crea.git] / lib / creaDevManagerLib / modelCDMFolder.cpp
index c1ef911dfd0b9efce843b402adc4529efd1dea1a..bcef483f2c6146028430e6baf83e3ca098cee4c7 100644 (file)
@@ -47,9 +47,11 @@ modelCDMFolder::modelCDMFolder()
   this->CMakeLists = NULL;
 }
 
-modelCDMFolder::modelCDMFolder(const std::string& path, const std::string& name, const int& level)
+modelCDMFolder::modelCDMFolder(modelCDMIProjectTreeNode* parent, const std::string& path, const std::string& name, const int& level)
 {
+  std::cout << "creating folder: " + path + "\n";
   //set attributes
+  this->parent = parent;
   this->children.clear();
   this->level = level;
   this->CMakeLists = NULL;
@@ -70,7 +72,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(this, pathFixed + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
+          this->children.push_back(folder);
+          this->folders.push_back(folder);
 
           cont = dir.GetNext(&fileName);
         }
@@ -83,12 +87,12 @@ modelCDMFolder::modelCDMFolder(const std::string& path, const std::string& name,
           //if CMakeLists, create CMakeLists
           if(stdfileName == "CMakeLists.txt")
             {
-              this->CMakeLists = new modelCDMCMakeListsFile(pathFixed + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
+              this->CMakeLists = new modelCDMCMakeListsFile(this, pathFixed + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
               this->children.push_back(this->CMakeLists);
             }
           else
             {
-              this->children.push_back(new modelCDMFile(pathFixed + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1));
+              this->children.push_back(new modelCDMFile(this, pathFixed + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1));
             }
           //if is an unknown file, create file
           cont = dir.GetNext(&fileName);
@@ -96,13 +100,14 @@ modelCDMFolder::modelCDMFolder(const std::string& path, const std::string& name,
     }
 
   this->SortChildren();
+  std::sort(this->folders.begin(), this->folders.end(), CompareNodeItem);
 }
 
 modelCDMFolder::~modelCDMFolder()
 {
   this->folders.clear();
   this->CMakeLists = NULL;
-  for (int i = 0; i < this->children.size(); i++)
+  for (int i = 0; i < (int)(this->children.size()); i++)
     {
       if(this->children[i] != NULL)
         {
@@ -113,6 +118,21 @@ modelCDMFolder::~modelCDMFolder()
   this->children.clear();
 }
 
+bool modelCDMFolder::CreateClass(const std::string& name)
+{
+  if (!CDMUtilities::createEmptyClass(name, this->path))
+      {
+        return false;
+      }
+    else
+      {
+        this->children.push_back(new modelCDMFile(this, this->path + CDMUtilities::SLASH + name + ".h", name + ".h", this->level + 1));
+        this->children.push_back(new modelCDMFile(this, this->path + CDMUtilities::SLASH + name + ".cpp", name + ".cpp", this->level + 1));
+        this->SortChildren();
+        return true;
+      }
+}
+
 modelCDMFolder* modelCDMFolder::CreateFolder(const std::string& name, std::string*& result)
 {
   //TODO:: mkdir depending on OS
@@ -122,7 +142,7 @@ modelCDMFolder* modelCDMFolder::CreateFolder(const std::string& name, std::strin
       result = new std::string("Error executing: " + command + ".");
       return NULL;
     }
-  modelCDMFolder* folder = new modelCDMFolder(path + CDMUtilities::SLASH + name, name, level + 1);
+  modelCDMFolder* folder = new modelCDMFolder(this, path + CDMUtilities::SLASH + name, name, level + 1);
   this->folders.push_back(folder);
   this->children.push_back(folder);
 
@@ -147,6 +167,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 +184,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 < (int)(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();
@@ -180,7 +200,7 @@ const bool modelCDMFolder::Refresh(std::string*& result)
             }
           if(!found)
             {
-              modelCDMFolder* folder = new modelCDMFolder(this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
+              modelCDMFolder* folder = new modelCDMFolder(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
               this->folders.push_back(folder);
               this->children.push_back(folder);
             }
@@ -197,7 +217,7 @@ const bool modelCDMFolder::Refresh(std::string*& result)
             {
               if (this->CMakeLists == NULL)
                 {
-                  this->CMakeLists = new modelCDMCMakeListsFile(this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
+                  this->CMakeLists = new modelCDMCMakeListsFile(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
                   this->children.push_back(this->CMakeLists);
                 }
               else
@@ -213,7 +233,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 < (int)(this->children.size()); i++)
                 {
                   if (this->children[i]->GetName() == stdfileName)
                     {
@@ -226,7 +246,7 @@ const bool modelCDMFolder::Refresh(std::string*& result)
 
               if(!found)
                 {
-                  modelCDMFile* file = new modelCDMFile(this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
+                  modelCDMFile* file = new modelCDMFile(this, this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
                   this->children.push_back(file);
                 }
             }
@@ -235,7 +255,7 @@ const bool modelCDMFolder::Refresh(std::string*& result)
         }
     }
 
-  for (int i = 0; i < checkedFolders.size(); i++)
+  for (int i = 0; i < (int)(checkedFolders.size()); i++)
     {
       if(!checkedFolders[i])
         {
@@ -244,7 +264,7 @@ const bool modelCDMFolder::Refresh(std::string*& result)
           i--;
         }
     }
-  for (int i = 0; i < checked.size(); i++)
+  for (int i = 0; i < (int)(checked.size()); i++)
     {
       if(!checked[i])
         {
@@ -255,6 +275,7 @@ const bool modelCDMFolder::Refresh(std::string*& result)
         }
     }
   this->SortChildren();
+  std::sort(this->folders.begin(), this->folders.end(), CompareNodeItem);
   return true;
 }