X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=lib%2FcreaDevManagerLib%2FwxCDMPackageDescriptionPanel.cpp;h=d4348fa152fe9d4956fc3bf61d049d391550afa0;hb=752294dd30e2ee94f38be513d441f4716509ce13;hp=99367d7eeb3487a1392295d71317439538e2d2d0;hpb=609d8d48cae96384e664ec6b000e8ecfcbad6459;p=crea.git diff --git a/lib/creaDevManagerLib/wxCDMPackageDescriptionPanel.cpp b/lib/creaDevManagerLib/wxCDMPackageDescriptionPanel.cpp index 99367d7..d4348fa 100644 --- a/lib/creaDevManagerLib/wxCDMPackageDescriptionPanel.cpp +++ b/lib/creaDevManagerLib/wxCDMPackageDescriptionPanel.cpp @@ -39,9 +39,15 @@ #include "creaDevManagerIds.h" #include "images/PkIcon64.xpm" +#include "wxCDMNewBlackBoxDialog.h" #include #include "CDMUtilities.h" +#include +#include "modelCDMCMakeListsFile.h" +#include "wxCDMPackageHelpDialog.h" + + BEGIN_EVENT_TABLE(wxCDMPackageDescriptionPanel, wxPanel) EVT_BUTTON(ID_BUTTON_PREV, wxCDMPackageDescriptionPanel::OnBtnReturn) EVT_BUTTON(ID_BUTTON_SET_AUTHOR, wxCDMPackageDescriptionPanel::OnBtnSetAuthor) @@ -95,14 +101,19 @@ void wxCDMPackageDescriptionPanel::CreateControls() 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); - - //Package Name - sizer->Add(new wxStaticText(this, -1, crea::std2wx(this->package->GetNamePackage())),0, wxALIGN_CENTER, 0); + //Header + wxBoxSizer* headerSizer = new wxBoxSizer(wxHORIZONTAL); + { + //Image + headerSizer->Add(new wxStaticBitmap(this, -1, wxBitmap(PkIcon64)),0, wxALIGN_CENTER, 0); + wxBoxSizer* textSizer = new wxBoxSizer(wxVERTICAL); + //Title + textSizer->Add(new wxStaticText(this, -1, _("Package")),0, wxALIGN_LEFT, 0); + //Package Name + textSizer->Add(new wxStaticText(this, -1, crea::std2wx(this->package->GetNamePackage())),0, wxALIGN_LEFT, 0); + headerSizer->Add(textSizer, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5); + } + sizer->Add(headerSizer, 0, wxALIGN_CENTER); //Package Properties wxStaticBoxSizer* propertiesBox = new wxStaticBoxSizer(wxVERTICAL, this, wxT("&Properties")); @@ -160,48 +171,66 @@ void wxCDMPackageDescriptionPanel::CreateControls() wxPanel* BBPanel = new wxPanel(this); wxBoxSizer* BBPanelSizer = new wxBoxSizer(wxVERTICAL); - std::vector blackBoxes = this->package->GetBlackBoxes(); + + std::vector 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())); + pBBlk->SetWindowStyle(wxALIGN_LEFT); + 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, wxEXPAND | wxALL, 5); + } } BBPanel->SetSizer(BBPanelSizer); BBPanelSizer->Fit(BBPanel); - BBBox->Add(BBPanel, 0, wxALL, 5); - + BBBox->Add(BBPanel, 1, wxEXPAND | wxALL, 5); sizer -> Add(BBBox, 0, wxEXPAND | wxALL, 10); //Actions wxStaticBoxSizer* actionsBox = new wxStaticBoxSizer(wxHORIZONTAL, this, wxT("&Actions")); wxPanel* actionsPanel = new wxPanel(this); wxBoxSizer* actionsPanelSizer = new wxBoxSizer(wxHORIZONTAL); + //actionsGrid Sizer + wxFlexGridSizer* actionsGridSizer = new wxFlexGridSizer(2, 2, 9, 15); - wxButton* createBBbt = new wxButton(actionsPanel, ID_BUTTON_CREATE_BLACKBOX, _T("Create Black Box")); + wxButton* createBBbt = new wxButton(actionsPanel, ID_BUTTON_CREATE_BLACKBOX, _T("A. 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")); + actionsGridSizer->Add(createBBbt, 1, wxALL | wxEXPAND, 5); + wxButton* editCMakebt = new wxButton(actionsPanel, ID_BUTTON_EDIT_CMAKELISTSFILE, _T("B. Edit CMakeLists File")); editCMakebt->SetToolTip(wxT("Open the system default text editor to edit the package's CMakeLists.txt file.")); editCMakebt->Connect(wxEVT_ENTER_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMPackageDescriptionPanel::OnCMakeMouseEnter,NULL,this); editCMakebt->Connect(wxEVT_LEAVE_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMPackageDescriptionPanel::OnCMakeMouseExit,NULL,this); - actionsPanelSizer->Add(editCMakebt, 0, wxALL, 5); - wxButton* openFolderbt = new wxButton(actionsPanel, ID_BUTTON_OPEN_FOLDER, _T("Open Package Folder")); + actionsGridSizer->Add(editCMakebt, 1, wxALL | wxEXPAND, 5); + wxButton* openFolderbt = new wxButton(actionsPanel, ID_BUTTON_OPEN_FOLDER, _T("C. Open Package Folder")); openFolderbt->SetToolTip(wxT("Open the package folder in the file explorer.")); - actionsPanelSizer->Add(openFolderbt, 0, wxALL, 5); + actionsGridSizer->Add(openFolderbt, 1, wxALL | wxEXPAND, 5); + actionsGridSizer->AddGrowableCol(0,1); + actionsGridSizer->AddGrowableCol(1,1); + + actionsPanelSizer->Add(actionsGridSizer, 1, wxEXPAND, 0); actionsPanel->SetSizer(actionsPanelSizer); actionsPanelSizer->Fit(actionsPanel); - actionsBox->Add(actionsPanel, 0, wxEXPAND); + actionsBox->Add(actionsPanel, 1, wxEXPAND); sizer -> Add(actionsBox, 0, wxEXPAND | wxALL, 10); //Assign sizer SetSizer(sizer); sizer->SetSizeHints(this); + + if (((wxCDMMainFrame*)this->GetParent())->isHelp()) + { + wxCDMPackageHelpDialog* helpDialog = new wxCDMPackageHelpDialog(this->GetParent(), this->package, wxID_ANY); + helpDialog->Show(true); + } } void wxCDMPackageDescriptionPanel::OnBtnReturn(wxCommandEvent& event) @@ -265,7 +294,7 @@ void wxCDMPackageDescriptionPanel::OnBtnSetVersion(wxCommandEvent& event) void wxCDMPackageDescriptionPanel::OnBtnSetDescription(wxCommandEvent& event) { - //get author from user + //get description from user wxTextEntryDialog* descDlg = new wxTextEntryDialog( this, wxT("Edit the package description."), @@ -277,7 +306,7 @@ void wxCDMPackageDescriptionPanel::OnBtnSetDescription(wxCommandEvent& event) if (descDlg->ShowModal() == wxID_OK) { std::string descriptionStr = crea::wx2std(descDlg->GetValue()); - //check name + //check desc if(descriptionStr.size() > 0) { std::string* result; @@ -292,19 +321,22 @@ void wxCDMPackageDescriptionPanel::OnBtnSetDescription(wxCommandEvent& event) void wxCDMPackageDescriptionPanel::OnLnkBlackBoxSelect(wxHyperlinkEvent& event) { int bbId = 0; - std::vector bbs = this->package->GetBlackBoxes(); + modelCDMBlackBox* bb; + std::vector 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); @@ -316,9 +348,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) @@ -351,13 +419,14 @@ 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 boxes = this->package->GetBlackBoxes(); + std::vector 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; } } @@ -372,12 +441,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 boxes = this->package->GetBlackBoxes(); + std::vector 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; } }