]> Creatis software - crea.git/blobdiff - lib/creaDevManagerLib/wxCDMPackageDescriptionPanel.cpp
Feature #1711
[crea.git] / lib / creaDevManagerLib / wxCDMPackageDescriptionPanel.cpp
index d6271ba80feda36af37263956e4ea90d49ec4934..00858bddbd9ccfb91596a91ac6b132a3bdcbba51 100644 (file)
 #include "creaDevManagerIds.h"
 #include "images/PkIcon64.xpm"
 
+#include "wxCDMNewBlackBoxDialog.h"
+#include <wx/textdlg.h>
+#include "CDMUtilities.h"
+
 BEGIN_EVENT_TABLE(wxCDMPackageDescriptionPanel, wxPanel)
 EVT_BUTTON(ID_BUTTON_PREV, wxCDMPackageDescriptionPanel::OnBtnReturn)
+EVT_BUTTON(ID_BUTTON_SET_AUTHOR, wxCDMPackageDescriptionPanel::OnBtnSetAuthor)
+EVT_BUTTON(ID_BUTTON_SET_VERSION, wxCDMPackageDescriptionPanel::OnBtnSetVersion)
+EVT_BUTTON(ID_BUTTON_SET_DESCRIPTION, wxCDMPackageDescriptionPanel::OnBtnSetDescription)
 EVT_HYPERLINK(ID_LINK_SELECT_BLACKBOX, wxCDMPackageDescriptionPanel::OnLnkBlackBoxSelect)
 EVT_BUTTON(ID_BUTTON_CREATE_BLACKBOX, wxCDMPackageDescriptionPanel::OnBtnCreateBlackBox)
 EVT_BUTTON(ID_BUTTON_EDIT_CMAKELISTSFILE, wxCDMPackageDescriptionPanel::OnBtnEditCMakeLists)
@@ -110,26 +117,26 @@ void wxCDMPackageDescriptionPanel::CreateControls()
 
   // author
   wxBoxSizer* pAuthorsz = new wxBoxSizer(wxHORIZONTAL);
-  wxStaticText* pAuthortc = new wxStaticText(propertiesPanel, wxID_ANY, crea::std2wx(this->package->GetAuthors()));
-  wxButton* pAuthorbt = new wxButton(propertiesPanel, ID_BUTTON_SET_VERSION, wxT("Change"));
+  this->authortc = new wxStaticText(propertiesPanel, wxID_ANY, crea::std2wx(this->package->GetAuthors()));
+  wxButton* pAuthorbt = new wxButton(propertiesPanel, ID_BUTTON_SET_AUTHOR, wxT("Change"));
   pAuthorbt->SetToolTip(wxT("Update the author/s of the package."));
-  pAuthorsz->Add(pAuthortc, 0, wxALIGN_CENTER_VERTICAL, 0);
+  pAuthorsz->Add(this->authortc, 1, wxALIGN_CENTER_VERTICAL);
   pAuthorsz->Add(pAuthorbt, 0, wxALIGN_CENTER | wxLEFT, 10);
 
   // version
   wxBoxSizer* pVersionsz = new wxBoxSizer(wxHORIZONTAL);
-  wxStaticText* pVersiontc = new wxStaticText(propertiesPanel, wxID_ANY, crea::std2wx(this->package->GetVersion()));
+  this->versiontc = new wxStaticText(propertiesPanel, wxID_ANY, crea::std2wx(this->package->GetVersion()));
   wxButton* pVersionbt = new wxButton(propertiesPanel, ID_BUTTON_SET_VERSION, wxT("Set"));
   pVersionbt->SetToolTip(wxT("Update the version of the package."));
-  pVersionsz->Add(pVersiontc, 0, wxALIGN_CENTER_VERTICAL, 0);
+  pVersionsz->Add(this->versiontc, 1, wxALIGN_CENTER_VERTICAL);
   pVersionsz->Add(pVersionbt, 0, wxALIGN_CENTER | wxLEFT, 10);
 
   // description
   wxBoxSizer* pDescriptionsz = new wxBoxSizer(wxHORIZONTAL);
