]> Creatis software - crea.git/blob - lib/creaDevManagerLib/wxCDMCMakeListsDescriptionPanel.cpp
Feature #1711
[crea.git] / lib / creaDevManagerLib / wxCDMCMakeListsDescriptionPanel.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  * wxCDMCMakeListsDescriptionPanel.cpp
30  *
31  *  Created on: Nov 27, 2012
32  *      Author: Daniel Felipe Gonzalez Obando
33  */
34
35 #include "wxCDMCMakeListsDescriptionPanel.h"
36
37 #include "wxCDMMainFrame.h"
38
39 #include "creaDevManagerIds.h"
40 #include "images/CMIcon64.xpm"
41
42 BEGIN_EVENT_TABLE(wxCDMCMakeListsDescriptionPanel, wxPanel)
43 EVT_HYPERLINK(ID_BUTTON_PREV, wxCDMCMakeListsDescriptionPanel::OnBtnReturn)
44 EVT_BUTTON(ID_BUTTON_EDIT_CMAKELISTSFILE, wxCDMCMakeListsDescriptionPanel::OnBtnOpenInEditor)
45 EVT_BUTTON(ID_BUTTON_OPEN_FOLDER, wxCDMCMakeListsDescriptionPanel::OnBtnOpenFolder)
46 END_EVENT_TABLE()
47
48 wxCDMCMakeListsDescriptionPanel::wxCDMCMakeListsDescriptionPanel(
49     wxWindow* parent,
50     modelCDMCMakeListsFile* makefile,
51     wxWindowID id,
52     const wxString& caption,
53     const wxPoint& pos,
54     const wxSize& size,
55     long style
56 )
57 {
58   wxCDMCMakeListsDescriptionPanel::Create(parent, makefile, id, caption, pos, size, style);
59 }
60
61 wxCDMCMakeListsDescriptionPanel::~wxCDMCMakeListsDescriptionPanel()
62 {
63 }
64
65 bool wxCDMCMakeListsDescriptionPanel::Create(
66     wxWindow* parent,
67     modelCDMCMakeListsFile* makefile,
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->cMakeLists = makefile;
77   CreateControls();
78   return TRUE;
79 }
80
81 void wxCDMCMakeListsDescriptionPanel::CreateControls()
82 {
83   wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
84
85   //Links to return
86   wxBoxSizer *linksSizer = new wxBoxSizer(wxHORIZONTAL);
87   std::vector<modelCDMIProjectTreeNode*> parents = this->cMakeLists->GetParents();
88   for (int i = 0; i < parents.size(); i++)
89     {
90       wxHyperlinkCtrl* returnLnk = new wxHyperlinkCtrl(this, ID_BUTTON_PREV, crea::std2wx(parents[parents.size()-1-i]->GetName()), crea::std2wx(parents[parents.size()-1-i]->GetPath()));
91       returnLnk->SetToolTip(crea::std2wx("Return to " + parents[parents.size()-1-i]->GetName() + "."));
92       linksSizer->Add(returnLnk, 0, wxALIGN_CENTER_VERTICAL | wxLEFT | wxRIGHT, 5);
93       if (i < parents.size()-1)
94         {
95           linksSizer->Add(new wxStaticText(this,wxID_ANY, wxT("/")), 0, wxALIGN_CENTER, 0);
96         }
97     }
98   sizer->Add(linksSizer, 0, wxALIGN_CENTER | wxALL, 5);
99
100   //Header
101   wxBoxSizer* headerSizer = new wxBoxSizer(wxHORIZONTAL);
102   {
103     //Image
104     headerSizer->Add(new wxStaticBitmap(this, -1, wxBitmap(CMIcon64)),0, wxALIGN_CENTER, 0);
105     wxBoxSizer* textSizer = new wxBoxSizer(wxVERTICAL);
106     //Title
107     textSizer->Add(new wxStaticText(this, -1, _("CMake Configuration File")),0, wxALIGN_LEFT, 0);
108     //File Name
109     textSizer->Add(new wxStaticText(this, -1, crea::std2wx("CMakeLists.txt")),0, wxALIGN_LEFT, 0);
110     headerSizer->Add(textSizer, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
111   }
112   sizer->Add(headerSizer, 0, wxALIGN_CENTER);
113
114   //Actions
115   wxStaticBoxSizer* actionsBox = new wxStaticBoxSizer(wxHORIZONTAL, this, wxT("&Actions"));
116   wxPanel* actionsPanel = new wxPanel(this);
117   wxBoxSizer* actionsPanelSizer = new wxBoxSizer(wxHORIZONTAL);
118   //actionsGrid Sizer
119   wxFlexGridSizer* actionsGridSizer = new wxFlexGridSizer(1, 2, 9, 15);
120
121   wxButton* editCMakebt = new wxButton(actionsPanel, ID_BUTTON_EDIT_CMAKELISTSFILE, _T("Open File"));
122   editCMakebt->SetToolTip(wxT("Open the CMakeLists file in the default text editor."));
123   actionsGridSizer->Add(editCMakebt, 1, wxALL | wxEXPAND, 5);
124   wxButton* openFolderbt = new wxButton(actionsPanel, ID_BUTTON_OPEN_FOLDER, _T("Open Containing Folder"));
125   openFolderbt->SetToolTip(wxT("Open the folder where the CMakeLists file is located in the file explorer."));
126   actionsGridSizer->Add(openFolderbt, 1, wxALL | wxEXPAND, 5);
127
128   actionsGridSizer->AddGrowableCol(0,1);
129   actionsGridSizer->AddGrowableCol(1,1);
130
131   actionsPanelSizer->Add(actionsGridSizer, 1, wxEXPAND, 0);
132   actionsPanel->SetSizer(actionsPanelSizer);
133   actionsPanelSizer->Fit(actionsPanel);
134   actionsBox->Add(actionsPanel, 1, wxEXPAND);
135   sizer -> Add(actionsBox, 0, wxEXPAND | wxALL, 10);
136
137   //Assign sizer
138   SetSizer(sizer);
139   sizer->SetSizeHints(this);
140 }
141
142 void wxCDMCMakeListsDescriptionPanel::OnBtnReturn(wxHyperlinkEvent& event)
143 {
144   std::vector<modelCDMIProjectTreeNode*> parents = this->cMakeLists->GetParents();
145   std::string parentURL = crea::wx2std(((wxHyperlinkCtrl*)event.GetEventObject())->GetURL());
146   //std::cout << parentURL << std::endl;
147   for (int i = 0; i < parents.size(); i++)
148     {
149       if (parents[i]->GetPath() == parentURL)
150         {
151           wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_DISPLAY_CHANGED);
152           newEvent->SetClientData(parents[i]);
153           newEvent->SetId(0);
154           wxPostEvent(this->GetParent(), *newEvent);
155         }
156     }
157 }
158
159 void wxCDMCMakeListsDescriptionPanel::OnBtnOpenInEditor(wxCommandEvent& event)
160 {
161   std::string* result;
162   if(!this->cMakeLists->OpenFile(result))
163     wxMessageBox(crea::std2wx(*result),_T("Open CMakeLists File - Error!"),wxOK | wxICON_ERROR);
164 }
165
166 void wxCDMCMakeListsDescriptionPanel::OnBtnOpenFolder(wxCommandEvent& event)
167 {
168   std::string* result;
169   if(!this->cMakeLists->OpenInFileExplorer(result))
170     wxMessageBox(crea::std2wx(*result),_T("Open Folder - Error!"),wxOK | wxICON_ERROR);
171 }