]> Creatis software - crea.git/blobdiff - lib/creaDevManagerLib/wxCDMPackageDescriptionPanel.cpp
Feature #1711
[crea.git] / lib / creaDevManagerLib / wxCDMPackageDescriptionPanel.cpp
index a958d35d0d625087f13b6fa0cfb0613716611cb2..5a4f56ae64efd0ef0ff1340789b8ac4f67a1e876 100644 (file)
 
 #include "wxCDMPackageDescriptionPanel.h"
 
+#include "wxCDMMainFrame.h"
+
 #include "creaDevManagerIds.h"
 #include "images/PkIcon64.xpm"
 
 BEGIN_EVENT_TABLE(wxCDMPackageDescriptionPanel, wxPanel)
-EVT_MENU(ID_BUTTON_CREATE_BLACKBOX, wxCDMPackageDescriptionPanel::OnBtnCreateBlackBox)
-EVT_MENU(ID_BUTTON_EDIT_CMAKELISTSFILE, wxCDMPackageDescriptionPanel::OnBtnEditCMakeLists)
+EVT_BUTTON(ID_BUTTON_PREV, wxCDMPackageDescriptionPanel::OnBtnReturn)
+EVT_HYPERLINK(ID_LINK_SELECT_BLACKBOX, wxCDMPackageDescriptionPanel::OnLnkBlackBoxSelect)
+EVT_BUTTON(ID_BUTTON_CREATE_BLACKBOX, wxCDMPackageDescriptionPanel::OnBtnCreateBlackBox)
+EVT_BUTTON(ID_BUTTON_EDIT_CMAKELISTSFILE, wxCDMPackageDescriptionPanel::OnBtnEditCMakeLists)
+EVT_BUTTON(ID_BUTTON_OPEN_FOLDER, wxCDMPackageDescriptionPanel::OnBtnOpenFolder)
 END_EVENT_TABLE()
 
 wxCDMPackageDescriptionPanel::wxCDMPackageDescriptionPanel(
@@ -79,59 +84,142 @@ void wxCDMPackageDescriptionPanel::CreateControls()
 {
   wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
 
-  //Welcome
+  //Link to return
+  wxButton* returnbt = new wxButton(this, ID_BUTTON_PREV, wxT("Return to project"));
+  returnbt->SetToolTip(wxT("Return to the active project description."));
+  sizer->Add(returnbt, 0, wxALIGN_CENTER | wxALL, 5);
+
+  //Title
   sizer->Add(new wxStaticText(this, -1, _("Package")),0, wxALIGN_CENTER, 0);
 
   //Image
   sizer->Add(new wxStaticBitmap(this, -1, wxBitmap(PkIcon64)),0, wxALIGN_CENTER, 0);
 
-  //Project Name
+  //Package Name
   sizer->Add(new wxStaticText(this, -1, crea::std2wx(this->package->GetNamePackage())),0, wxALIGN_CENTER, 0);
 
-  //Project Properties
-  wxStaticBox* propertiesBox = new wxStaticBox(this, -1, _T("&Properties"));
-  wxStaticBoxSizer* propertiesBoxInnerSizer = new wxStaticBoxSizer(propertiesBox, wxVERTICAL);
-
-  wxFlexGridSizer* flexGridSizer = new wxFlexGridSizer(4, 2, 9, 15);
-
-  wxStaticText *pAuthor = new wxStaticText(this, -1, wxT("Author"));
-  wxStaticText *pAuthorEmail = new wxStaticText(this, -1, wxT("Author E-mail"));
-  wxStaticText *pVersion = new wxStaticText(this, -1, wxT("Version"));
-  wxStaticText *pDescription = new wxStaticText(this, -1, wxT("Description"));
-
-  wxTextCtrl *pAuthortc = new wxTextCtrl(this, -1, crea::std2wx(this->package->GetAuthors()));
-  wxTextCtrl *pAuthorEmailtc = new wxTextCtrl(this, -1, crea::std2wx(this->package->GetAuthorsEmail()));
-  wxTextCtrl *pVersiontc = new wxTextCtrl(this, -1, crea::std2wx(this->package->GetVersion()));
-  wxTextCtrl *pDescriptiontc = new wxTextCtrl(this, -1, crea::std2wx(this->package->GetDescription()));
-
-  flexGridSizer->Add(pAuthor, 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL);
-  flexGridSizer->Add(pAuthortc, 1, wxEXPAND);
-  flexGridSizer->Add(pAuthorEmail, 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL);
-  flexGridSizer->Add(pAuthorEmailtc, 1, wxEXPAND);
-  flexGridSizer->Add(pVersion, 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL);
-  flexGridSizer->Add(pVersiontc, 1, wxEXPAND);
-  flexGridSizer->Add(pDescription, 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL);
-  flexGridSizer->Add(pDescriptiontc, 1, wxEXPAND);
-
-  propertiesBoxInnerSizer -> Add(flexGridSizer, 0, wxEXPAND);
-  sizer -> Add(propertiesBoxInnerSizer, 1, wxEXPAND | wxALL, 20);
+  //Package Properties
+  wxStaticBoxSizer* propertiesBox = new wxStaticBoxSizer(wxVERTICAL, this, wxT("&Properties"));
+  wxPanel* propertiesPanel = new wxPanel(this);
+  wxBoxSizer* propertiesPanelSizer = new wxBoxSizer(wxVERTICAL);
+  wxFlexGridSizer* propertiesGridSizer = new wxFlexGridSizer(4, 2, 9, 15);
+
+  wxStaticText *pAuthor = new wxStaticText(propertiesPanel, -1, wxT("Author"));
+  wxStaticText *pVersion = new wxStaticText(propertiesPanel, -1, wxT("Version"));
+  wxStaticText *pDescription = new wxStaticText(propertiesPanel, -1, wxT("Description"));
+
+  // 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"));
+  pAuthorbt->SetToolTip(wxT("Update the author/s of the package."));
+  pAuthorsz->Add(pAuthortc, 0, wxALIGN_CENTER_VERTICAL, 0);
+  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()));
+  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(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"));
+  pDescriptionbt->SetToolTip(wxT("Update the description of the project."));
+  pDescriptionsz->Add(pDescriptiontc, 0, wxALIGN_CENTER_VERTICAL, 0);
+  pDescriptionsz->Add(pDescriptionbt, 0, wxALIGN_CENTER | wxLEFT, 10);
+
+  propertiesGridSizer->Add(pAuthor, 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL);
+  propertiesGridSizer->Add(pAuthorsz, 1, wxEXPAND);
+  propertiesGridSizer->Add(pVersion, 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL);
+  propertiesGridSizer->Add(pVersionsz, 1, wxEXPAND);
+  propertiesGridSizer->Add(pDescription, 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL);
+  propertiesGridSizer->Add(pDescriptionsz, 1, wxEXPAND);
+
+  propertiesPanelSizer -> Add(propertiesGridSizer, 1, wxEXPAND);
+  propertiesPanel->SetSizer(propertiesPanelSizer);
+  propertiesPanelSizer->Fit(propertiesPanel);
+  propertiesBox->Add(propertiesPanel, 0, wxALL, 5);
+
+  sizer->Add(propertiesBox, 0, wxEXPAND | wxALL, 10);
+
+  //Black Boxes
+  wxStaticBoxSizer* BBBox = new wxStaticBoxSizer(wxVERTICAL, this, wxT("A&vailable Black Boxes"));
+  BBBox->GetStaticBox()->SetToolTip(wxT("Select any of the available black boxes to see its details or modify them."));
+  wxPanel* BBPanel = new wxPanel(this);
+  wxBoxSizer* BBPanelSizer = new wxBoxSizer(wxVERTICAL);
+
+  std::vector<modelCDMBlackBox*> blackBoxes = this->package->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));
+      BBPanelSizer -> Add(pBBlk, 0, wxALIGN_LEFT | wxALL, 5);
+    }
+
+  BBPanel->SetSizer(BBPanelSizer);
+  BBPanelSizer->Fit(BBPanel);
+  BBBox->Add(BBPanel, 0, wxALL, 5);
+
+  sizer -> Add(BBBox, 0, wxEXPAND | wxALL, 10);
 
   //Actions
