]> Creatis software - crea.git/blobdiff - lib/creaDevManagerLib/wxCreaDevManagerMainFrame.cxx
Feature #1711
[crea.git] / lib / creaDevManagerLib / wxCreaDevManagerMainFrame.cxx
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();
   }