-  wxStaticText* pDescriptiontc = new wxStaticText(propertiesPanel, wxID_ANY, crea::std2wx(this->package->GetDescription()));
-  wxButton* pDescriptionbt = new wxButton(propertiesPanel, ID_BUTTON_SET_VERSION, wxT("Change"));
+  this->descriptiontc = new wxStaticText(propertiesPanel, wxID_ANY, crea::std2wx(this->package->GetDescription()));
+  wxButton* pDescriptionbt = new wxButton(propertiesPanel, ID_BUTTON_SET_DESCRIPTION, wxT("Change"));
   pDescriptionbt->SetToolTip(wxT("Update the description of the project."));
-  pDescriptionsz->Add(pDescriptiontc, 0, wxALIGN_CENTER_VERTICAL, 0);
+  pDescriptionsz->Add(this->descriptiontc, 1, wxALIGN_CENTER_VERTICAL);
   pDescriptionsz->Add(pDescriptionbt, 0, wxALIGN_CENTER | wxLEFT, 10);
 
   propertiesGridSizer->Add(pAuthor, 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL);
@@ -139,10 +146,12 @@ void wxCDMPackageDescriptionPanel::CreateControls()
   propertiesGridSizer->Add(pDescription, 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL);
   propertiesGridSizer->Add(pDescriptionsz, 1, wxEXPAND);
 
+  propertiesGridSizer->AddGrowableCol(1,1);
+
   propertiesPanelSizer -> Add(propertiesGridSizer, 1, wxEXPAND);
   propertiesPanel->SetSizer(propertiesPanelSizer);
   propertiesPanelSizer->Fit(propertiesPanel);
-  propertiesBox->Add(propertiesPanel, 0, wxALL, 5);
+  propertiesBox->Add(propertiesPanel, 0, wxEXPAND | wxALL, 5);
 
   sizer->Add(propertiesBox, 0, wxEXPAND | wxALL, 10);
 
@@ -152,15 +161,21 @@ void wxCDMPackageDescriptionPanel::CreateControls()
   wxPanel* BBPanel = new wxPanel(this);
   wxBoxSizer* BBPanelSizer = new wxBoxSizer(wxVERTICAL);
 
-  std::vector<modelCDMBlackBox*> blackBoxes = this->package->GetBlackBoxes();
+
+  std::vector<modelCDMBlackBox*> blackBoxes = this->package->GetSrc()->GetBlackBoxes();
   for (int i = 0; i < blackBoxes.size(); i++)
     {
-      wxHyperlinkCtrl* pBBlk = new wxHyperlinkCtrl(BBPanel,ID_LINK_SELECT_BLACKBOX, crea::std2wx(blackBoxes[i]->GetName().c_str()), crea::std2wx(blackBoxes[i]->GetName().c_str()));
-      std::string tt = "Author: " + blackBoxes[i]->GetAuthors() + "\nDescription: " + blackBoxes[i]->GetDescription() + "\nCategories: " + blackBoxes[i]->GetCategories();
-      pBBlk->SetToolTip(crea::std2wx(tt));
-      pBBlk->Connect(wxEVT_ENTER_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMPackageDescriptionPanel::OnMouseEnter,NULL,this);
-      pBBlk->Connect(wxEVT_LEAVE_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMPackageDescriptionPanel::OnMouseExit,NULL,this);
-      BBPanelSizer -> Add(pBBlk, 0, wxALIGN_LEFT | wxALL, 5);
+
+      if(blackBoxes[i] != NULL)
+        {
+
+          wxHyperlinkCtrl* pBBlk = new wxHyperlinkCtrl(BBPanel,ID_LINK_SELECT_BLACKBOX, crea::std2wx(blackBoxes[i]->GetName().c_str()), crea::std2wx(blackBoxes[i]->GetName().c_str()));
+          std::string tt = "Author: " + blackBoxes[i]->GetAuthors() + "\nDescription: " + blackBoxes[i]->GetDescription() + "\nCategories: " + blackBoxes[i]->GetCategories();
+          pBBlk->SetToolTip(crea::std2wx(tt));
+          pBBlk->Connect(wxEVT_ENTER_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMPackageDescriptionPanel::OnMouseEnter,NULL,this);
+          pBBlk->Connect(wxEVT_LEAVE_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMPackageDescriptionPanel::OnMouseExit,NULL,this);
+          BBPanelSizer -> Add(pBBlk, 0, wxALIGN_LEFT | wxALL, 5);
+        }
     }
 
   BBPanel->SetSizer(BBPanelSizer);
