2 * ModelCreaDevManagerTree.cpp
4 * Created on: 22/10/2012
8 #include "ModelCreaDevManagerTree.h"
19 ModelCreaDevManagerTree::ModelCreaDevManagerTree()
23 ModelCreaDevManagerTree::~ModelCreaDevManagerTree()
27 bool ModelCreaDevManagerTree::CompareNodeItem(ModelCreaDevManagerTreeNode x, ModelCreaDevManagerTreeNode y)
32 std::string xName = x.GetName();
33 std::string yName = y.GetName();
34 unsigned char xType = x.GetType();
35 unsigned char yType = y.GetType();
37 while ((i < xName.length()) && (i < yName.length()))
39 if (tolower (xName[i]) < tolower (yName[i]))
45 else if (tolower (xName[i]) > tolower (yName[i]))
56 if (xName.length() < yName.length())
73 void ModelCreaDevManagerTree::addRoot(std::string path)
75 std::stringstream p(path);
76 std::vector<std::string> breadcrumbs;
83 breadcrumbs.push_back(name);
87 for (int i = 0; i < breadcrumbs.size()-1; i++)
89 path += breadcrumbs[i] + "/";
91 name = breadcrumbs[breadcrumbs.size()-1];
92 this->projectRoots.push_back(ModelCreaDevManagerTreeNode(path,name,DT_DIR,0));
94 std::cout << "project root added: " << name << " in " << path << std::endl;
97 void ModelCreaDevManagerTree::populateNode(ModelCreaDevManagerTreeNode& node)
99 //std::cout << "populating " << node.GetName() << " path " << node.GetPath() << "..." << std::endl;
100 std::vector <ModelCreaDevManagerTreeNode>* nodes = new std::vector <ModelCreaDevManagerTreeNode>;
102 std::string path = node.GetPath()+node.GetName()+"/";
104 wxDir dir(wxString(path.c_str()));
107 std::cerr << "Couldn't open the directory" << std::endl;
112 bool cont = dir.GetFirst(&fileName, wxEmptyString, wxDIR_DIRS);
115 ModelCreaDevManagerTreeNode innerNode = ModelCreaDevManagerTreeNode(path, crea::wx2std(fileName), wxDIR_DIRS, node.GetLevel()+1);
116 this->populateNode(innerNode);
117 nodes->push_back(innerNode);
118 cont = dir.GetNext(&fileName);
121 cont = dir.GetFirst(&fileName, wxEmptyString, wxDIR_FILES);
124 ModelCreaDevManagerTreeNode innerNode = ModelCreaDevManagerTreeNode(path, crea::wx2std(fileName), wxDIR_FILES, node.GetLevel()+1);
125 nodes->push_back(innerNode);
126 cont = dir.GetNext(&fileName);
129 sort (nodes->begin(), nodes->end(), CompareNodeItem);
130 node.SetChildren(*nodes);
137 std::string path = node.GetPath()+node.GetName()+"/";
139 dp = opendir(path.c_str());
142 while ((ep = readdir (dp)) != NULL)
144 //std::cout << ep->d_name << std::endl;
145 if(strcmp(ep->d_name, ".") != 0 && strcmp(ep->d_name, "..") != 0 )
147 ModelCreaDevManagerTreeNode innerNode = ModelCreaDevManagerTreeNode(path, ep->d_name, ep->d_type, node.GetLevel()+1);
148 if (ep->d_type == DT_DIR)
150 this->populateNode(innerNode);
153 nodes->push_back(innerNode);
158 (void) closedir (dp);
160 sort (nodes->begin(), nodes->end(), CompareNodeItem);
162 node.SetChildren(*nodes);
166 std::cerr << "Couldn't open the directory" << std::endl;
170 void ModelCreaDevManagerTree::populateNode(std::string path)
172 if(path[path.size()-1] != '/')
174 std::cout << "searching " << path << std::endl;
175 for (int i = 0; i < this->projectRoots.size(); i++)
177 //std::cout << (this->projectRoots[i].GetPath() + this->projectRoots[i].GetName() + "/") << "..." << std::endl;
178 if(this->projectRoots[i].GetPath()+this->projectRoots[i].GetName()+"/" == path)
180 std::cout << "Populating Project: " << path << "..." << std::endl;
181 this->populateNode(this->projectRoots[i]);