]> Creatis software - crea.git/blob - lib/creaDevManagerLib/wxCDMLibraryDescriptionPanel.cpp
Feature #1711
[crea.git] / lib / creaDevManagerLib / wxCDMLibraryDescriptionPanel.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  * wxCDMLibraryDescriptionPanel.cpp
30  *
31  *  Created on: Nov 27, 2012
32  *      Author: Daniel Felipe Gonzalez Obando
33  */
34
35 #include "wxCDMLibraryDescriptionPanel.h"
36
37 #include "wxCDMMainFrame.h"
38
39 #include "creaDevManagerIds.h"
40 #include "images/LIcon64.xpm"
41
42 BEGIN_EVENT_TABLE(wxCDMLibraryDescriptionPanel, wxPanel)
43 EVT_BUTTON(ID_BUTTON_PREV, wxCDMLibraryDescriptionPanel::OnBtnReturn)
44 EVT_BUTTON(ID_BUTTON_CREATE_CLASS, wxCDMLibraryDescriptionPanel::OnBtnCreateClass)
45 EVT_BUTTON(ID_BUTTON_CREATE_FOLDER, wxCDMLibraryDescriptionPanel::OnBtnCreateFolder)
46 EVT_BUTTON(ID_BUTTON_EDIT_CMAKELISTSFILE, wxCDMLibraryDescriptionPanel::OnBtnEditCMakeLists)
47 EVT_BUTTON(ID_BUTTON_OPEN_FOLDER, wxCDMLibraryDescriptionPanel::OnBtnOpenFolder)
48 END_EVENT_TABLE()
49
50 wxCDMLibraryDescriptionPanel::wxCDMLibraryDescriptionPanel(
51     wxWindow* parent,
52     modelCDMLibrary* library,
53     wxWindowID id,
54     const wxString& caption,
55     const wxPoint& pos,
56     const wxSize& size,
57     long style
58 )
59 {
60   wxCDMLibraryDescriptionPanel::Create(parent, library, id, caption, pos, size, style);
61 }
62
63 wxCDMLibraryDescriptionPanel::~wxCDMLibraryDescriptionPanel()
64 {
65 }
66
67 bool wxCDMLibraryDescriptionPanel::Create(
68     wxWindow* parent,
69     modelCDMLibrary* library,
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->library = library;
79   CreateControls();
80   return TRUE;
81 }
82
83 void wxCDMLibraryDescriptionPanel::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   //Title
93   sizer->Add(new wxStaticText(this, -1, _("Library")),0, wxALIGN_CENTER, 0);
94
95   //Image
96   sizer->Add(new wxStaticBitmap(this, -1, wxBitmap(LIcon64)),0, wxALIGN_CENTER, 0);
97
98   //Project Name
99   sizer->Add(new wxStaticText(this, -1, crea::std2wx(this->library->GetNameLibrary())),0, wxALIGN_CENTER, 0);
100
101   //Actions
102   wxStaticBoxSizer* actionsBox = new wxStaticBoxSizer(wxHORIZONTAL, this, wxT("&Actions"));
103   wxPanel* actionsPanel = new wxPanel(this);
104   wxBoxSizer* actionsPanelSizer = new wxBoxSizer(wxHORIZONTAL);
105
106   wxButton* createClassbt = new wxButton(actionsPanel, ID_BUTTON_CREATE_CLASS, _T("Create Class"));
107   createClassbt->SetToolTip(wxT("Create a new class for this library."));
108   actionsPanelSizer->Add(createClassbt, 0, wxALL, 5);
109   wxButton* createFolderbt = new wxButton(actionsPanel, ID_BUTTON_CREATE_FOLDER, _T("Create Folder"));
110   createFolderbt->SetToolTip(wxT("Create a new folder for this library."));
111   actionsPanelSizer->Add(createFolderbt, 0, wxALL, 5);
112   wxButton* editCMakebt = new wxButton(actionsPanel, ID_BUTTON_EDIT_CMAKELISTSFILE, _T("Edit CMakeLists File"));
113   editCMakebt->SetToolTip(wxT("Edit the CMakeLists.txt of this library in the default text editor."));
114   editCMakebt->Connect(wxEVT_ENTER_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMLibraryDescriptionPanel::OnCMakeMouseEnter,NULL,this);
115   editCMakebt->Connect(wxEVT_LEAVE_WINDOW, (wxObjectEventFunction)(wxEventFunction)(wxMouseEventFunction)&wxCDMLibraryDescriptionPanel::OnCMakeMouseExit,NULL,this);
116   actionsPanelSizer->Add(editCMakebt, 0, wxALL, 5);
117   wxButton* openFolderbt = new wxButton(actionsPanel, ID_BUTTON_OPEN_FOLDER, _T("Open Library Folder"));
118   openFolderbt->SetToolTip(wxT("Open the library folder in the file explorer."));
119   actionsPanelSizer->Add(openFolderbt, 0, wxALL, 5);
120
121   actionsPanel->SetSizer(actionsPanelSizer);
122   actionsPanelSizer->Fit(actionsPanel);
123   actionsBox->Add(actionsPanel, 1, wxEXPAND);
124   sizer -> Add(actionsBox, 0, wxALL | wxEXPAND, 10);
125
126   //Assign sizer
127   SetSizer(sizer);
128   sizer->SetSizeHints(this);
129 }
130
131 void wxCDMLibraryDescriptionPanel::OnBtnReturn(wxCommandEvent& event)
132 {
133   wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_DISPLAY_CHANGED);
134   newEvent->SetInt(((wxCDMMainFrame*)this->GetParent())->GetModel()->GetProject()->GetId());
135   newEvent->SetId(0);
136   wxPostEvent(this->GetParent(), *newEvent);
137 }
138
139 void wxCDMLibraryDescriptionPanel::OnBtnCreateClass(wxCommandEvent& event)
140 {
141   //TODO: implement method
142   std::cerr << "Event OnBtnCreateClass not implemented" << std::endl;
143   event.Skip();
144 }
145
146 void wxCDMLibraryDescriptionPanel::OnBtnCreateFolder(wxCommandEvent& event)
147 {
148   //TODO: implement method
149   std::cerr << "Event OnBtnCreateFolder not implemented" << std::endl;
150   event.Skip();
151 }
152
153 void wxCDMLibraryDescriptionPanel::OnBtnEditCMakeLists(wxCommandEvent& event)
154 {
155   std::string* result;
156     if(!this->library->OpenCMakeListsFile(result))
157       wxMessageBox(crea::std2wx(*result),_T("Open CMakeLists File - Error!"),wxOK | wxICON_ERROR);
158
159     wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LIST_ITEM_DESELECTED);
160
161     if(this->library->GetCMakeLists() != NULL)
162       {
163         int CMId = this->library->GetCMakeLists()->GetId();
164         newEvent->SetInt(CMId);
165         newEvent->SetId(0);
166         wxPostEvent(this->GetParent(), *newEvent);
167       }
168
169     event.Skip();
170 }
171
172 void wxCDMLibraryDescriptionPanel::OnBtnOpenFolder(wxCommandEvent& event)
173 {
174   std::string* result;
175   if(!this->library->OpenInFileExplorer(result))
176     wxMessageBox(crea::std2wx(*result),_T("Open Folder - Error!"),wxOK | wxICON_ERROR);
177 }
178
179 void wxCDMLibraryDescriptionPanel::OnCMakeMouseEnter(wxMouseEvent& event)
180 {
181   wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LIST_ITEM_SELECTED);
182
183   if(this->library->GetCMakeLists() != NULL)
184     {
185       int CMId = this->library->GetCMakeLists()->GetId();
186       newEvent->SetInt(CMId);
187       newEvent->SetId(0);
188       wxPostEvent(this->GetParent(), *newEvent);
189     }
190   event.Skip();
191 }
192
193 void wxCDMLibraryDescriptionPanel::OnCMakeMouseExit(wxMouseEvent& event)
194 {
195   wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_COMMAND_LIST_ITEM_DESELECTED);
196
197   if(this->library->GetCMakeLists() != NULL)
198     {
199       int CMId = this->library->GetCMakeLists()->GetId();
200       newEvent->SetInt(CMId);
201       newEvent->SetId(0);
202       wxPostEvent(this->GetParent(), *newEvent);
203     }
204   event.Skip();
205 }