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