]> Creatis software - crea.git/blobdiff - lib/creaDevManagerLib/modelCDMApplication.cpp
Feature #1711
[crea.git] / lib / creaDevManagerLib / modelCDMApplication.cpp
index 57770444d31e13ad6df5c98617f5b83ab7a9cb1e..d88e25704411fce97eea9a2d519c334ff837f12e 100644 (file)
 
 modelCDMApplication::modelCDMApplication()
 {
+  mainFile = NULL;
 }
 
 modelCDMApplication::modelCDMApplication(const std::string& path, const std::string& name, const int& level)
 {
   std::cout << "creating application: " + path + "\n";
+  this->mainFile = NULL;
   //folder name
   this->name = name;
   //path
@@ -123,7 +125,27 @@ modelCDMApplication::modelCDMApplication(const std::string& path, const std::str
           //if is an unknown file, create file
           else
             {
-              this->children.push_back(new modelCDMFile(this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1));
+              modelCDMFile* file = new modelCDMFile(this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
+              std::string extension = stdfileName.substr(stdfileName.size()-4);
+              if (mainFile == NULL && (extension == ".cxx" || extension == ".cpp"))
+                {
+                  std::ifstream fileStream;
+                  std::string word;
+                  fileStream.open((this->path + CDMUtilities::SLASH + stdfileName).c_str());
+                  while (fileStream.is_open() && !fileStream.eof())
+                    {
+                      //get sets
+                      std::getline(fileStream,word,'(');
+                      std::vector<std::string> wordBits;
+                      CDMUtilities::splitter::split(wordBits,word," \n",CDMUtilities::splitter::no_empties);
+                      if (wordBits[wordBits.size() - 1] == "main")
+                        {
+                          this->mainFile = file;
+                        }
+                    }
+                  fileStream.close();
+                }
+              this->children.push_back(file);
             }
 
           cont = dir.GetNext(&fileName);
@@ -142,6 +164,11 @@ const std::string& modelCDMApplication::GetExecutableName() const
   return this->executableName;
 }
 
+modelCDMFile* modelCDMApplication::GetMainFile() const
+{
+  return this->mainFile;
+}
+
 bool modelCDMApplication::SetExecutableName(const std::string& fileName, std::string*& result)
 {
   std::vector<std::string> words;
@@ -206,6 +233,7 @@ modelCDMFolder* modelCDMApplication::CreateFolder(const std::string& name, std::
 
 const bool modelCDMApplication::Refresh(std::string*& result)
 {
+  this->mainFile = NULL;
   std::cout << "refreshing application: " << this->executableName << std::endl;
   //set attributes
   this->type = wxDIR_DIRS;
@@ -312,14 +340,56 @@ const bool modelCDMApplication::Refresh(std::string*& result)
                     {
                       found = true;
                       checked[i] = true;
+
                       if(!this->children[i]->Refresh(result))
                         return false;
+
+                      std::string extension = stdfileName.substr(stdfileName.size()-4);
+                      if (mainFile == NULL && (extension == ".cxx" || extension == ".cpp"))
+                        {
+                          std::ifstream fileStream;
+                          std::string word;
+                          fileStream.open((this->path + CDMUtilities::SLASH + stdfileName).c_str());
+                          while (fileStream.is_open() && !fileStream.eof())
+                            {
+                              //get sets
+                              std::getline(fileStream,word,'(');
+                              std::vector<std::string> wordBits;
+                              CDMUtilities::splitter::split(wordBits,word," \n",CDMUtilities::splitter::no_empties);
+                              if (wordBits[wordBits.size() - 1] == "main")
+                                {
+                                  this->mainFile = dynamic_cast<modelCDMFile*>(children[i]);
+                                }
+                            }
+                          fileStream.close();
+                        }
                     }
                 }
 
               if(!found)
                 {
                   modelCDMFile* file = new modelCDMFile(this->path + CDMUtilities::SLASH + stdfileName, stdfileName, this->level + 1);
+
+                  std::string extension = stdfileName.substr(stdfileName.size()-4);
+                  if (mainFile == NULL && (extension == ".cxx" || extension == ".cpp"))
+                    {
+                      std::ifstream fileStream;
+                      std::string word;
+                      fileStream.open((this->path + CDMUtilities::SLASH + stdfileName).c_str());
+                      while (fileStream.is_open() && !fileStream.eof())
+                        {
+                          //get sets
+                          std::getline(fileStream,word,'(');
+                          std::vector<std::string> wordBits;
+                          CDMUtilities::splitter::split(wordBits,word," \n",CDMUtilities::splitter::no_empties);
+                          if (wordBits[wordBits.size() - 1] == "main")
+                            {
+                              this->mainFile = file;
+                            }
+                        }
+                      fileStream.close();
+                    }
+
                   this->children.push_back(file);
                 }
             }