]> Creatis software - crea.git/blobdiff - lib/creaDevManagerLib/wxCDMAppliDescriptionPanel.cpp
Feature #1711
[crea.git] / lib / creaDevManagerLib / wxCDMAppliDescriptionPanel.cpp
index 617f39fbb4e725aa59b35da0fd10207777122f3f..9d815d224db30a7d351e20426e27317f3529a00b 100644 (file)
 #include "wxCDMAppliDescriptionPanel.h"
 
 #include "creaDevManagerIds.h"
+
+#include "wxCDMMainFrame.h"
 #include "images/ApIcon64.xpm"
 
 BEGIN_EVENT_TABLE(wxCDMAppliDescriptionPanel, wxPanel)
-EVT_MENU(ID_BUTTON_CREATE_APPLICATION, wxCDMAppliDescriptionPanel::OnBtnCreateApplication)
-EVT_MENU(ID_BUTTON_EDIT_CMAKELISTSFILE, wxCDMAppliDescriptionPanel::OnBtnEditCMakeLists)
+EVT_BUTTON(ID_BUTTON_CREATE_APPLICATION, wxCDMAppliDescriptionPanel::OnBtnCreateApplication)
+EVT_BUTTON(ID_BUTTON_EDIT_CMAKELISTSFILE, wxCDMAppliDescriptionPanel::OnBtnEditCMakeLists)
 END_EVENT_TABLE()
 
 wxCDMAppliDescriptionPanel::wxCDMAppliDescriptionPanel(
@@ -102,9 +104,37 @@ void wxCDMAppliDescriptionPanel::CreateControls()
 
 void wxCDMAppliDescriptionPanel::OnBtnCreateApplication(wxCommandEvent& event)
 {
-  //TODO: implement method
-  std::cerr << "Event OnBtnCreateApplication not implemented" << std::endl;
-  event.Skip();
+  //get name
+  wxString applicationName = wxGetTextFromUser(
+      _T("Enter the new application name"),
+      _T("New Application - creaDevManager"),
+      _T("")
+  );
+  //check name
+  if(applicationName.Len() > 0)
+    {
+      std::string* result;
+      //create library
+      modelCDMIProjectTreeNode* application = this->appli->CreateApplication(crea::wx2std(applicationName),result);
+      //check library created
+      if(application == NULL)
+        {
+          wxMessageBox(crea::std2wx(*result),_T("New Application - Error!"),wxOK | wxICON_ERROR);
+          event.Skip();
+          return;
+        }
+      wxMessageBox(crea::std2wx("Application successfully created."),_T("New Application - Success!"),wxOK | wxICON_INFORMATION);
+
+      //refreshing tree and description
+      //send event instead of calling parent to avoid crashing
+
+      ((wxCDMMainFrame*)this->GetParent())->RefreshProject();
+
+      wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_DISPLAY_CHANGED);
+      newEvent->SetInt(application->GetId());
+      wxPostEvent(this->GetParent(), *newEvent);
+      event.Skip();
+    }
 }
 
 void wxCDMAppliDescriptionPanel::OnBtnEditCMakeLists(wxCommandEvent& event)