]> Creatis software - crea.git/blobdiff - lib/creaDevManagerLib/wxCDMLibDescriptionPanel.cpp
Feature #1711
[crea.git] / lib / creaDevManagerLib / wxCDMLibDescriptionPanel.cpp
index cdefeed299e315e21309543469b58e80f95ef8f2..d9392aac288aa60cc473d0ebe084bad8e6270174 100644 (file)
 
 #include "wxCDMLibDescriptionPanel.h"
 
+#include "wxCDMMainFrame.h"
+
 #include "creaDevManagerIds.h"
-#include "images/LbIcon.xpm"
+#include "images/LbIcon64.xpm"
 
 BEGIN_EVENT_TABLE(wxCDMLibDescriptionPanel, wxPanel)
-EVT_MENU(ID_BUTTON_CREATE_LIBRARY, wxCDMLibDescriptionPanel::OnBtnCreateLibrary)
-EVT_MENU(ID_BUTTON_EDIT_CMAKELISTSFILE, wxCDMLibDescriptionPanel::OnBtnEditCMakeLists)
+EVT_BUTTON(ID_BUTTON_CREATE_LIBRARY, wxCDMLibDescriptionPanel::OnBtnCreateLibrary)
+EVT_BUTTON(ID_BUTTON_EDIT_CMAKELISTSFILE, wxCDMLibDescriptionPanel::OnBtnEditCMakeLists)
 END_EVENT_TABLE()
 
 wxCDMLibDescriptionPanel::wxCDMLibDescriptionPanel(
@@ -83,7 +85,7 @@ void wxCDMLibDescriptionPanel::CreateControls()
   sizer->Add(new wxStaticText(this, -1, _("Libraries")),0, wxALIGN_CENTER, 0);
 
   //Image
-  sizer->Add(new wxStaticBitmap(this, -1, wxBitmap(LbIcon)),0, wxALIGN_CENTER, 0);
+  sizer->Add(new wxStaticBitmap(this, -1, wxBitmap(LbIcon64)),0, wxALIGN_CENTER, 0);
 
   //Actions
   wxStaticBox* actionsBox = new wxStaticBox(this, -1, _T("&Actions"));
@@ -105,6 +107,39 @@ void wxCDMLibDescriptionPanel::OnBtnCreateLibrary(wxCommandEvent& event)
   //TODO: implement method
   std::cerr << "Event OnBtnCreateLibrary not implemented" << std::endl;
   event.Skip();
+
+
+  //get name
+  wxString libraryName = wxGetTextFromUser(
+      _T("Enter the new library name"),
+      _T("New Library - creaDevManager"),
+      _T("")
+  );
+  //check name
+  if(libraryName.Len() > 0)
+    {
+      std::string* result;
+      //create library
+      modelCDMIProjectTreeNode* library = this->lib->CreateLibrary(crea::wx2std(libraryName),result);
+      //check library created
+      if(library == NULL)
+        {
+          wxMessageBox(crea::std2wx(*result),_T("New Library - Error!"),wxOK | wxICON_ERROR);
+          event.Skip();
+          return;
+        }
+      wxMessageBox(crea::std2wx("Library successfully created."),_T("New Library - 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(library->GetId());
+      wxPostEvent(this->GetParent(), *newEvent);
+      event.Skip();
+    }
 }
 
 void wxCDMLibDescriptionPanel::OnBtnEditCMakeLists(wxCommandEvent& event)