@@ -204,22 +219,102 @@ void wxCDMPackageDescriptionPanel::OnBtnReturn(wxCommandEvent& event)
   wxPostEvent(this->GetParent(), *newEvent);
 }
 
+void wxCDMPackageDescriptionPanel::OnBtnSetAuthor(wxCommandEvent& event)
+{
+  //get author from user
+  wxTextEntryDialog* authDlg = new wxTextEntryDialog(
+      this,
+      wxT("Enter the new authors name. Separate each author with a '/'."),
+      wxT("Change Package Author - creaDevManager"),
+      crea::std2wx(this->package->GetAuthors()),
+      wxTE_MULTILINE | wxOK | wxCANCEL
+  );
+
+  if (authDlg->ShowModal() == wxID_OK)
+    {
+      std::string authorsStr = crea::wx2std(authDlg->GetValue());
+      //check name
+      if(authorsStr.size() > 0)
+        {
+          std::string* result;
+          if(!this->package->SetAuthors(authorsStr, result))
+            wxMessageBox(crea::std2wx(*result),_T("Change Package Author - Error!"),wxOK | wxICON_ERROR);
+        }
+      this->authortc->SetLabel(crea::std2wx(this->package->GetAuthors()));
+      this->authortc->GetParent()->GetSizer()->RecalcSizes();
+    }
+
+}
+
+void wxCDMPackageDescriptionPanel::OnBtnSetVersion(wxCommandEvent& event)
+{
+  //get version
+  wxString versionWx = wxGetTextFromUser(
+      wxT("Enter the new version name"),
+      wxT("Change Package Version - creaDevManager"),
+      crea::std2wx(this->package->GetVersion())
+  );
+  //check name
+  std::vector<std::string> parts;
+  CDMUtilities::splitter::split(parts, crea::wx2std(versionWx), " .", CDMUtilities::splitter::no_empties);
+  if(parts.size() == 3)
+    {
+      std::string* result;
+      if(!this->package->SetVersion(crea::wx2std(versionWx), result))
+        wxMessageBox(crea::std2wx(*result),_T("Change Package Version - Error!"),wxOK | wxICON_ERROR);
+    }
+  else
+    {
+      wxMessageBox(crea::std2wx("The version format is incorrect, please follow the following format:\nX.Y.Z\nX: Major Version\nY: Minor Version\nZ: Build Version"),_T("Set Project Version - Error!"),wxOK | wxICON_ERROR);
+    }
+  this->versiontc->SetLabel(crea::std2wx(this->package->GetVersion()));
+}
+
+void wxCDMPackageDescriptionPanel::OnBtnSetDescription(wxCommandEvent& event)
+{
+  //get description from user
+  wxTextEntryDialog* descDlg = new wxTextEntryDialog(
+      this,
+      wxT("Edit the package description."),
+      wxT("Change Package Description - creaDevManager"),
+      crea::std2wx(this->package->GetDescription()),
+      wxTE_MULTILINE | wxOK | wxCANCEL
+  );
+
+  if (descDlg->ShowModal() == wxID_OK)
+    {
+      std::string descriptionStr = crea::wx2std(descDlg->GetValue());
+      //check desc
+      if(descriptionStr.size() > 0)
+        {
+          std::string* result;
+          if(!this->package->SetDescription(descriptionStr, result))
+            wxMessageBox(crea::std2wx(*result),_T("Change Package Description - Error!"),wxOK | wxICON_ERROR);
+        }
+      this->descriptiontc->SetLabel(crea::std2wx(this->package->GetDescription()));
+      this->descriptiontc->GetParent()->GetSizer()->RecalcSizes();
+    }
+}
+
 void wxCDMPackageDescriptionPanel::OnLnkBlackBoxSelect(wxHyperlinkEvent& event)
 {
   int bbId = 0;
-  std::vector<modelCDMBlackBox*> bbs = this->package->GetBlackBoxes();
+  modelCDMBlackBox* bb;
+  std::vector<modelCDMBlackBox*> bbs = this->package->GetSrc()->GetBlackBoxes();
   for (int i = 0; i < bbs.size(); i++)
     {
       if(bbs[i]->GetName() == crea::wx2std(event.GetURL()))
         {
-          bbId = bbs[i]->GetId();
+          bbId = bbs[i]->GetHeaderFile()->GetId();
+          bb = bbs[i];
           break;
         }
     }
 
   wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_DISPLAY_CHANGED);
