]> Creatis software - crea.git/commitdiff
Feature #1711
authorDaniel Gonzalez <daniel.gonzalez@creatis.insa-lyon.fr>
Mon, 14 Jan 2013 15:33:49 +0000 (16:33 +0100)
committerDaniel Gonzalez <daniel.gonzalez@creatis.insa-lyon.fr>
Mon, 14 Jan 2013 15:33:49 +0000 (16:33 +0100)
CreaDevManager application implementation

-Application now opens the main cpp file. It searches for the source file that has the main method. Also, on refresh it rechecks for the main file.

lib/creaDevManagerLib/modelCDMApplication.cpp
lib/creaDevManagerLib/modelCDMApplication.h
lib/creaDevManagerLib/wxCDMApplicationDescriptionPanel.cpp
lib/creaDevManagerLib/wxCDMApplicationDescriptionPanel.h

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);
                 }
             }
index 244ec736cdebf14e14bca49a850aeebe83c3a366..98399487cba8a683d36adfe83a3d99fb4175de5a 100644 (file)
@@ -38,7 +38,8 @@
 #include<iostream>
 #include<vector>
 
-#include"modelCDMFolder.h"
+#include "modelCDMFolder.h"
+#include "modelCDMFile.h"
 
 class modelCDMApplication : public modelCDMFolder
 {
@@ -48,6 +49,7 @@ public:
   ~modelCDMApplication();
 
   const std::string& GetExecutableName() const;
+  modelCDMFile* GetMainFile() const;
 
   bool SetExecutableName(const std::string& fileName, std::string*& result);
 
@@ -57,6 +59,7 @@ public:
 
 private:
   std::string executableName;
+  modelCDMFile* mainFile;
   std::vector<modelCDMFolder*> folders;
 };
 
index bf0acee23ae8a81143a51ecb8ebddb56fa4f06e7..60fbdf64ac1541a7c166bbd65ada113fbf492acd 100644 (file)
@@ -49,6 +49,7 @@ EVT_BUTTON(ID_BUTTON_CREATE_CLASS, wxCDMApplicationDescriptionPanel::OnBtnCreate
 EVT_BUTTON(ID_BUTTON_CREATE_FOLDER, wxCDMApplicationDescriptionPanel::OnBtnCreateFolder)
 EVT_BUTTON(ID_BUTTON_EDIT_CMAKELISTSFILE, wxCDMApplicationDescriptionPanel::OnBtnEditCMakeLists)
 EVT_BUTTON(ID_BUTTON_OPEN_FOLDER, wxCDMApplicationDescriptionPanel::OnBtnOpenFolder)
+EVT_BUTTON(ID_BUTTON_OPEN_CXX, wxCDMApplicationDescriptionPanel::OnBtnOpenMain)
 END_EVENT_TABLE()
 
 wxCDMApplicationDescriptionPanel::wxCDMApplicationDescriptionPanel(
@@ -142,22 +143,27 @@ void wxCDMApplicationDescriptionPanel::CreateControls()
   //actions Sizer
   wxBoxSizer* actionsPanelSizer = new wxBoxSizer(wxHORIZONTAL);
   //actionsGrid Sizer
-  wxFlexGridSizer* actionsGridSizer = new wxFlexGridSizer(2, 2, 9, 15);
+  wxFlexGridSizer* actionsGridSizer = new wxFlexGridSizer(3, 2, 9, 15);
 
   wxButton* createClassbt = new wxButton(actionsPanel, ID_BUTTON_CREATE_CLASS, _T("Create Class (Optional)"));
   createClassbt->SetToolTip(wxT("Create a new Class (.h and .cxx files)."));
   wxButton* createFolderbt = new wxButton(actionsPanel, ID_BUTTON_CREATE_FOLDER, _T("Create Folder (Optional)"));
   createFolderbt->SetToolTip(wxT("Create a new Folder inside the application folder."));
+  wxButton* openMainbt = new wxButton(actionsPanel, ID_BUTTON_OPEN_CXX, _T("A. Open Main File (Optional)"));
+  openMainbt->SetToolTip(wxT("Open the main file in the application folder with the default code editor."));
+  openMainbt->Connect(wxEVT_ENTER_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMApplicationDescriptionPanel::OnMainMouseEnter,NULL,this);
+  openMainbt->Connect(wxEVT_LEAVE_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMApplicationDescriptionPanel::OnMainMouseExit,NULL,this);
   wxButton* editCMakebt = new wxButton(actionsPanel, ID_BUTTON_EDIT_CMAKELISTSFILE, _T("B. Edit CMakeLists File"));
   editCMakebt->SetToolTip(wxT("Edit the CMakeLists.txt file inside this application."));
   editCMakebt->Connect(wxEVT_ENTER_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMApplicationDescriptionPanel::OnCMakeMouseEnter,NULL,this);
   editCMakebt->Connect(wxEVT_LEAVE_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMApplicationDescriptionPanel::OnCMakeMouseExit,NULL,this);
-  wxButton* openFolderbt = new wxButton(actionsPanel, ID_BUTTON_OPEN_FOLDER, _T("A. Open Application Folder"));
+  wxButton* openFolderbt = new wxButton(actionsPanel, ID_BUTTON_OPEN_FOLDER, _T("C. Open Application Folder"));
   openFolderbt->SetToolTip(wxT("Open the application folder in the file explorer."));
 
 
-  actionsGridSizer->Add(openFolderbt, 1, wxALL | wxEXPAND, 5);
+  actionsGridSizer->Add(openMainbt, 1, wxALL | wxEXPAND, 5);
   actionsGridSizer->Add(editCMakebt, 1, wxALL | wxEXPAND, 5);
+  actionsGridSizer->Add(openFolderbt, 1, wxALL | wxEXPAND, 5);
   actionsGridSizer->Add(createClassbt, 1, wxALL | wxEXPAND, 5);
   actionsGridSizer->Add(createFolderbt, 1, wxALL | wxEXPAND, 5);
 
@@ -334,3 +340,55 @@ void wxCDMApplicationDescriptionPanel::OnCMakeMouseExit(wxMouseEvent& event)
     }
   event.Skip();
 }
