2 # ---------------------------------------------------------------------
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
6 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
7 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
8 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
10 # This software is governed by the CeCILL-B license under French law and
11 # abiding by the rules of distribution of free software. You can use,
12 # modify and/ or redistribute the software under the terms of the CeCILL-B
13 # license as circulated by CEA, CNRS and INRIA at the following URL
14 # http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
15 # or in the file LICENSE.txt.
17 # As a counterpart to the access to the source code and rights to copy,
18 # modify and redistribute granted by the license, users are provided only
19 # with a limited warranty and the software's author, the holder of the
20 # economic rights, and the successive licensors have only limited
23 # The fact that you are presently reading this means that you have had
24 # knowledge of the CeCILL-B license and that you accept its terms.
25 # ------------------------------------------------------------------------
29 * wxCDMFolderDescriptionPanel.cpp
31 * Created on: Nov 27, 2012
32 * Author: Daniel Felipe Gonzalez Obando
35 #include "wxCDMFolderDescriptionPanel.h"
37 #include "wxCDMMainFrame.h"
38 #include "CDMUtilities.h"
40 #include "creaDevManagerIds.h"
41 #include "images/FdIcon64.xpm"
43 BEGIN_EVENT_TABLE(wxCDMFolderDescriptionPanel, wxPanel)
44 EVT_BUTTON(ID_BUTTON_PREV, wxCDMFolderDescriptionPanel::OnBtnReturn)
45 EVT_BUTTON(ID_BUTTON_OPEN_FOLDER, wxCDMFolderDescriptionPanel::OnBtnOpenInExplorer)
46 EVT_BUTTON(ID_BUTTON_EDIT_CMAKELISTSFILE, wxCDMFolderDescriptionPanel::OnBtnEditCMakeLists)
47 EVT_BUTTON(ID_BUTTON_CREATE_FOLDER, wxCDMFolderDescriptionPanel::OnBtnCreateFolder)
50 wxCDMFolderDescriptionPanel::wxCDMFolderDescriptionPanel(
52 modelCDMFolder* folder,
54 const wxString& caption,
60 wxCDMFolderDescriptionPanel::Create(parent, folder, id, caption, pos, size, style);
63 wxCDMFolderDescriptionPanel::~wxCDMFolderDescriptionPanel()
67 bool wxCDMFolderDescriptionPanel::Create(
69 modelCDMFolder* folder,
71 const wxString& caption,
77 wxPanel::Create(parent, id, pos, size, style);
78 this->folder = folder;
83 void wxCDMFolderDescriptionPanel::CreateControls()
85 wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
88 wxButton* returnbt = new wxButton(this, ID_BUTTON_PREV, wxT("Return to project"));
89 returnbt->SetToolTip(wxT("Return to the active project description."));
90 sizer->Add(returnbt, 0, wxALIGN_CENTER | wxALL, 5);
93 sizer->Add(new wxStaticText(this, -1, _("Folder")),0, wxALIGN_CENTER, 0);
96 sizer->Add(new wxStaticBitmap(this, -1, wxBitmap(FdIcon64)),0, wxALIGN_CENTER, 0);
99 sizer->Add(new wxStaticText(this, -1, crea::std2wx(this->folder->GetName())),0, wxALIGN_CENTER, 0);
102 wxStaticBoxSizer* actionsBox = new wxStaticBoxSizer(wxHORIZONTAL, this, wxT("&Actions"));
103 wxPanel* actionsPanel = new wxPanel(this);
104 wxBoxSizer* actionsPanelSizer = new wxBoxSizer(wxHORIZONTAL);
106 wxButton* openFolderbt = new wxButton(actionsPanel, ID_BUTTON_OPEN_FOLDER, _T("Open in File Explorer"));
107 openFolderbt->SetToolTip(wxT("Open this folder in the file explorer."));
108 actionsPanelSizer->Add(openFolderbt, 0, wxALL, 5);
110 if(this->folder->HasCMakeLists())
112 wxButton* editCMakebt = new wxButton(actionsPanel, ID_BUTTON_EDIT_CMAKELISTSFILE, _T("Edit CMakeLists File"));
113 editCMakebt->SetToolTip(wxT("Open the CMakeLists.txt file in this folder with the default text editor."));
114 editCMakebt->Connect(wxEVT_ENTER_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMFolderDescriptionPanel::OnCMakeMouseEnter,NULL,this);
115 editCMakebt->Connect(wxEVT_LEAVE_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMFolderDescriptionPanel::OnCMakeMouseExit,NULL,this);
116 actionsPanelSizer->Add(editCMakebt, 0, wxALL, 5);
119 wxButton* createFolderbt = new wxButton(actionsPanel, ID_BUTTON_CREATE_FOLDER, _T("Create Folder"));
120 createFolderbt->SetToolTip(wxT("Create a new folder inside this folder."));
121 actionsPanelSizer->Add(createFolderbt, 0, wxALL, 5);
123 actionsPanel->SetSizer(actionsPanelSizer);
124 actionsPanelSizer->Fit(actionsPanel);
125 actionsBox->Add(actionsPanel, 0, wxEXPAND);
126 sizer -> Add(actionsBox, 0, wxEXPAND | wxALL, 10);
130 sizer->SetSizeHints(this);
133 void wxCDMFolderDescriptionPanel::OnBtnReturn(wxCommandEvent& event)
135 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_DISPLAY_CHANGED);
136 newEvent->SetInt(((wxCDMMainFrame*)this->GetParent())->GetModel()->GetProject()->GetId());
138 wxPostEvent(this->GetParent(), *newEvent);
141 void wxCDMFolderDescriptionPanel::OnBtnOpenInExplorer(wxCommandEvent& event)
144 if(!this->folder->OpenInFileExplorer(result))
145 wxMessageBox(crea::std2wx(*result),_T("Open Folder - Error!"),wxOK | wxICON_ERROR);
148 void wxCDMFolderDescriptionPanel::OnBtnEditCMakeLists(wxCommandEvent& event)
151 if(!this->folder->OpenCMakeListsFile(result))
152 wxMessageBox(crea::std2wx(*result),_T("Open CMakeLists File - Error!"),wxOK | wxICON_ERROR);
154 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LIST_ITEM_DESELECTED);
156 if(this->folder->GetCMakeLists() != NULL)
158 int CMId = this->folder->GetCMakeLists()->GetId();
159 newEvent->SetInt(CMId);
161 wxPostEvent(this->GetParent(), *newEvent);
165 void wxCDMFolderDescriptionPanel::OnBtnCreateFolder(wxCommandEvent& event)
168 wxString folderName = wxGetTextFromUser(
169 wxT("Enter the name of the new folder:"),
170 wxT("Create Folder - creaDevManager")
173 std::vector<std::string> parts;
174 CDMUtilities::splitter::split(parts, crea::wx2std(folderName), " /\\\"", CDMUtilities::splitter::no_empties);
178 modelCDMFolder* folderC = this->folder->CreateFolder(crea::wx2std(folderName), result);
181 wxMessageBox(crea::std2wx(*result),_T("Create Folder - Error!"),wxOK | wxICON_ERROR);
184 ((wxCDMMainFrame*)this->GetParent())->RefreshProject();
185 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_DISPLAY_CHANGED);
186 newEvent->SetInt(folderC->GetId());
187 wxPostEvent(this->GetParent(), *newEvent);
188 wxMessageBox(crea::std2wx("The folder was successfully created"),_T("Create Folder - Success"),wxOK | wxICON_INFORMATION);
192 wxMessageBox(crea::std2wx("No name specified"),_T("Create Folder - Error!"),wxOK | wxICON_ERROR);
196 void wxCDMFolderDescriptionPanel::OnCMakeMouseEnter(wxMouseEvent& event)
198 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LIST_ITEM_SELECTED);
200 if(this->folder->GetCMakeLists() != NULL)
202 int CMId = this->folder->GetCMakeLists()->GetId();
203 newEvent->SetInt(CMId);
205 wxPostEvent(this->GetParent(), *newEvent);
210 void wxCDMFolderDescriptionPanel::OnCMakeMouseExit(wxMouseEvent& event)
212 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LIST_ITEM_DESELECTED);
214 if(this->folder->GetCMakeLists() != NULL)
216 int CMId = this->folder->GetCMakeLists()->GetId();
217 newEvent->SetInt(CMId);
219 wxPostEvent(this->GetParent(), *newEvent);