]> Creatis software - crea.git/blob - lib/creaDevManagerLib/wxCDMFolderDescriptionPanel.cpp
Feature #1711
[crea.git] / lib / creaDevManagerLib / wxCDMFolderDescriptionPanel.cpp
1 /*
2 # ---------------------------------------------------------------------
3 #
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
5 #                        pour la Sant�)
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
9 #
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.
16 #
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
21 #  liability.
22 #
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 # ------------------------------------------------------------------------
26  */
27
28 /*
29  * wxCDMFolderDescriptionPanel.cpp
30  *
31  *  Created on: Nov 27, 2012
32  *      Author: Daniel Felipe Gonzalez Obando
33  */
34
35 #include "wxCDMFolderDescriptionPanel.h"
36
37 #include "wxCDMMainFrame.h"
38 #include "CDMUtilities.h"
39
40 #include "creaDevManagerIds.h"
41 #include "images/FdIcon64.xpm"
42
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)
48 END_EVENT_TABLE()
49
50 wxCDMFolderDescriptionPanel::wxCDMFolderDescriptionPanel(
51     wxWindow* parent,
52     modelCDMFolder* folder,
53     wxWindowID id,
54     const wxString& caption,
55     const wxPoint& pos,
56     const wxSize& size,
57     long style
58 )
59 {
60   wxCDMFolderDescriptionPanel::Create(parent, folder, id, caption, pos, size, style);
61 }
62
63 wxCDMFolderDescriptionPanel::~wxCDMFolderDescriptionPanel()
64 {
65 }
66
67 bool wxCDMFolderDescriptionPanel::Create(
68     wxWindow* parent,
69     modelCDMFolder* folder,
70     wxWindowID id,
71     const wxString& caption,
72     const wxPoint& pos,
73     const wxSize& size,
74     long style
75 )
76 {
77   wxPanel::Create(parent, id, pos, size, style);
78   this->folder = folder;
79   CreateControls();
80   return TRUE;
81 }
82
83 void wxCDMFolderDescriptionPanel::CreateControls()
84 {
85   wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
86
87   //Link to return
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);
91
92   //Header
93   wxBoxSizer* headerSizer = new wxBoxSizer(wxHORIZONTAL);
94   {
95     //Image
96     headerSizer->Add(new wxStaticBitmap(this, -1, wxBitmap(FdIcon64)),0, wxALIGN_CENTER, 0);
97     wxBoxSizer* textSizer = new wxBoxSizer(wxVERTICAL);
98     //Title
99     textSizer->Add(new wxStaticText(this, -1, _("Folder")),0, wxALIGN_LEFT, 0);
100     //Folder Name
101     textSizer->Add(new wxStaticText(this, -1, crea::std2wx(this->folder->GetName())),0, wxALIGN_LEFT, 0);
102     headerSizer->Add(textSizer, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
103   }
104   sizer->Add(headerSizer, 0, wxALIGN_CENTER);
105
106   //Actions
107   wxStaticBoxSizer* actionsBox = new wxStaticBoxSizer(wxHORIZONTAL, this, wxT("&Actions"));
108   wxPanel* actionsPanel = new wxPanel(this);
109   wxBoxSizer* actionsPanelSizer = new wxBoxSizer(wxHORIZONTAL);
110   //actionsGrid Sizer
111   wxFlexGridSizer* actionsGridSizer = new wxFlexGridSizer(2, 2, 9, 15);
112
113   wxButton* openFolderbt = new wxButton(actionsPanel, ID_BUTTON_OPEN_FOLDER, _T("Open in File Explorer"));
114   openFolderbt->SetToolTip(wxT("Open this folder in the file explorer."));
115   actionsGridSizer->Add(openFolderbt, 1, wxALL | wxEXPAND, 5);
116
117   if(this->folder->HasCMakeLists())
118     {
119       wxButton* editCMakebt = new wxButton(actionsPanel, ID_BUTTON_EDIT_CMAKELISTSFILE, _T("Edit CMakeLists File"));
120       editCMakebt->SetToolTip(wxT("Open the CMakeLists.txt file in this folder with the default text editor."));
121       editCMakebt->Connect(wxEVT_ENTER_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMFolderDescriptionPanel::OnCMakeMouseEnter,NULL,this);
122       editCMakebt->Connect(wxEVT_LEAVE_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMFolderDescriptionPanel::OnCMakeMouseExit,NULL,this);
123       actionsGridSizer->Add(editCMakebt, 1, wxALL | wxEXPAND, 5);
124     }
125
126   wxButton* createClassbt = new wxButton(actionsPanel, ID_BUTTON_CREATE_CLASS, _T("Create Class"));
127   createClassbt->SetToolTip(wxT("Create a new class (.h and .cpp) inside this folder."));
128   actionsGridSizer->Add(createClassbt, 1, wxALL | wxEXPAND, 5);
129
130   wxButton* createFolderbt = new wxButton(actionsPanel, ID_BUTTON_CREATE_FOLDER, _T("Create Folder"));
131   createFolderbt->SetToolTip(wxT("Create a new folder inside this folder."));
132   actionsGridSizer->Add(createFolderbt, 1, wxALL | wxEXPAND, 5);
133
134   actionsGridSizer->AddGrowableCol(0,1);
135   actionsGridSizer->AddGrowableCol(1,1);
136
137   actionsPanelSizer->Add(actionsGridSizer, 1, wxEXPAND, 0);
138   actionsPanel->SetSizer(actionsPanelSizer);
139   actionsPanelSizer->Fit(actionsPanel);
140   actionsBox->Add(actionsPanel, 1, wxEXPAND);
141   sizer -> Add(actionsBox, 0, wxEXPAND | wxALL, 10);
142
143   //Assign sizer
144   SetSizer(sizer);
145   sizer->SetSizeHints(this);
146 }
147
148 void wxCDMFolderDescriptionPanel::OnBtnReturn(wxCommandEvent& event)
149 {
150   wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_DISPLAY_CHANGED);
151   newEvent->SetInt(((wxCDMMainFrame*)this->GetParent())->GetModel()->GetProject()->GetId());
152   newEvent->SetId(0);
153   wxPostEvent(this->GetParent(), *newEvent);
154 }
155
156 void wxCDMFolderDescriptionPanel::OnBtnOpenInExplorer(wxCommandEvent& event)
157 {
158   std::string* result;
159   if(!this->folder->OpenInFileExplorer(result))
160     wxMessageBox(crea::std2wx(*result),_T("Open Folder - Error!"),wxOK | wxICON_ERROR);
161 }
162
163 void wxCDMFolderDescriptionPanel::OnBtnEditCMakeLists(wxCommandEvent& event)
164 {
165   std::string* result;
166   if(!this->folder->OpenCMakeListsFile(result))
167     wxMessageBox(crea::std2wx(*result),_T("Open CMakeLists File - Error!"),wxOK | wxICON_ERROR);
168
169   wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LIST_ITEM_DESELECTED);
170
171   if(this->folder->GetCMakeLists() != NULL)
172     {
173       int CMId = this->folder->GetCMakeLists()->GetId();
174       newEvent->SetInt(CMId);
175       newEvent->SetId(0);
176       wxPostEvent(this->GetParent(), *newEvent);
177     }
178 }
179
180 void wxCDMFolderDescriptionPanel::OnBtnCreateFolder(wxCommandEvent& event)
181 {
182   //get name
183   wxString folderName = wxGetTextFromUser(
184       wxT("Enter the name of the new folder:"),
185       wxT("Create Folder - creaDevManager")
186   );
187   //check name
188   std::vector<std::string> parts;
189   CDMUtilities::splitter::split(parts, crea::wx2std(folderName), " /\\\"", CDMUtilities::splitter::no_empties);
190   if(parts.size() > 0)
191     {
192       std::string* result;
193       modelCDMFolder* folderC = this->folder->CreateFolder(crea::wx2std(folderName), result);
194       if(folderC == NULL)
195         {
196           wxMessageBox(crea::std2wx(*result),_T("Create Folder - Error!"),wxOK | wxICON_ERROR);
197           return;
198         }
199       ((wxCDMMainFrame*)this->GetParent())->RefreshProject();
200       wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_DISPLAY_CHANGED);
201       newEvent->SetInt(folderC->GetId());
202       wxPostEvent(this->GetParent(), *newEvent);
203       wxMessageBox(crea::std2wx("The folder was successfully created"),_T("Create Folder - Success"),wxOK | wxICON_INFORMATION);
204     }
205   else
206     {
207       wxMessageBox(crea::std2wx("No name specified"),_T("Create Folder - Error!"),wxOK | wxICON_ERROR);
208     }
209 }
210
211 void wxCDMFolderDescriptionPanel::OnCMakeMouseEnter(wxMouseEvent& event)
212 {
213   wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LIST_ITEM_SELECTED);
214
215   if(this->folder->GetCMakeLists() != NULL)
216     {
217       int CMId = this->folder->GetCMakeLists()->GetId();
218       newEvent->SetInt(CMId);
219       newEvent->SetId(0);
220       wxPostEvent(this->GetParent(), *newEvent);
221     }
222   event.Skip();
223 }
224
225 void wxCDMFolderDescriptionPanel::OnCMakeMouseExit(wxMouseEvent& event)
226 {
227   wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LIST_ITEM_DESELECTED);
228
229   if(this->folder->GetCMakeLists() != NULL)
230     {
231       int CMId = this->folder->GetCMakeLists()->GetId();
232       newEvent->SetInt(CMId);
233       newEvent->SetId(0);
234       wxPostEvent(this->GetParent(), *newEvent);
235     }
236   event.Skip();
237 }