-  newEvent->SetInt(bbId);
-  newEvent->SetId(0);
+  newEvent->SetClientData(bb);
+  newEvent->SetId(1);
+  newEvent->SetString(wxT("blackbox"));
   wxPostEvent(this->GetParent(), *newEvent);
 
   wxCommandEvent* newEvent1 = new wxCommandEvent(wxEVT_COMMAND_LIST_ITEM_DESELECTED);
@@ -231,36 +326,85 @@ 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)
 {
-  //TODO: implement method
-  std::cerr << "Event OnBtnEditCMakeLists not implemented" << std::endl;
+  std::string* result;
+  if(!this->package->OpenCMakeListsFile(result))
+    wxMessageBox(crea::std2wx(*result),_T("Open CMakeLists File - Error!"),wxOK | wxICON_ERROR);
+
+  wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LIST_ITEM_DESELECTED);
+
+  if(this->package->GetCMakeLists() != NULL)
+    {
+      int CMId = this->package->GetCMakeLists()->GetId();
+      newEvent->SetInt(CMId);
+      newEvent->SetId(0);
+      wxPostEvent(this->GetParent(), *newEvent);
+    }
+
   event.Skip();
 }
 
 void wxCDMPackageDescriptionPanel::OnBtnOpenFolder(wxCommandEvent& event)
 {
-  //TODO: implement method
-  std::cerr << "Event OnBtnOpenFolder not implemented" << std::endl;
-  event.Skip();
+  std::string* result;
+  if(!this->package->OpenInFileExplorer(result))
+    wxMessageBox(crea::std2wx(*result),_T("Open Folder - Error!"),wxOK | wxICON_ERROR);
 }
 
 void wxCDMPackageDescriptionPanel::OnMouseEnter(wxMouseEvent& event)
 {
   wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LIST_ITEM_SELECTED);
   std::string BBName = crea::wx2std(((wxHyperlinkCtrl*)event.GetEventObject())->GetURL());
+
   int bbId = 0;
-  std::vector<modelCDMBlackBox*> boxes = this->package->GetBlackBoxes();
+  std::vector<modelCDMBlackBox*> boxes = this->package->GetSrc()->GetBlackBoxes();
   for (int i = 0; i < boxes.size(); i++)
     {
       if(boxes[i]->GetName() == BBName)
         {
-          bbId = boxes[i]->GetId();
+          bbId = boxes[i]->GetHeaderFile()->GetId();
           break;
         }
     }
@@ -275,12 +419,12 @@ void wxCDMPackageDescriptionPanel::OnMouseExit(wxMouseEvent& event)
   wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LIST_ITEM_DESELECTED);
   std::string BBName = crea::wx2std(((wxHyperlinkCtrl*)event.GetEventObject())->GetURL());
   int bbId = 0;
-  std::vector<modelCDMBlackBox*> boxes = this->package->GetBlackBoxes();
+  std::vector<modelCDMBlackBox*> boxes = this->package->GetSrc()->GetBlackBoxes();
   for (int i = 0; i < boxes.size(); i++)
     {
       if(boxes[i]->GetName() == BBName)
         {
-          bbId = boxes[i]->GetId();
+          bbId = boxes[i]->GetHeaderFile()->GetId();
           break;
         }
     }