#include "wxCDMFolderDescriptionPanel.h"
+#include "wxCDMMainFrame.h"
+#include "CDMUtilities.h"
+
#include "creaDevManagerIds.h"
-#include "images/FdIcon.xpm"
+#include "images/FdIcon64.xpm"
BEGIN_EVENT_TABLE(wxCDMFolderDescriptionPanel, wxPanel)
-EVT_MENU(ID_BUTTON_OPEN_FOLDER, wxCDMFolderDescriptionPanel::OnBtnOpenInExplorer)
-EVT_MENU(ID_BUTTON_EDIT_CMAKELISTSFILE, wxCDMFolderDescriptionPanel::OnBtnEditCMakeLists)
+EVT_BUTTON(ID_BUTTON_PREV, wxCDMFolderDescriptionPanel::OnBtnReturn)
+EVT_BUTTON(ID_BUTTON_OPEN_FOLDER, wxCDMFolderDescriptionPanel::OnBtnOpenInExplorer)
+EVT_BUTTON(ID_BUTTON_EDIT_CMAKELISTSFILE, wxCDMFolderDescriptionPanel::OnBtnEditCMakeLists)
+EVT_BUTTON(ID_BUTTON_CREATE_FOLDER, wxCDMFolderDescriptionPanel::OnBtnCreateFolder)
END_EVENT_TABLE()
wxCDMFolderDescriptionPanel::wxCDMFolderDescriptionPanel(
{
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, _("Folder")),0, wxALIGN_CENTER, 0);
//Image
- sizer->Add(new wxStaticBitmap(this, -1, wxBitmap(FdIcon)),0, wxALIGN_CENTER, 0);
+ sizer->Add(new wxStaticBitmap(this, -1, wxBitmap(FdIcon64)),0, wxALIGN_CENTER, 0);
- //Welcome
+ //Folder Name
sizer->Add(new wxStaticText(this, -1, crea::std2wx(this->folder->GetName())),0, wxALIGN_CENTER, 0);
//Actions
- wxStaticBox* actionsBox = new wxStaticBox(this, -1, _T("&Actions"));
- wxStaticBoxSizer* actionsBoxInnerSizer = new wxStaticBoxSizer(actionsBox, wxVERTICAL);
- sizer -> Add(actionsBoxInnerSizer, 1, wxEXPAND | wxALL, 20);
+ wxStaticBoxSizer* actionsBox = new wxStaticBoxSizer(wxHORIZONTAL, this, wxT("&Actions"));
+ wxPanel* actionsPanel = new wxPanel(this);
+ wxBoxSizer* actionsPanelSizer = new wxBoxSizer(wxHORIZONTAL);
+
+ wxButton* openFolderbt = new wxButton(actionsPanel, ID_BUTTON_OPEN_FOLDER, _T("Open in File Explorer"));
+ openFolderbt->SetToolTip(wxT("Open this folder in the file explorer."));
+ actionsPanelSizer->Add(openFolderbt, 0, wxALL, 5);
- actionsBoxInnerSizer->Add(new wxButton(this, ID_BUTTON_OPEN_FOLDER, _T("Open in File Explorer")), 0, wxEXPAND | wxRIGHT | wxLEFT, 20);
if(this->folder->HasCMakeLists())
{
- actionsBoxInnerSizer->Add(new wxButton(this, ID_BUTTON_EDIT_CMAKELISTSFILE, _T("Edit CMakeLists File")), 0, wxEXPAND | wxRIGHT | wxLEFT, 20);
+ wxButton* editCMakebt = new wxButton(actionsPanel, ID_BUTTON_EDIT_CMAKELISTSFILE, _T("Edit CMakeLists File"));
+ editCMakebt->SetToolTip(wxT("Open the CMakeLists.txt file in this folder with the default text editor."));
+ editCMakebt->Connect(wxEVT_ENTER_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMFolderDescriptionPanel::OnCMakeMouseEnter,NULL,this);
+ editCMakebt->Connect(wxEVT_LEAVE_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMFolderDescriptionPanel::OnCMakeMouseExit,NULL,this);
+ actionsPanelSizer->Add(editCMakebt, 0, wxALL, 5);
}
- //Assign sizer
- actionsBoxInnerSizer->SetSizeHints(this);
+ wxButton* createFolderbt = new wxButton(actionsPanel, ID_BUTTON_CREATE_FOLDER, _T("Create Folder"));
+ createFolderbt->SetToolTip(wxT("Create a new folder inside this folder."));
+ actionsPanelSizer->Add(createFolderbt, 0, wxALL, 5);
+
+ actionsPanel->SetSizer(actionsPanelSizer);
+ actionsPanelSizer->Fit(actionsPanel);
+ actionsBox->Add(actionsPanel, 0, wxEXPAND);
+ sizer -> Add(actionsBox, 0, wxEXPAND | wxALL, 10);
+ //Assign sizer
SetSizer(sizer);
sizer->SetSizeHints(this);
}
+void wxCDMFolderDescriptionPanel::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 wxCDMFolderDescriptionPanel::OnBtnOpenInExplorer(wxCommandEvent& event)
{
- //TODO: implement method
- std::cerr << "Event OnBtnOpenInExplorer not implemented" << std::endl;
- event.Skip();
+ std::string* result;
+ if(!this->folder->OpenInFileExplorer(result))
+ wxMessageBox(crea::std2wx(*result),_T("Open Folder - Error!"),wxOK | wxICON_ERROR);
}
void wxCDMFolderDescriptionPanel::OnBtnEditCMakeLists(wxCommandEvent& event)
{
- //TODO: implement method
- std::cerr << "Event OnBtnEditCMakeLists not implemented" << std::endl;
+ std::string* result;
+ if(!this->folder->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->folder->GetCMakeLists() != NULL)
+ {
+ int CMId = this->folder->GetCMakeLists()->GetId();
+ newEvent->SetInt(CMId);
+ newEvent->SetId(0);
+ wxPostEvent(this->GetParent(), *newEvent);
+ }
+}
+
+void wxCDMFolderDescriptionPanel::OnBtnCreateFolder(wxCommandEvent& event)
+{
+ //get name
+ wxString folderName = wxGetTextFromUser(
+ wxT("Enter the name of the new folder:"),
+ wxT("Create Folder - creaDevManager")
+ );
+ //check name
+ std::vector<std::string> parts;
+ CDMUtilities::splitter::split(parts, crea::wx2std(folderName), " /\\\"", CDMUtilities::splitter::no_empties);
+ if(parts.size() > 0)
+ {
+ std::string* result;
+ modelCDMFolder* folderC = this->folder->CreateFolder(crea::wx2std(folderName), result);
+ if(folderC == NULL)
+ {
+ wxMessageBox(crea::std2wx(*result),_T("Create Folder - Error!"),wxOK | wxICON_ERROR);
+ return;
+ }
+ ((wxCDMMainFrame*)this->GetParent())->RefreshProject();
+ wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_DISPLAY_CHANGED);
+ newEvent->SetInt(folderC->GetId());
+ wxPostEvent(this->GetParent(), *newEvent);
+ wxMessageBox(crea::std2wx("The folder was successfully created"),_T("Create Folder - Success"),wxOK | wxICON_INFORMATION);
+ }
+ else
+ {
+ wxMessageBox(crea::std2wx("No name specified"),_T("Create Folder - Error!"),wxOK | wxICON_ERROR);
+ }
+}
+
+void wxCDMFolderDescriptionPanel::OnCMakeMouseEnter(wxMouseEvent& event)
+{
+ wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LIST_ITEM_SELECTED);
+
+ if(this->folder->GetCMakeLists() != NULL)
+ {
+ int CMId = this->folder->GetCMakeLists()->GetId();
+ newEvent->SetInt(CMId);
+ newEvent->SetId(0);
+ wxPostEvent(this->GetParent(), *newEvent);
+ }
+ event.Skip();
+}
+
+void wxCDMFolderDescriptionPanel::OnCMakeMouseExit(wxMouseEvent& event)
+{
+ wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LIST_ITEM_DESELECTED);
+
+ if(this->folder->GetCMakeLists() != NULL)
+ {
+ int CMId = this->folder->GetCMakeLists()->GetId();
+ newEvent->SetInt(CMId);
+ newEvent->SetId(0);
+ wxPostEvent(this->GetParent(), *newEvent);
+ }
event.Skip();
}