]> Creatis software - crea.git/blobdiff - lib/creaDevManagerLib/wxCDMMainFrame.cpp
Feature #1711
[crea.git] / lib / creaDevManagerLib / wxCDMMainFrame.cpp
index 8050bf924cf503f16d221e46d58830d9bf224fc5..28d9a5d0e7860f3fe791adb9669577a4394a17eb 100755 (executable)
@@ -190,18 +190,9 @@ void wxCDMMainFrame::CreateControls()
 
 
 
-  panel_ProjectActions = new wxCDMProjectActionsPanel(
-      this,
-      ID_WINDOW_PROJ_ACTIONS,
-      wxT("Project Actions Panel"),
-      wxDefaultPosition,
-      wxSize(600,200),
-      0
-  );
-  panel_ProjectActions->SetMinSize(wxSize(500, 100));
+
 
   auiManager.AddPane(tree_Projects, wxLEFT, wxT("Projects Tree"));
-  auiManager.AddPane(panel_ProjectActions, wxBOTTOM, wxT("Project Actions"));
   auiManager.AddPane(panel_Properties, wxCENTER, wxT("Properties"));
 
   auiManager.Update();
@@ -212,6 +203,8 @@ void wxCDMMainFrame::CreateControls()
 //File menu
 void wxCDMMainFrame::OnMenuNewProject(wxCommandEvent& event)
 {
+  std::string* result;
+
   wxCDMNewProjectDialog* dialog = new wxCDMNewProjectDialog(this);
   long userResponse;
   userResponse = dialog->ShowModal();
@@ -219,7 +212,17 @@ void wxCDMMainFrame::OnMenuNewProject(wxCommandEvent& event)
   if(userResponse == wxID_FORWARD)
     {
       //create project
-      std::string* result;
+      if(this->model->GetProject() != NULL)
+        {
+          if(!this->model->CloseProject(result))
+            {
+              std::cout << "error closing project: " << *result << std::endl;
+              wxMessageBox(crea::std2wx(*result),_T("New Project - Error!"),wxOK | wxICON_ERROR);
+              event.Skip();
+              return;
+            }
+        }
+
       if(!this->model->CreateProject(
           crea::wx2std(dialog->GetProjectName()),
           crea::wx2std(dialog->GetProjectLocation()),
@@ -228,6 +231,7 @@ void wxCDMMainFrame::OnMenuNewProject(wxCommandEvent& event)
           crea::wx2std(dialog->GetPackageDescription())
       ))
         {
+          std::cout << "error opening project: " << *result << std::endl;
           wxMessageBox(crea::std2wx(*result),_T("New Project - Error!"),wxOK | wxICON_ERROR);
           event.Skip();
           return;
@@ -238,8 +242,12 @@ void wxCDMMainFrame::OnMenuNewProject(wxCommandEvent& event)
       tree_Projects->SelectItem(this->model->GetProject()->GetId());
 
       //change description panel
-      auiManager.DetachPane(this->panel_Properties);
-      this->panel_Properties->Destroy();
+      if(this->panel_Properties != NULL)
+        {
+          auiManager.DetachPane(this->panel_Properties);
+          this->panel_Properties->Destroy();
+        }
+
       this->panel_Properties = new wxCDMProjectDescriptionPanel(
           this,
           this->model->GetProject(),
@@ -248,9 +256,27 @@ void wxCDMMainFrame::OnMenuNewProject(wxCommandEvent& event)
           wxDefaultPosition,
           wxSize(300, 400),
           0);
+      //show projectactions panel
+      if(this->panel_ProjectActions != NULL)
+        {
+          auiManager.DetachPane(this->panel_Properties);
+          this->panel_ProjectActions->Destroy();
+        }
+
+      panel_ProjectActions = new wxCDMProjectActionsPanel(
+          this,
+          ID_WINDOW_PROJ_ACTIONS,
+          wxT("Project Actions Panel"),
+          wxDefaultPosition,
+          wxSize(600,200),
+          0
+      );
+      panel_ProjectActions->SetMinSize(wxSize(500, 100));
+
+
       auiManager.AddPane(panel_Properties, wxCENTER, wxT("Properties"));
+      auiManager.AddPane(panel_ProjectActions, wxBOTTOM, wxT("Project Actions"));
 
-      //TODO: change project's actions panel
       auiManager.Update();
 
       wxMessageBox(_T("New Project created!"),_T("New Project - Success!"), wxOK | wxICON_INFORMATION);
@@ -260,6 +286,8 @@ void wxCDMMainFrame::OnMenuNewProject(wxCommandEvent& event)
 }
 void wxCDMMainFrame::OnMenuOpenProject(wxCommandEvent& event)
 {
+  std::string* result;
+
   long style = wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST;
   wxDirDialog* FD = new wxDirDialog(this, wxT("Select the project directory"), wxT(""), style);
   long userResponse = FD->ShowModal();
@@ -273,19 +301,40 @@ void wxCDMMainFrame::OnMenuOpenProject(wxCommandEvent& event)
 
 
       //populate model
-      std::string* result;
+      if(this->model->GetProject() != NULL)
+        {
+          std::cout << "Project not null, closing it" << std::endl;
+          if(!this->model->CloseProject(result))
+            {
+              std::cout << "error closing project: " << *result << std::endl;
+              wxMessageBox(crea::std2wx(result->c_str()),_T("New Project - Error!"),wxOK | wxICON_ERROR);
+              event.Skip();
+              return;
+            }
+        }
+
       if (!this->model->OpenProject(path, result))
         {
+          std::cout << "error opening project: " << *result << std::endl;
           wxMessageBox( crea::std2wx(result->c_str()), wxT("Open Project - Error"), wxICON_ERROR);
+          event.Skip();
+          return;
         };
 
+      std::cout << "building ui" << std::endl;
+
+
       //populate tree control
       tree_Projects->BuildTree(this->model->GetProject());
       tree_Projects->SelectItem(this->model->GetProject()->GetId());
 
       //change description panel
-      auiManager.DetachPane(this->panel_Properties);
-      this->panel_Properties->Destroy();
+      if(this->panel_Properties != NULL)
+        {
+          auiManager.DetachPane(this->panel_Properties);
+          this->panel_Properties->Destroy();
+        }
+
       this->panel_Properties = new wxCDMProjectDescriptionPanel(
           this,
           this->model->GetProject(),
@@ -293,11 +342,29 @@ void wxCDMMainFrame::OnMenuOpenProject(wxCommandEvent& event)
           wxT("Description Panel"),
           wxDefaultPosition,
           wxSize(300, 400),
-          0);
+          0
+      );
+
+      //change project's actions panel
+      if(this->panel_ProjectActions!= NULL)
+        {
+          auiManager.DetachPane(this->panel_ProjectActions);
+          this->panel_ProjectActions->Destroy();
+        }
+      panel_ProjectActions = new wxCDMProjectActionsPanel(
+          this,
+          ID_WINDOW_PROJ_ACTIONS,
+          wxT("Project Actions Panel"),
+          wxDefaultPosition,
+          wxSize(600,200),
+          0
+      );
+      panel_ProjectActions->SetMinSize(wxSize(500, 100));
+
 
       auiManager.AddPane(panel_Properties, wxCENTER, wxT("Properties"));
+      auiManager.AddPane(panel_ProjectActions, wxBOTTOM, wxT("Project Actions"));
 
-      //TODO: change project's actions panel
       auiManager.Update();
     }
 
@@ -313,9 +380,33 @@ void wxCDMMainFrame::OnMenuCloseProject(wxCommandEvent& event)
   std::string* result;
   if(!this->model->CloseProject(result))
     {
+      std::cout << "error closing project: " << *result << std::endl;
       wxMessageBox( crea::std2wx(result->c_str()), wxT("Close Project - Error"), wxICON_ERROR);
     }
   tree_Projects->BuildTree(this->model->GetProject());
+
+  if(this->panel_Properties != NULL)
+    {
+      auiManager.DetachPane(this->panel_Properties);
+      this->panel_Properties->Destroy();
+    }
+  if(this->panel_ProjectActions != NULL)
+    {
+      auiManager.DetachPane(this->panel_ProjectActions);
+      this->panel_ProjectActions->Destroy();
+    }
+
+  this->panel_Properties = new wxCDMMainDescriptionPanel(
+      this,
+      ID_WINDOW_PROPERTIES,
+      wxT("Description Panel"),
+      wxDefaultPosition,
+      wxSize(300, 400),
+      0
+  );
+
+  auiManager.AddPane(panel_Properties, wxCENTER, wxT("Properties"));
+
   auiManager.Update();
   event.Skip();
 }