]> Creatis software - crea.git/blobdiff - lib/creaDevManagerLib/wxCDMPackageDescriptionPanel.cpp
Feature #1711
[crea.git] / lib / creaDevManagerLib / wxCDMPackageDescriptionPanel.cpp
index 4411c9eeb5cc9963864c7c8e4090aa35b64cd413..00858bddbd9ccfb91596a91ac6b132a3bdcbba51 100644 (file)
@@ -39,6 +39,7 @@
 #include "creaDevManagerIds.h"
 #include "images/PkIcon64.xpm"
 
+#include "wxCDMNewBlackBoxDialog.h"
 #include <wx/textdlg.h>
 #include "CDMUtilities.h"
 
@@ -325,9 +326,45 @@ void wxCDMPackageDescriptionPanel::OnLnkBlackBoxSelect(wxHyperlinkEvent& event)
 
 void wxCDMPackageDescriptionPanel::OnBtnCreateBlackBox(wxCommandEvent& event)
 {
-  //TODO: implement method
-  std::cerr << "Event OnBtnCreateBlackBox not implemented" << std::endl;
-  event.Skip();
+
+  wxCDMNewBlackBoxDialog* dialog = new wxCDMNewBlackBoxDialog(this);
+  long userResponse;
+  userResponse = dialog->ShowModal();
+
+  if(userResponse == wxID_FORWARD)
+    {
+      std::string* result;
+      //create black box
+      modelCDMIProjectTreeNode* blackBox = this->package->CreateBlackBox(
+          result,
+          crea::wx2std(dialog->GetBlackBoxName()),
+          crea::wx2std(dialog->GetBlackBoxType()),
+          crea::wx2std(dialog->GetBlackBoxFormat()),
+          crea::wx2std(dialog->GetBlackBoxCategories()),
+          crea::wx2std(dialog->GetBlackBoxAuthor()),
+          crea::wx2std(dialog->GetBlackBoxAuthorEmail()),
+          crea::wx2std(dialog->GetBlackBoxDescription())
+      );
+      //check black box created
+      if(blackBox == NULL)
+        {
+          wxMessageBox(crea::std2wx(*result),_T("New Black Box - Error!"),wxOK | wxICON_ERROR);
+          return;
+        }
+      wxMessageBox(crea::std2wx("Black box successfully created."),_T("New Black Box - 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->SetId(1);
+      newEvent->SetInt(blackBox->GetId());
+      newEvent->SetString(wxT("blackbox"));
+      newEvent->SetClientData(blackBox);
+      wxPostEvent(this->GetParent(), *newEvent);
+    }
 }
 
 void wxCDMPackageDescriptionPanel::OnBtnEditCMakeLists(wxCommandEvent& event)