-  wxStaticBox* actionsBox = new wxStaticBox(this, -1, _T("&Actions"));
-  wxStaticBoxSizer* actionsBoxInnerSizer = new wxStaticBoxSizer(actionsBox, wxVERTICAL);
-  sizer -> Add(actionsBoxInnerSizer, 1, wxEXPAND | wxALL, 20);
-
-  actionsBoxInnerSizer->Add(new wxButton(this, ID_BUTTON_CREATE_BLACKBOX, _T("Create Black Box")), 0, wxEXPAND | wxRIGHT | wxLEFT, 20);
-
-  actionsBoxInnerSizer->Add(new wxButton(this, ID_BUTTON_EDIT_CMAKELISTSFILE, _T("Edit CMakeLists File")), 0, wxEXPAND | wxRIGHT | wxLEFT, 20);
+  wxStaticBoxSizer* actionsBox = new wxStaticBoxSizer(wxHORIZONTAL, this, wxT("&Actions"));
+  wxPanel* actionsPanel = new wxPanel(this);
+  wxBoxSizer* actionsPanelSizer = new wxBoxSizer(wxHORIZONTAL);
+
+  wxButton* createBBbt = new wxButton(actionsPanel, ID_BUTTON_CREATE_BLACKBOX, _T("Create Black Box"));
+  createBBbt->SetToolTip(wxT("Create a new black box for the active project inside this package."));
+  actionsPanelSizer->Add(createBBbt, 0, wxALL, 5);
+  wxButton* editCMakebt = new wxButton(actionsPanel, ID_BUTTON_EDIT_CMAKELISTSFILE, _T("Edit CMakeLists File"));
+  editCMakebt->SetToolTip(wxT("Open the system default text editor to edit the package's CMakeLists.txt file."));
+  actionsPanelSizer->Add(editCMakebt, 0, wxALL, 5);
+  wxButton* openFolderbt = new wxButton(actionsPanel, ID_BUTTON_OPEN_FOLDER, _T("Open Package Folder"));
+  openFolderbt->SetToolTip(wxT("Open the package folder in the file explorer."));
+  actionsPanelSizer->Add(openFolderbt, 0, wxALL, 5);
+
+  actionsPanel->SetSizer(actionsPanelSizer);
+  actionsPanelSizer->Fit(actionsPanel);
+  actionsBox->Add(actionsPanel, 0, wxEXPAND);
+  sizer -> Add(actionsBox, 0, wxEXPAND | wxALL, 10);
 
   //Assign sizer