+
+void wxCDMApplicationDescriptionPanel::OnBtnOpenMain(wxCommandEvent& event)
+{
+  if (this->application->GetMainFile() != NULL)
+    {
+      if (CDMUtilities::openTextEditor(this->application->GetMainFile()->GetPath()))
+      {
+        wxMessageBox(crea::std2wx("The main file couldn't be opened."),_T("Open Main File - Error!"),wxOK | wxICON_ERROR);
+      }
+
+      wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LIST_ITEM_DESELECTED);
+
+      int MId = this->application->GetMainFile()->GetId();
+      newEvent->SetInt(MId);
+      newEvent->SetId(0);
+      wxPostEvent(this->GetParent(), *newEvent);
+
+      event.Skip();
+    }
+  else
+    {
+      wxMessageBox(crea::std2wx("There is no main file or it couldn't be detected."),_T("Open Main File - Error!"),wxOK | wxICON_ERROR);
+    }
+}
+
+void wxCDMApplicationDescriptionPanel::OnMainMouseEnter(wxMouseEvent& event)
+{
+  wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LIST_ITEM_SELECTED);
+
+  if(this->application->GetMainFile() != NULL)
+    {
+      int MId = this->application->GetMainFile()->GetId();
+      newEvent->SetInt(MId);
+      newEvent->SetId(0);
+      wxPostEvent(this->GetParent(), *newEvent);
+    }
+  event.Skip();
+}
+
+void wxCDMApplicationDescriptionPanel::OnMainMouseExit(wxMouseEvent& event)
+{
+  wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LIST_ITEM_DESELECTED);
+
+  if(this->application->GetMainFile() != NULL)
+    {
+      int MId = this->application->GetMainFile()->GetId();
+      newEvent->SetInt(MId);
+      newEvent->SetId(0);
+      wxPostEvent(this->GetParent(), *newEvent);
+    }
+  event.Skip();
+}
index 0aa79fa1a89517c09fba8498cc2ab310fd00f5a6..995d2be5939a2f09bcd24410c21b57063540ac06 100644 (file)
@@ -82,6 +82,9 @@ protected:
   void OnBtnOpenFolder(wxCommandEvent& event);
   void OnCMakeMouseEnter(wxMouseEvent& event);
   void OnCMakeMouseExit(wxMouseEvent& event);
+  void OnBtnOpenMain(wxCommandEvent& event);
+  void OnMainMouseEnter(wxMouseEvent& event);
+  void OnMainMouseExit(wxMouseEvent& event);
 
 };