]> 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
39 #include "creaDevManagerIds.h"
40 #include "images/FdIcon64.xpm"
41
42 BEGIN_EVENT_TABLE(wxCDMFolderDescriptionPanel, wxPanel)
43 EVT_BUTTON(ID_BUTTON_PREV, wxCDMFolderDescriptionPanel::OnBtnReturn)
44 EVT_BUTTON(ID_BUTTON_OPEN_FOLDER, wxCDMFolderDescriptionPanel::OnBtnOpenInExplorer)
45 EVT_BUTTON(ID_BUTTON_EDIT_CMAKELISTSFILE, wxCDMFolderDescriptionPanel::OnBtnEditCMakeLists)
46 END_EVENT_TABLE()
47
48 wxCDMFolderDescriptionPanel::wxCDMFolderDescriptionPanel(
49     wxWindow* parent,
50     modelCDMFolder* folder,
51     wxWindowID id,
52     const wxString& caption,
53     const wxPoint& pos,
54     const wxSize& size,
55     long style
56 )
57 {
58   wxCDMFolderDescriptionPanel::Create(parent, folder, id, caption, pos, size, style);
59 }
60
61 wxCDMFolderDescriptionPanel::~wxCDMFolderDescriptionPanel()
62 {
63 }
64
65 bool wxCDMFolderDescriptionPanel::Create(
66     wxWindow* parent,
67     modelCDMFolder* folder,
68     wxWindowID id,
69     const wxString& caption,
70     const wxPoint& pos,
71     const wxSize& size,
72     long style
73 )
74 {
75   wxPanel::Create(parent, id, pos, size, style);
76   this->folder = folder;
77   CreateControls();
78   return TRUE;
79 }
80
81 void wxCDMFolderDescriptionPanel::CreateControls()
82 {
83   wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
84
85   //Link to return
86   wxButton* returnbt = new wxButton(this, ID_BUTTON_PREV, wxT("Return to project"));
87   returnbt->SetToolTip(wxT("Return to the active project description."));
88   sizer->Add(returnbt, 0, wxALIGN_CENTER | wxALL, 5);
89
90   //Title
91   sizer->Add(new wxStaticText(this, -1, _("Folder")),0, wxALIGN_CENTER, 0);
92
93   //Image
94   sizer->Add(new wxStaticBitmap(this, -1, wxBitmap(FdIcon64)),0, wxALIGN_CENTER, 0);
95
96   //Folder Name
97   sizer->Add(new wxStaticText(this, -1, crea::std2wx(this->folder->GetName())),0, wxALIGN_CENTER, 0);
98
99   //Actions
100   wxStaticBoxSizer* actionsBox = new wxStaticBoxSizer(wxHORIZONTAL, this, wxT("&Actions"));
101   wxPanel* actionsPanel = new wxPanel(this);
102   wxBoxSizer* actionsPanelSizer = new wxBoxSizer(wxHORIZONTAL);
103
104   wxButton* openFolderbt = new wxButton(actionsPanel, ID_BUTTON_OPEN_FOLDER, _T("Open in File Explorer"));
105   openFolderbt->SetToolTip(wxT("Open this folder in the file explorer."));
106   actionsPanelSizer->Add(openFolderbt, 0, wxALL, 5);
107
108   if(this->folder->HasCMakeLists())
109     {
110       wxButton* editCMakebt = new wxButton(actionsPanel, ID_BUTTON_EDIT_CMAKELISTSFILE, _T("Edit CMakeLists File"));
111       editCMakebt->SetToolTip(wxT("Open the CMakeLists.txt file in this folder with the default text editor."));
112       editCMakebt->Connect(wxEVT_ENTER_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMFolderDescriptionPanel::OnCMakeMouseEnter,NULL,this);
113       editCMakebt->Connect(wxEVT_LEAVE_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMFolderDescriptionPanel::OnCMakeMouseExit,NULL,this);
114       actionsPanelSizer->Add(editCMakebt, 0, wxALL, 5);
115     }
116
117   actionsPanel->SetSizer(actionsPanelSizer);
118   actionsPanelSizer->Fit(actionsPanel);
119   actionsBox->Add(actionsPanel, 0, wxEXPAND);
120   sizer -> Add(actionsBox, 0, wxEXPAND | wxALL, 10);
121
122   //Assign sizer
123   SetSizer(sizer);
124   sizer->SetSizeHints(this);
125 }
126
127 void wxCDMFolderDescriptionPanel::OnBtnReturn(wxCommandEvent& event)
128 {
129   wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_DISPLAY_CHANGED);
130   newEvent->SetInt(((wxCDMMainFrame*)this->GetParent())->GetModel()->GetProject()->GetId());
131   newEvent->SetId(0);
132   wxPostEvent(this->GetParent(), *newEvent);
133 }
134
135 void wxCDMFolderDescriptionPanel::OnBtnOpenInExplorer(wxCommandEvent& event)
136 {
137   std::string* result;
138     if(!this->folder->OpenInFileExplorer(result))
139       wxMessageBox(crea::std2wx(*result),_T("Open Folder - Error!"),wxOK | wxICON_ERROR);
140 }
141
142 void wxCDMFolderDescriptionPanel::OnBtnEditCMakeLists(wxCommandEvent& event)
143 {
144   std::string* result;
145   if(!this->folder->OpenCMakeListsFile(result))
146     wxMessageBox(crea::std2wx(*result),_T("Open CMakeLists File - Error!"),wxOK | wxICON_ERROR);
147
148   wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LIST_ITEM_DESELECTED);
149
150   if(this->folder->GetCMakeLists() != NULL)
151     {
152       int CMId = this->folder->GetCMakeLists()->GetId();
153       newEvent->SetInt(CMId);
154       newEvent->SetId(0);
155       wxPostEvent(this->GetParent(), *newEvent);
156     }
157 }
158
159 void wxCDMFolderDescriptionPanel::OnCMakeMouseEnter(wxMouseEvent& event)
160 {
161   wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LIST_ITEM_SELECTED);
162
163   if(this->folder->GetCMakeLists() != NULL)
164     {
165       int CMId = this->folder->GetCMakeLists()->GetId();
166       newEvent->SetInt(CMId);
167       newEvent->SetId(0);
168       wxPostEvent(this->GetParent(), *newEvent);
169     }
170   event.Skip();
171 }
172
173 void wxCDMFolderDescriptionPanel::OnCMakeMouseExit(wxMouseEvent& event)
174 {
175   wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LIST_ITEM_DESELECTED);
176
177   if(this->folder->GetCMakeLists() != NULL)
178     {
179       int CMId = this->folder->GetCMakeLists()->GetId();
180       newEvent->SetInt(CMId);
181       newEvent->SetId(0);
182       wxPostEvent(this->GetParent(), *newEvent);
183     }
184   event.Skip();
185 }