-  actionsBoxInnerSizer->SetSizeHints(this);
-
   SetSizer(sizer);
   sizer->SetSizeHints(this);
 }
 
+void wxCDMPackageDescriptionPanel::OnBtnReturn(wxCommandEvent& event)
+{
+  wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_DISPLAY_CHANGED);
+  newEvent->SetInt(((wxCDMMainFrame*)this->GetParent())->GetModel()->GetProject()->GetId());
+  newEvent->SetId(0);
+  wxPostEvent(this->GetParent(), *newEvent);
+}
+
+void wxCDMPackageDescriptionPanel::OnLnkBlackBoxSelect(wxHyperlinkEvent& event)
+{
+  int bbId = 0;
+  std::vector<modelCDMBlackBox*> bbs = this->package->GetBlackBoxes();
+  for (int i = 0; i < bbs.size(); i++)
+    {
+      if(bbs[i]->GetName() == crea::wx2std(event.GetURL()))
+        {
+          bbId = bbs[i]->GetId();
+          break;
+        }
+    }
+
+  wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_DISPLAY_CHANGED);
+  newEvent->SetInt(bbId);
+  newEvent->SetId(0);
+  wxPostEvent(this->GetParent(), *newEvent);
+
+}
+
 void wxCDMPackageDescriptionPanel::OnBtnCreateBlackBox(wxCommandEvent& event)
 {
   //TODO: implement method
@@ -145,3 +233,11 @@ void wxCDMPackageDescriptionPanel::OnBtnEditCMakeLists(wxCommandEvent& event)
   std::cerr << "Event OnBtnEditCMakeLists not implemented" << std::endl;
   event.Skip();
 }
+
+void wxCDMPackageDescriptionPanel::OnBtnOpenFolder(wxCommandEvent& event)
+{
+  //TODO: implement method
+  std::cerr << "Event OnBtnOpenFolder not implemented" << std::endl;
+  event.Skip();
+}
+