]> Creatis software - crea.git/blobdiff - lib/creaDevManagerLib/modelCDMFolder.cpp
Feature #1711
[crea.git] / lib / creaDevManagerLib / modelCDMFolder.cpp
index a1965a663ee3f2f061f1ba4697bb1fc65c3ca373..537e636759f79b919d5efde421cc4eb12dbbc0bd 100644 (file)
 
 #include "modelCDMFolder.h"
 
+#include <creaWx.h>
+#include <wx/dir.h>
+
+#include "CDMUtilities.h"
+
 modelCDMFolder::modelCDMFolder()
 {
+  this->CMakeLists = NULL;
 }
 
 modelCDMFolder::modelCDMFolder(const std::string& path, const int& level)
 {
+  //set attributes
+  this->children.clear();
+  this->level = level;
+  this->CMakeLists = NULL;
+
+  std::vector<std::string> words;
+  std::string delimiters;
+  //TODO::fix for windows
+  delimiters = "/";
+  CDMUtilities::splitter::split(words, path, delimiters, CDMUtilities::splitter::no_empties);
+  this->name = words[words.size()-1];
+
+  this->path = path;
+  this->type = wxDIR_DIRS;
+
+  std::string pathFixed(CDMUtilities::fixPath(path));
+  //check all folders
+  wxDir dir(crea::std2wx((pathFixed).c_str()));
+  if (dir.IsOpened())
+    {
+      wxString fileName;
+      bool cont = dir.GetFirst(&fileName, wxEmptyString, wxDIR_DIRS);
+      while (cont)
+        {
+          std::string stdfileName = crea::wx2std(fileName);
+
+          //if is an unknown folder, create folder
+          this->children.push_back(new modelCDMFolder(pathFixed + "/" + stdfileName, this->level + 1));
+
+          cont = dir.GetNext(&fileName);
+        }
+
+      cont = dir.GetFirst(&fileName, wxEmptyString, wxDIR_FILES);
+      while (cont)
+        {
+          std::string stdfileName = crea::wx2std(fileName);
+
+          //if CMakeLists, create CMakeLists
+          if(stdfileName == "CMakeLists.txt")
+            {
+              this->CMakeLists = new modelCDMCMakeListsFile(pathFixed + "/" + stdfileName, this->level + 1);
+              this->children.push_back(this->CMakeLists);
+            }
+          else
+            {
+              this->children.push_back(new modelCDMFile(pathFixed + "/" + stdfileName, this->level + 1));
+            }
+          //if is an unknown file, create file
+          cont = dir.GetNext(&fileName);
+        }
+    }
+
+  this->SortChildren();
 }
 
 modelCDMFolder::~modelCDMFolder()
 {
+  for (int i = 0; i < this->children.size(); i++)
+    {
+      if(this->children[i] != NULL)
+        {
+          delete this->children[i];
+          this->children[i] = NULL;
+        }
+    }
 }
 
 bool modelCDMFolder::CreateFolder(const std::string& name, std::string*& result,