From: Daniel Gonzalez Date: Mon, 5 Nov 2012 15:01:12 +0000 (+0000) Subject: Feature #1711 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=24f60b821f76e16fcbaa37dca60e3a8e62ff8949;p=crea.git Feature #1711 CreaDevManager application implementation: Implementation of New Project functionality --- diff --git a/lib/creaDevManagerLib/ControlCreaDevManagerMain.cpp b/lib/creaDevManagerLib/ControlCreaDevManagerMain.cpp new file mode 100644 index 0000000..56337bd --- /dev/null +++ b/lib/creaDevManagerLib/ControlCreaDevManagerMain.cpp @@ -0,0 +1,105 @@ +/* + * ControlCreaDevManagerMain.cpp + * + * Created on: 5/11/2012 + * Author: daniel + */ + +#include "ControlCreaDevManagerMain.h" +#include "ModelCreaDevManagerTree.h" + +#include +#include + +ControlCreaDevManagerMain::ControlCreaDevManagerMain() +{ +} + +ControlCreaDevManagerMain::~ControlCreaDevManagerMain() +{ +} + +const ModelCreaDevManagerTree& ControlCreaDevManagerMain::GetActiveProjects() const +{ + return projectsTree; +} + +bool ControlCreaDevManagerMain::LoadActiveProjects() +{ + // TODO LoadActiveProjects + std::cerr << "LoadActiveProjects unimplemented yet" << std::endl; + return true; +} + +bool ControlCreaDevManagerMain::UpdateActiveProjects() +{ + // TODO UpdateActiveProjects + std::cerr << "UpdateActiveProjects unimplemented yet" << std::endl; + return true; +} + +const int ControlCreaDevManagerMain::OpenProject(const std::string& actualpath) +{ + std::string path = actualpath; + std::cout << "selection path: "<< path << std::endl; + std::string path1 = path + "/Makefile"; + FILE* pFile = fopen(path1.c_str(), "r"); + if(pFile == NULL) // not the binary folder + { + std::cerr << path1 << ": file not found..." << std::endl; + path1 = path + "/CMakeLists.txt"; + pFile = fopen(path1.c_str(), "r"); + if(pFile == NULL) //not the source folder + { + std::cerr << path1 << ": file not found..." << std::endl; + return 1; + }else{//source folder + std::cout << "sources folder found..." << std::endl; + fclose(pFile); + } + }else{//binary folder + std::cout << "binary folder found..." << std::endl; + fclose(pFile); + + std::ifstream readFile; + readFile.open(path1.c_str()); + std::string word; + bool found = false; + + while(!found && readFile >> word) + { + //cout << word << endl; + if(word == "CMAKE_SOURCE_DIR") + { + readFile >> word; + readFile.ignore(); + getline(readFile, word, '\n'); + path = word; + found = true; + } + } + readFile.close(); + + if(!found) + { + std::cerr << "sources not found..." << std::endl; + + return 2; + }else{ + pFile = fopen(path.c_str(), "r"); + std::cout << "sources at " << path << " open = " << (pFile != NULL) << std::endl; + std::cout.flush(); + } + } + + projectsTree.addRoot(path); + projectsTree.populateNode(path); + return 0; +} + +bool ControlCreaDevManagerMain::CloseProject(const std::string& projectName) +{ + // TODO CloseProject + std::cerr << "CloseProject unimplemented yet" << std::endl; + return true; +} diff --git a/lib/creaDevManagerLib/ControlCreaDevManagerMain.h b/lib/creaDevManagerLib/ControlCreaDevManagerMain.h new file mode 100644 index 0000000..786df73 --- /dev/null +++ b/lib/creaDevManagerLib/ControlCreaDevManagerMain.h @@ -0,0 +1,32 @@ +/* + * ControlCreaDevManagerMain.h + * + * Created on: 5/11/2012 + * Author: daniel + */ + +#ifndef CONTROLCREADEVMANAGERMAIN_H_ +#define CONTROLCREADEVMANAGERMAIN_H_ + +#include +#include "ModelCreaDevManagerTree.h" + +class ControlCreaDevManagerMain +{ +public: + ControlCreaDevManagerMain(); + ~ControlCreaDevManagerMain(); + + const ModelCreaDevManagerTree& GetActiveProjects() const; + bool LoadActiveProjects(); + bool UpdateActiveProjects(); + const int OpenProject(const std::string& path); + bool CloseProject(const std::string& projectName); + +private: + ModelCreaDevManagerTree projectsTree; +}; + + + +#endif /* CONTROLCREADEVMANAGERMAIN_H_ */ diff --git a/lib/creaDevManagerLib/ControlCreaDevManagerProject.cpp b/lib/creaDevManagerLib/ControlCreaDevManagerProject.cpp new file mode 100644 index 0000000..9660328 --- /dev/null +++ b/lib/creaDevManagerLib/ControlCreaDevManagerProject.cpp @@ -0,0 +1,99 @@ +/* + * ControlCreaDevManagerProject.cpp + * + * Created on: 5/11/2012 + * Author: daniel + */ + +#include "ControlCreaDevManagerProject.h" + +#include +#include +#include // for getenv + +ControlCreaDevManagerProject::ControlCreaDevManagerProject() +{ + // TODO Auto-generated constructor stub + +} + +ControlCreaDevManagerProject::~ControlCreaDevManagerProject() +{ + // TODO Auto-generated destructor stub +} + +bool ControlCreaDevManagerProject::CreateProject(const std::string& name, const std::string& dir, const std::string& author, const std::string& description) +{ + +#if(_WIN32) + + std::string command("creaNewProject.bat "); + std::string command1("creaSed.exe "); + std::string command2("del "); + + command += "\"" + dir + "\" \"" + name + "\""; + command1 += "\"" + dir+"\\"+name+"\\CMakeLists.txt.in\" " + "NameOfTheProject " + name + "> \"" + dir + "\\" + name + "\\CMakeLists.txt\""; + command2 += "\"" + dir+"\\"+name+"\\CMakeLists.txt.in\""; + if ( ! system ( command.c_str() ) ) + { + system ( command1.c_str() ); + system ( command2.c_str() ); + + // Create a Package at the same time. JPR + char *author = author.c_str(); + std::string nomDirectory = dir + "\\" + name; + std::string nomPackageDirectory = nomDirectory + "\\" + "bbtk_" + name + "_PKG"; + std::string bbCreatePackage("bbCreatePackage "); + bbCreatePackage += nomDirectory + " " + name + " " + author + " " + description; + system (bbCreatePackage.c_str()); + std::string add; + add = "echo ADD_SUBDIRECTORY(bbtk_" + name + "_PKG) >> " + nomDirectory + "/CMakeLists.txt"; + system(add.c_str()); + + wxMessageBox(_T("New Project created !"),_T("creaNewProject"), wxOK | wxICON_INFORMATION); + } + else + { + wxString err(_T("An error occured while running '")); + err += crea::std2wx(command) + _T("'"); + wxMessageBox(err,_T("creaNewProject"),wxOK | wxICON_ERROR); + return false; + } + +// ------ LINUX / MacOS + +#else + std::string command("creaNewProject.sh "); + command += "\"" + dir + "\"" +" " + name; + std::cout << "executing " << command << std::endl; + if ( ! system ( command.c_str() ) ) + { + //wxMessageBox(_T("New Project created !"),_T("creaNewProject"), wxOK | wxICON_INFORMATION); + + std::string nomDirectory = dir + "/" + name; + std::string nomPackageDirectory = nomDirectory + "/" + "bbtk_" + name + "_PKG"; + + std::string bbCreatePackage("bbCreatePackage "); + bbCreatePackage += nomDirectory + " " + name + " " + author + " " + description; + std::cout << "executing " << bbCreatePackage << std::endl; + system (bbCreatePackage.c_str()); + + std::string add; + add = "echo 'ADD_SUBDIRECTORY(bbtk_" + name + "_PKG)' >> " + nomDirectory + "/CMakeLists.txt"; + //std::cout << add << std::endl; + std::cout << "executing " << add << std::endl; + system(add.c_str()); + + } + else + { + wxString err(_T("An error occured while running '")); + err += crea::std2wx(command) + _T("'"); + wxMessageBox(err,_T("creaNewProject"),wxOK | wxICON_ERROR); + return false; + } + +#endif + + return true; +} diff --git a/lib/creaDevManagerLib/ControlCreaDevManagerProject.h b/lib/creaDevManagerLib/ControlCreaDevManagerProject.h new file mode 100644 index 0000000..a227ef7 --- /dev/null +++ b/lib/creaDevManagerLib/ControlCreaDevManagerProject.h @@ -0,0 +1,21 @@ +/* + * ControlCreaDevManagerProject.h + * + * Created on: 5/11/2012 + * Author: daniel + */ + +#ifndef CONTROLCREADEVMANAGERPROJECT_H_ +#define CONTROLCREADEVMANAGERPROJECT_H_ + +#include + +class ControlCreaDevManagerProject +{ +public: + ControlCreaDevManagerProject(); + ~ControlCreaDevManagerProject(); + static bool CreateProject(const std::string& name, const std::string& location, const std::string& author, const std::string& description); +}; + +#endif /* CONTROLCREADEVMANAGERPROJECT_H_ */ diff --git a/lib/creaDevManagerLib/ModelCreaDevManagerTree.cpp b/lib/creaDevManagerLib/ModelCreaDevManagerTree.cpp index 64106b6..e980346 100644 --- a/lib/creaDevManagerLib/ModelCreaDevManagerTree.cpp +++ b/lib/creaDevManagerLib/ModelCreaDevManagerTree.cpp @@ -89,7 +89,20 @@ void ModelCreaDevManagerTree::addRoot(std::string path) path += breadcrumbs[i] + "/"; } name = breadcrumbs[breadcrumbs.size()-1]; - this->projectRoots.push_back(ModelCreaDevManagerTreeNode(path,name,DT_DIR,0)); + + bool projectFound = false; + for (int i = 0; i < this->projectRoots.size(); i++) + { + if(this->projectRoots[i].GetName() == name) + projectFound = true; + } + + if(!projectFound) + { + this->projectRoots.push_back(ModelCreaDevManagerTreeNode(path,name,DT_DIR,0)); + }else{ + std::cout << "already existing "; + } std::cout << "project root added: " << name << " in " << path << std::endl; } diff --git a/lib/creaDevManagerLib/ModelCreaDevManagerTreeNode.cpp b/lib/creaDevManagerLib/ModelCreaDevManagerTreeNode.cpp index 8486f80..832f001 100644 --- a/lib/creaDevManagerLib/ModelCreaDevManagerTreeNode.cpp +++ b/lib/creaDevManagerLib/ModelCreaDevManagerTreeNode.cpp @@ -19,26 +19,26 @@ ModelCreaDevManagerTreeNode::~ModelCreaDevManagerTreeNode() { } -std::string ModelCreaDevManagerTreeNode::GetPath() +const std::string& ModelCreaDevManagerTreeNode::GetPath() const { return this->_path; } -std::string ModelCreaDevManagerTreeNode::GetName() +const std::string& ModelCreaDevManagerTreeNode::GetName() const { return this->_name; } -unsigned char ModelCreaDevManagerTreeNode::GetType() +const unsigned char& ModelCreaDevManagerTreeNode::GetType() const { return this->_type; } -int ModelCreaDevManagerTreeNode::GetLevel() +const int& ModelCreaDevManagerTreeNode::GetLevel() const { return this->_level; } -std::vector& ModelCreaDevManagerTreeNode::GetChildren() +const std::vector& ModelCreaDevManagerTreeNode::GetChildren() const { return this->_children; } diff --git a/lib/creaDevManagerLib/ModelCreaDevManagerTreeNode.h b/lib/creaDevManagerLib/ModelCreaDevManagerTreeNode.h index 0cf4a56..61d9449 100644 --- a/lib/creaDevManagerLib/ModelCreaDevManagerTreeNode.h +++ b/lib/creaDevManagerLib/ModelCreaDevManagerTreeNode.h @@ -19,11 +19,11 @@ class ModelCreaDevManagerTreeNode ModelCreaDevManagerTreeNode(std::string path, std::string name, unsigned char type, int level); ~ModelCreaDevManagerTreeNode(); - std::string GetPath(); - std::string GetName(); - unsigned char GetType(); - int GetLevel(); - std::vector& GetChildren(); + const std::string& GetPath() const; + const std::string& GetName() const; + const unsigned char& GetType() const; + const int& GetLevel() const; + const std::vector& GetChildren() const; void SetChildren(std::vector& children); diff --git a/lib/creaDevManagerLib/creaDevManagerIds.h b/lib/creaDevManagerLib/creaDevManagerIds.h index 9937c17..a4c283c 100644 --- a/lib/creaDevManagerLib/creaDevManagerIds.h +++ b/lib/creaDevManagerLib/creaDevManagerIds.h @@ -41,4 +41,8 @@ #define ID_WINDOW_PROPERTIES 10225 #define ID_WINDOW_PROJ_ACTIONS 10226 +#define ID_BUTTON_NEXT 10300 +#define ID_BUTTON_CANCEL 10301 +#define ID_BUTTON_CHOOSE 10302 + #endif /* CREADEVMANAGERIDS_H_ */ diff --git a/lib/creaDevManagerLib/wxCreaDevManagerMainFrame.cxx b/lib/creaDevManagerLib/wxCreaDevManagerMainFrame.cxx index 03e4b10..e69b26a 100644 --- a/lib/creaDevManagerLib/wxCreaDevManagerMainFrame.cxx +++ b/lib/creaDevManagerLib/wxCreaDevManagerMainFrame.cxx @@ -5,6 +5,8 @@ #include "wxCreaDevManagerDescriptionPanel.h" #include "wxCreaDevManagerProjectActionsPanel.h" +#include "wxCreaDevManagerNewProjectDialog.h" +#include "ControlCreaDevManagerMain.h" #include @@ -59,6 +61,12 @@ wxCreaDevManagerMainFrame::~wxCreaDevManagerMainFrame() auiManager.UnInit(); } +void wxCreaDevManagerMainFrame::UpdateVisual() +{ + auiManager.Update(); + this->Update(); +} + bool wxCreaDevManagerMainFrame::Create( wxWindow* parent, wxWindowID id, @@ -69,6 +77,8 @@ bool wxCreaDevManagerMainFrame::Create( ) { wxFrame::Create(parent, id, caption, pos, size, style); + this->controller = new ControlCreaDevManagerMain(); + this->controller->LoadActiveProjects(); CreateMenus(); CreateControls(); return TRUE; @@ -185,79 +195,39 @@ void wxCreaDevManagerMainFrame::CreateControls() //File menu void wxCreaDevManagerMainFrame::OnMenuNewProject(wxCommandEvent& event) { - std::cerr << "Event OnMenuNewProject not implemented yet" << std::endl; + wxCreaDevManagerNewProjectDialog* dialog = new wxCreaDevManagerNewProjectDialog(this, this->controller); + long userResponse; + userResponse = dialog->ShowModal(); + + ((wxCreaDevManagerTreeCtrl*)tree_Projects)->BuildTree(this->controller->GetActiveProjects()); + + this->UpdateVisual(); + event.Skip(); } void wxCreaDevManagerMainFrame::OnMenuOpenProject(wxCommandEvent& event) { - //std::cerr << "Event OnMenuOpenProject not implemented" << std::endl; - long style = wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST; wxDirDialog* FD = new wxDirDialog(this, wxString("Select the project directory"), wxString(""), style); long userResponse; userResponse = FD->ShowModal(); if(userResponse == wxID_OK) { - std::string path = crea::wx2std (FD->GetPath()); - std::cout << "selection path: "<< path << std::endl; - std::string path1 = path + "/Makefile"; - - FILE* pFile = fopen(path1.c_str(), "r"); - if(pFile == NULL) // not the binary folder + switch(this->controller->OpenProject(crea::wx2std (FD->GetPath()))) { - std::cerr << path1 << ": file not found..." << std::endl; - path1 = path + "/CMakeLists.txt"; - pFile = fopen(path1.c_str(), "r"); - if(pFile == NULL) //not the source folder - { - std::cerr << path1 << ": file not found..." << std::endl; - wxMessageBox( wxT("No project selected."), wxT("Open Project - Error"), wxICON_ERROR); - event.Skip(); - return; - }else{//source folder - std::cout << "sources folder found..." << std::endl; - fclose(pFile); - } - }else{//binary folder - std::cout << "binary folder found..." << std::endl; - fclose(pFile); - - std::ifstream readFile; - readFile.open(path1.c_str()); - std::string word; - bool found = false; - while(!found && readFile >> word) - { - //cout << word << endl; - if(word == "CMAKE_SOURCE_DIR") - { - readFile >> word; - readFile.ignore(); - getline(readFile, word, '\n'); - path = word; - found = true; - } - } - readFile.close(); - - if(!found) - { - std::cerr << "sources not found..." << std::endl; - wxMessageBox( wxString("Sources not found."), wxString("Open Project - Error"), wxICON_ERROR); - event.Skip(); - return; - }else{ - pFile = fopen(path.c_str(), "r"); - std::cout << "sources at " << path << " open = " << (pFile != NULL) << std::endl; - std::cout.flush(); - } - } - - - this->projectTree.addRoot(path); - this->projectTree.populateNode(path); - - ((wxCreaDevManagerTreeCtrl*)tree_Projects)->BuildTree(this->projectTree); + case 1: + wxMessageBox( wxT("No project selected."), wxT("Open Project - Error"), wxICON_ERROR); + event.Skip(); + break; + case 2: + wxMessageBox( wxString("Sources not found."), wxString("Open Project - Error"), wxICON_ERROR); + event.Skip(); + break; + case 0: + break; + }; + + ((wxCreaDevManagerTreeCtrl*)tree_Projects)->BuildTree(this->controller->GetActiveProjects()); auiManager.Update(); } diff --git a/lib/creaDevManagerLib/wxCreaDevManagerMainFrame.h b/lib/creaDevManagerLib/wxCreaDevManagerMainFrame.h index cfdb1dd..c01d546 100644 --- a/lib/creaDevManagerLib/wxCreaDevManagerMainFrame.h +++ b/lib/creaDevManagerLib/wxCreaDevManagerMainFrame.h @@ -6,6 +6,7 @@ #include #include "ModelCreaDevManagerTree.h" +#include "ControlCreaDevManagerMain.h" class wxCreaDevManagerMainFrame:public wxFrame { @@ -31,6 +32,7 @@ class wxCreaDevManagerMainFrame:public wxFrame const wxSize& size = wxDefaultSize, long style = wxDEFAULT_FRAME_STYLE ); + void UpdateVisual(); protected: void CreateMenus(); @@ -83,7 +85,7 @@ class wxCreaDevManagerMainFrame:public wxFrame wxPanel* panel_ProjectActions; //Model - ModelCreaDevManagerTree projectTree; + ControlCreaDevManagerMain* controller; }; diff --git a/lib/creaDevManagerLib/wxCreaDevManagerNewProjectDialog.cpp b/lib/creaDevManagerLib/wxCreaDevManagerNewProjectDialog.cpp new file mode 100644 index 0000000..5fc6772 --- /dev/null +++ b/lib/creaDevManagerLib/wxCreaDevManagerNewProjectDialog.cpp @@ -0,0 +1,173 @@ +/* + * wxCreaDevManagerNewProjectDialog.cpp + * + * Created on: 2/11/2012 + * Author: daniel + */ + +#include "wxCreaDevManagerNewProjectDialog.h" + +#include "wx/richtext/richtextctrl.h" + +#include "creaDevManagerIds.h" + +#include "ControlCreaDevManagerProject.h" + +#include "wxCreaDevManagerMainFrame.h" + +BEGIN_EVENT_TABLE(wxCreaDevManagerNewProjectDialog, wxDialog) + EVT_BUTTON(ID_BUTTON_NEXT, wxCreaDevManagerNewProjectDialog::OnCreateProject) + EVT_BUTTON(ID_BUTTON_CANCEL, wxCreaDevManagerNewProjectDialog::OnCancel) + EVT_BUTTON(ID_BUTTON_CHOOSE, wxCreaDevManagerNewProjectDialog::OnChooseLocation) +END_EVENT_TABLE() + +wxCreaDevManagerNewProjectDialog::wxCreaDevManagerNewProjectDialog( + wxWindow* parent, + ControlCreaDevManagerMain* controller, + wxWindowID id, + const wxString& caption, + const wxPoint& position, + const wxSize& size, + long style +) +{ + this->Controller = controller; + wxCreaDevManagerNewProjectDialog::Create(parent, id, caption, position, size, style); +} + +wxCreaDevManagerNewProjectDialog::~wxCreaDevManagerNewProjectDialog() +{ +} + +bool wxCreaDevManagerNewProjectDialog::Create( + wxWindow* parent, + wxWindowID id, + const wxString& caption, + const wxPoint& position, + const wxSize& size, + long style +) +{ + wxDialog::Create(parent, id, caption, position, size, style); + + this->CreateControls(); + + return TRUE; +} + +void wxCreaDevManagerNewProjectDialog::CreateControls() +{ + wxBoxSizer* v_sizer1 = new wxBoxSizer(wxVERTICAL); + + + wxStaticText* title = new wxStaticText(this, wxID_ANY, wxString("Create a new project"), wxDefaultPosition, wxDefaultSize, wxALIGN_LEFT);//new wxRichTextCtrl(this,wxID_ANY, wxString("Create a new project"), wxDefaultPosition, wxDefaultSize, wxRE_READONLY); + v_sizer1->Add(title, 0, wxALIGN_LEFT | wxALL | wxALIGN_CENTER_VERTICAL, 5); + + wxStaticText* instruction = new wxStaticText(this, wxID_ANY, wxString("Please fill the following details."), wxDefaultPosition, wxDefaultSize, wxALIGN_LEFT); + v_sizer1->Add(instruction, 0, wxALIGN_LEFT | wxALL | wxALIGN_CENTER_VERTICAL, 5); + + wxFlexGridSizer* formItems = new wxFlexGridSizer(4,2,9,15); + + wxStaticText *stxtPrjLoc = new wxStaticText(this, -1, wxT("Project Location")); + wxStaticText *stxtPrjName = new wxStaticText(this, -1, wxT("Project Name")); + wxStaticText *stxtPrjAuth = new wxStaticText(this, -1, wxT("Default Package's Author (1 word)")); + wxStaticText *stxtPrjPkg = new wxStaticText(this, -1, wxT("Default Package's Description (HTML)")); + + wxBoxSizer* h_sizer1 = new wxBoxSizer(wxHORIZONTAL); + wxButton *ddPrjLocBtn = new wxButton(this, ID_BUTTON_CHOOSE, wxString("Choose directory...")); + this->projectLocation = new wxStaticText(this, -1, wxString("")); + h_sizer1->Add(ddPrjLocBtn,0,wxALIGN_LEFT | wxLEFT | wxALIGN_CENTER_VERTICAL, 5); + h_sizer1->Add(this->projectLocation,0,wxALIGN_LEFT | wxLEFT | wxALIGN_CENTER_VERTICAL, 5); + h_sizer1->SetMinSize(wxSize(150, 20)); + + this->projectName = new wxTextCtrl(this, -1); + this->packageAuthor = new wxTextCtrl(this, -1); + this->packageDescription = new wxTextCtrl(this, -1, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE); + + formItems->Add(stxtPrjLoc, 0, wxALIGN_CENTER_VERTICAL); + formItems->Add(h_sizer1, 1, wxEXPAND | wxALIGN_CENTER_VERTICAL); + formItems->Add(stxtPrjName, 0, wxALIGN_CENTER_VERTICAL); + formItems->Add(this->projectName, 1, wxEXPAND | wxALIGN_CENTER_VERTICAL); + formItems->Add(stxtPrjAuth, 0, wxALIGN_CENTER_VERTICAL); + formItems->Add(this->packageAuthor, 1, wxEXPAND | wxALIGN_CENTER_VERTICAL); + formItems->Add(stxtPrjPkg); + formItems->Add(this->packageDescription, 1, wxEXPAND); + + formItems->AddGrowableCol(1,1); + formItems->AddGrowableRow(3,1); + + v_sizer1->Add(formItems, 1, wxEXPAND | wxALL, 15); + + wxBoxSizer* h_sizer2 = new wxBoxSizer(wxHORIZONTAL); + h_sizer2->Add(new wxButton(this, ID_BUTTON_NEXT, wxString("Create Project")), 0, wxALL | wxALIGN_CENTER_VERTICAL, 5); + h_sizer2->Add(new wxButton(this, ID_BUTTON_CANCEL, wxString("Cancel")), 0, wxALL | wxALIGN_CENTER_VERTICAL, 5); + + v_sizer1->Add(h_sizer2, 0, wxALIGN_RIGHT | wxRIGHT | wxBOTTOM | wxALIGN_CENTER_VERTICAL, 30); + + SetSizer(v_sizer1); + v_sizer1->SetSizeHints(this); +} + +void wxCreaDevManagerNewProjectDialog::OnCreateProject(wxCommandEvent& event) +{ + bool ready = true; + + if(ready && this->projectName->GetValue() == wxString("")) + { + wxMessageBox(wxString("The project name cannot be empty"),_T("Error"),wxOK | wxICON_ERROR); + ready = false; + } + if(ready && this->projectLocation->GetLabel() == wxString("")) + { + wxMessageBox(wxString("The project location cannot be empty"),_T("Error"),wxOK | wxICON_ERROR); + ready = false; + } + if(ready && this->packageAuthor->GetValue() == wxString("")) + { + wxMessageBox(wxString("The project's author cannot be empty"),_T("Error"),wxOK | wxICON_ERROR); + ready = false; + } + + std::cout << ready << std::endl; + + if(ready && ControlCreaDevManagerProject::CreateProject(crea::wx2std(this->projectName->GetValue()), crea::wx2std(this->projectLocation->GetLabel()), crea::wx2std(this->packageAuthor->GetValue()), crea::wx2std(this->packageDescription->GetValue()))) + { + this->Controller->OpenProject(crea::wx2std(this->projectLocation->GetLabel()) + "/" + crea::wx2std(this->projectName->GetValue())); + + this->DestroyChildren(); + + wxBoxSizer* v_sizer1 = new wxBoxSizer(wxVERTICAL); + + wxStaticText* title = new wxStaticText(this, wxID_ANY, wxString("Your project is ready!"), wxDefaultPosition, wxDefaultSize, wxALIGN_LEFT);//new wxRichTextCtrl(this,wxID_ANY, wxString("Create a new project"), wxDefaultPosition, wxDefaultSize, wxRE_READONLY); + v_sizer1->Add(title, 0, wxALL, 5); + + wxStaticText* instruction = new wxStaticText(this, wxID_ANY, wxString("Please close this dialog to continue to the project."), wxDefaultPosition, wxDefaultSize, wxALIGN_LEFT); + v_sizer1->Add(instruction, 0, wxALL, 5); + + v_sizer1->Add(new wxButton(this, ID_BUTTON_CANCEL, wxString("Close")), 0, wxALL, 5); + + SetSizer(v_sizer1); + v_sizer1->SetSizeHints(this); + }else{ + if(ready) + this->Close(); + } + + + event.Skip(); +} + +void wxCreaDevManagerNewProjectDialog::OnCancel(wxCommandEvent& event) +{ + this->Close(); + event.Skip(); +} + +void wxCreaDevManagerNewProjectDialog::OnChooseLocation(wxCommandEvent& event) +{ + wxDirDialog* dialog = new wxDirDialog(this, "Choose the location of the new project"); + dialog->ShowModal(); + this->projectLocation->SetLabel(dialog->GetPath()); + this->Update(); + event.Skip(); +} diff --git a/lib/creaDevManagerLib/wxCreaDevManagerNewProjectDialog.h b/lib/creaDevManagerLib/wxCreaDevManagerNewProjectDialog.h new file mode 100644 index 0000000..58f516b --- /dev/null +++ b/lib/creaDevManagerLib/wxCreaDevManagerNewProjectDialog.h @@ -0,0 +1,56 @@ +/* + * wxCreaDevManagerNewProjectDialog.h + * + * Created on: 2/11/2012 + * Author: daniel + */ + +#ifndef WXCREADEVMANAGERNEWPROJECTDIALOG_H_ +#define WXCREADEVMANAGERNEWPROJECTDIALOG_H_ + +#include +#include +#include "ControlCreaDevManagerMain.h" + +class wxCreaDevManagerNewProjectDialog : public wxDialog +{ + DECLARE_EVENT_TABLE() + public: + wxCreaDevManagerNewProjectDialog( + wxWindow* parent, + ControlCreaDevManagerMain* controller, + wxWindowID id = wxID_ANY, + const wxString& caption = wxString("New Project"), + const wxPoint& position = wxDefaultPosition, + const wxSize& size = wxSize(400,300), + long style = wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER + ); + ~wxCreaDevManagerNewProjectDialog(); + bool Create( + wxWindow* parent, + wxWindowID id = wxID_ANY, + const wxString& caption = wxString("New Project"), + const wxPoint& position = wxDefaultPosition, + const wxSize& size = wxSize(400,300), + long style = wxDEFAULT_DIALOG_STYLE + ); + + protected: + void CreateControls(); + + void OnCreateProject(wxCommandEvent& event); + void OnCancel(wxCommandEvent& event); + void OnChooseLocation(wxCommandEvent& event); + + private: + wxStaticText* projectLocation; + wxTextCtrl* projectName; + wxTextCtrl* packageAuthor; + wxTextCtrl* packageDescription; + + ControlCreaDevManagerMain* Controller; + + +}; + +#endif /* WXCREADEVMANAGERNEWPROJECTDIALOG_H_ */ diff --git a/lib/creaDevManagerLib/wxCreaDevManagerTreeCtrl.cxx b/lib/creaDevManagerLib/wxCreaDevManagerTreeCtrl.cxx index 613112e..b325804 100644 --- a/lib/creaDevManagerLib/wxCreaDevManagerTreeCtrl.cxx +++ b/lib/creaDevManagerLib/wxCreaDevManagerTreeCtrl.cxx @@ -42,7 +42,7 @@ bool wxCreaDevManagerTreeCtrl::Create( return TRUE; } -void wxCreaDevManagerTreeCtrl::BuildTree(ModelCreaDevManagerTree& projectsTree) +void wxCreaDevManagerTreeCtrl::BuildTree(const ModelCreaDevManagerTree& projectsTree) { this->DeleteAllItems(); wxTreeItemId rootIndex = this-> AddRoot(_("Open Projects")); @@ -57,7 +57,7 @@ void wxCreaDevManagerTreeCtrl::BuildTree(ModelCreaDevManagerTree& projectsTree) this->Update(); } -void wxCreaDevManagerTreeCtrl::BuildTree(std::vector& projectsTree, wxTreeItemId parent) +void wxCreaDevManagerTreeCtrl::BuildTree(const std::vector& projectsTree, wxTreeItemId parent) { for (int i = 0; i < projectsTree.size(); i++) { diff --git a/lib/creaDevManagerLib/wxCreaDevManagerTreeCtrl.h b/lib/creaDevManagerLib/wxCreaDevManagerTreeCtrl.h index 151f3b7..f5671e0 100644 --- a/lib/creaDevManagerLib/wxCreaDevManagerTreeCtrl.h +++ b/lib/creaDevManagerLib/wxCreaDevManagerTreeCtrl.h @@ -38,9 +38,9 @@ public: const wxString &name=_("Projects tree") ); - void BuildTree(ModelCreaDevManagerTree& tree); + void BuildTree(const ModelCreaDevManagerTree& tree); private: - void BuildTree(std::vector& tree, wxTreeItemId parent); + void BuildTree(const std::vector& tree, wxTreeItemId parent); }; #endif /* WXCREADEVMANAGERTREECTRL_H_ */