From: Daniel Gonzalez Date: Mon, 14 Jan 2013 15:33:49 +0000 (+0100) Subject: Feature #1711 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=aac70f229589d8d7bf887f6f60afe1150f3cdd25;p=crea.git Feature #1711 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. --- diff --git a/lib/creaDevManagerLib/modelCDMApplication.cpp b/lib/creaDevManagerLib/modelCDMApplication.cpp index 5777044..d88e257 100644 --- a/lib/creaDevManagerLib/modelCDMApplication.cpp +++ b/lib/creaDevManagerLib/modelCDMApplication.cpp @@ -43,11 +43,13 @@ 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 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 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 wordBits; + CDMUtilities::splitter::split(wordBits,word," \n",CDMUtilities::splitter::no_empties); + if (wordBits[wordBits.size() - 1] == "main") + { + this->mainFile = dynamic_cast(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 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); } } diff --git a/lib/creaDevManagerLib/modelCDMApplication.h b/lib/creaDevManagerLib/modelCDMApplication.h index 244ec73..9839948 100644 --- a/lib/creaDevManagerLib/modelCDMApplication.h +++ b/lib/creaDevManagerLib/modelCDMApplication.h @@ -38,7 +38,8 @@ #include #include -#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 folders; }; diff --git a/lib/creaDevManagerLib/wxCDMApplicationDescriptionPanel.cpp b/lib/creaDevManagerLib/wxCDMApplicationDescriptionPanel.cpp index bf0acee..60fbdf6 100644 --- a/lib/creaDevManagerLib/wxCDMApplicationDescriptionPanel.cpp +++ b/lib/creaDevManagerLib/wxCDMApplicationDescriptionPanel.cpp @@ -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(); +} diff --git a/lib/creaDevManagerLib/wxCDMApplicationDescriptionPanel.h b/lib/creaDevManagerLib/wxCDMApplicationDescriptionPanel.h index 0aa79fa..995d2be 100644 --- a/lib/creaDevManagerLib/wxCDMApplicationDescriptionPanel.h +++ b/lib/creaDevManagerLib/wxCDMApplicationDescriptionPanel.h @@ -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); };