]> Creatis software - crea.git/commitdiff
Feature #1711
authorDaniel Gonzalez <Daniel.Gonzalez@creatis.insa-lyon.fr>
Mon, 5 Nov 2012 15:01:12 +0000 (15:01 +0000)
committerDaniel Gonzalez <Daniel.Gonzalez@creatis.insa-lyon.fr>
Mon, 5 Nov 2012 15:01:12 +0000 (15:01 +0000)
CreaDevManager application implementation:

Implementation of New Project functionality

14 files changed:
lib/creaDevManagerLib/ControlCreaDevManagerMain.cpp [new file with mode: 0644]
lib/creaDevManagerLib/ControlCreaDevManagerMain.h [new file with mode: 0644]
lib/creaDevManagerLib/ControlCreaDevManagerProject.cpp [new file with mode: 0644]
lib/creaDevManagerLib/ControlCreaDevManagerProject.h [new file with mode: 0644]
lib/creaDevManagerLib/ModelCreaDevManagerTree.cpp
lib/creaDevManagerLib/ModelCreaDevManagerTreeNode.cpp
lib/creaDevManagerLib/ModelCreaDevManagerTreeNode.h
lib/creaDevManagerLib/creaDevManagerIds.h
lib/creaDevManagerLib/wxCreaDevManagerMainFrame.cxx
lib/creaDevManagerLib/wxCreaDevManagerMainFrame.h
lib/creaDevManagerLib/wxCreaDevManagerNewProjectDialog.cpp [new file with mode: 0644]
lib/creaDevManagerLib/wxCreaDevManagerNewProjectDialog.h [new file with mode: 0644]
lib/creaDevManagerLib/wxCreaDevManagerTreeCtrl.cxx
lib/creaDevManagerLib/wxCreaDevManagerTreeCtrl.h

diff --git a/lib/creaDevManagerLib/ControlCreaDevManagerMain.cpp b/lib/creaDevManagerLib/ControlCreaDevManagerMain.cpp
new file mode 100644 (file)
index 0000000..56337bd
--- /dev/null
@@ -0,0 +1,105 @@
+/*
+ * ControlCreaDevManagerMain.cpp
+ *
+ *  Created on: 5/11/2012
+ *      Author: daniel
+ */
+
+#include "ControlCreaDevManagerMain.h"
+#include "ModelCreaDevManagerTree.h"
+
+#include <cstdio>
+#include <fstream>
+
+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 (file)
index 0000000..786df73
--- /dev/null
@@ -0,0 +1,32 @@
+/*
+ * ControlCreaDevManagerMain.h
+ *
+ *  Created on: 5/11/2012
+ *      Author: daniel
+ */
+
+#ifndef CONTROLCREADEVMANAGERMAIN_H_
+#define CONTROLCREADEVMANAGERMAIN_H_
+
+#include <iostream>
+#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 (file)
index 0000000..9660328
--- /dev/null
@@ -0,0 +1,99 @@
+/*
+ * ControlCreaDevManagerProject.cpp
+ *
+ *  Created on: 5/11/2012
+ *      Author: daniel
+ */
+
+#include "ControlCreaDevManagerProject.h"
+
+#include <creaWx.h>
+#include <wx/dirdlg.h>
+#include <stdlib.h> // 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 (file)
index 0000000..a227ef7
--- /dev/null
@@ -0,0 +1,21 @@
+/*
+ * ControlCreaDevManagerProject.h
+ *
+ *  Created on: 5/11/2012
+ *      Author: daniel
+ */
+
+#ifndef CONTROLCREADEVMANAGERPROJECT_H_
+#define CONTROLCREADEVMANAGERPROJECT_H_
+
+#include <iostream>
+
+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_ */
index 64106b672c06401d47954b359b4d5ab16e50fda8..e98034617e12bd6ed5de23e2af358f9848426861 100644 (file)
@@ -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;
 }
index 8486f8054c37f34889aa595415c1d83d691b5e71..832f001b58de5ea91a35eb6e08e71856f412e3b1 100644 (file)
@@ -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>& ModelCreaDevManagerTreeNode::GetChildren()
+const std::vector<ModelCreaDevManagerTreeNode>& ModelCreaDevManagerTreeNode::GetChildren() const
 {
   return this->_children;
 }
index 0cf4a56241d7d10f0b66c9cd132bcce72bbdc489..61d9449557afc23896b053732b2e593eab768ad4 100644 (file)
@@ -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<ModelCreaDevManagerTreeNode>& GetChildren();
+    const std::string& GetPath() const;
+    const std::string& GetName() const;
+    const unsigned char& GetType() const;
+    const int& GetLevel() const;
+    const std::vector<ModelCreaDevManagerTreeNode>& GetChildren() const;
 
     void SetChildren(std::vector<ModelCreaDevManagerTreeNode>& children);
 
index 9937c17a85699b7cc19a52bf72fc628094c9b55a..a4c283cd162bcbf5c49ab5ea0f5cab10682dbdcb 100644 (file)
@@ -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_ */
index 03e4b10bd1a3ea4cd2382b15072774f38363f216..e69b26ad8f62453668939cc39c0f0693f343d137 100644 (file)
@@ -5,6 +5,8 @@
 
 #include "wxCreaDevManagerDescriptionPanel.h"
 #include "wxCreaDevManagerProjectActionsPanel.h"
+#include "wxCreaDevManagerNewProjectDialog.h"
+#include "ControlCreaDevManagerMain.h"
 
 #include <wx/dirdlg.h>
 
@@ -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();
   }
index cfdb1ddac5a936e5d4d7fb014ea0466085a8c482..c01d5465f840a147bdc51fd08e24b56a6cc2248d 100644 (file)
@@ -6,6 +6,7 @@
 #include <wx/aui/aui.h>
 
 #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 (file)
index 0000000..5fc6772
--- /dev/null
@@ -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 (file)
index 0000000..58f516b
--- /dev/null
@@ -0,0 +1,56 @@
+/*
+ * wxCreaDevManagerNewProjectDialog.h
+ *
+ *  Created on: 2/11/2012
+ *      Author: daniel
+ */
+
+#ifndef WXCREADEVMANAGERNEWPROJECTDIALOG_H_
+#define WXCREADEVMANAGERNEWPROJECTDIALOG_H_
+
+#include <creaWx.h>
+#include <wx/dialog.h>
+#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_ */
index 613112e4cd1c31e2e7dab891802de1e2466986c7..b325804b7e9dcbb322ed4dfa9c780aeccfe4540b 100644 (file)
@@ -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<ModelCreaDevManagerTreeNode>& projectsTree, wxTreeItemId parent)
+void wxCreaDevManagerTreeCtrl::BuildTree(const std::vector<ModelCreaDevManagerTreeNode>& projectsTree, wxTreeItemId parent)
 {
   for (int i = 0; i < projectsTree.size(); i++)
   {
index 151f3b7a0420ff7bcb1b5f135e82ba7562c7271f..f5671e0d340fa044fa532c1fa6a876dd5b62543b 100644 (file)
@@ -38,9 +38,9 @@ public:
     const wxString &name=_("Projects tree")
   );
 
-  void BuildTree(ModelCreaDevManagerTree& tree);
+  void BuildTree(const ModelCreaDevManagerTree& tree);
 private:
-  void BuildTree(std::vector<ModelCreaDevManagerTreeNode>& tree, wxTreeItemId parent);
+  void BuildTree(const std::vector<ModelCreaDevManagerTreeNode>& tree, wxTreeItemId parent);
 };
 
 #endif /* WXCREADEVMANAGERTREECTRL_H_ */