]> Creatis software - crea.git/blob - lib/creaDevManagerLib/wxCDMFileDescriptionPanel.cpp
Feature #1711 CreaDevManager application implementation
[crea.git] / lib / creaDevManagerLib / wxCDMFileDescriptionPanel.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  * wxCDMBlackBoxDescriptionPanel.cpp
30  *
31  *  Created on: Nov 27, 2012
32  *      Author: Daniel Felipe Gonzalez Obando
33  */
34
35 #include "wxCDMFileDescriptionPanel.h"
36
37 #include<sstream>
38
39 #include "wxCDMMainFrame.h"
40
41 #include "creaDevManagerIds.h"
42 #include "images/FlIcon64.xpm"
43
44 BEGIN_EVENT_TABLE(wxCDMFileDescriptionPanel, wxPanel)
45 EVT_HYPERLINK(ID_BUTTON_PREV, wxCDMFileDescriptionPanel::OnBtnReturn)
46 EVT_BUTTON(ID_BUTTON_OPEN_FOLDER, wxCDMFileDescriptionPanel::OnBtnOpenFolder)
47 EVT_BUTTON(ID_BUTTON_OPEN_COMMAND, wxCDMFileDescriptionPanel::OnBtnOpenWithCommand)
48 END_EVENT_TABLE()
49
50 wxCDMFileDescriptionPanel::wxCDMFileDescriptionPanel(
51     wxWindow* parent,
52     modelCDMFile* file,
53     wxWindowID id,
54     const wxString& caption,
55     const wxPoint& pos,
56     const wxSize& size,
57     long style
58 )
59 {
60   wxCDMFileDescriptionPanel::Create(parent, file, id, caption, pos, size, style);
61 }
62
63 wxCDMFileDescriptionPanel::~wxCDMFileDescriptionPanel()
64 {
65 }
66
67 bool wxCDMFileDescriptionPanel::Create(
68     wxWindow* parent,
69     modelCDMFile* file,
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->file = file;
79   CreateControls();
80   // this part makes the scrollbars show up
81   this->FitInside(); // ask the sizer about the needed size
82   this->SetScrollRate(5, 5);
83   return TRUE;
84 }
85
86 void wxCDMFileDescriptionPanel::CreateControls()
87 {
88   wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
89
90   //Links to return
91   wxBoxSizer *linksSizer = new wxBoxSizer(wxHORIZONTAL);
92   std::vector<modelCDMIProjectTreeNode*> parents = this->file->GetParents();
93   for (int i = 0; i < (int)(parents.size()); i++)
94     {
95       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);
96       returnLnk->SetWindowStyle(wxNO_BORDER);
97       returnLnk->SetToolTip(crea::std2wx("Return to " + parents[parents.size()-1-i]->GetName() + "."));
98       linksSizer->Add(returnLnk, 0, wxALIGN_CENTER_VERTICAL | wxLEFT | wxRIGHT, 5);
99       linksSizer->Add(new wxStaticText(this,wxID_ANY, wxT("/")), 0, wxALIGN_CENTER, 0);
100     }
101
102   linksSizer->Add(new wxStaticText(this, wxID_ANY, crea::std2wx(this->file->GetName())), 0, wxALIGN_CENTER, 0);
103
104   sizer->Add(linksSizer, 0, wxALIGN_CENTER | wxALL, 5);
105
106   //Header
107   wxBoxSizer* headerSizer = new wxBoxSizer(wxHORIZONTAL);
108   {
109     //Image
110     headerSizer->Add(new wxStaticBitmap(this, -1, wxBitmap(FlIcon64)),0, wxALIGN_CENTER, 0);
111     wxBoxSizer* textSizer = new wxBoxSizer(wxVERTICAL);
112     //Title
113     textSizer->Add(new wxStaticText(this, -1, _("File")),0, wxALIGN_LEFT, 0);
114     //File Name
115     textSizer->Add(new wxStaticText(this, -1, crea::std2wx(this->file->GetName())),0, wxALIGN_LEFT, 0);
116     headerSizer->Add(textSizer, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
117   }
118   sizer->Add(headerSizer, 0, wxALIGN_CENTER);
119
120   //File Properties
121   wxStaticBoxSizer* propertiesBox = new wxStaticBoxSizer(wxVERTICAL, this, wxT("&Properties"));
122   wxPanel* propertiesPanel = new wxPanel(this);
123   wxBoxSizer* propertiesPanelSizer = new wxBoxSizer(wxVERTICAL);
124   wxFlexGridSizer* propertiesGridSizer = new wxFlexGridSizer(4, 2, 9, 15);
125
126   wxStaticText *pLocation = new wxStaticText(propertiesPanel, -1, wxT("Location"));
127   wxStaticText *pLength = new wxStaticText(propertiesPanel, -1, wxT("File Size"));
128
129   wxStaticText* pLocationtc = new wxStaticText(propertiesPanel, wxID_ANY, crea::std2wx(this->file->GetPath()));
130   pLocationtc->SetMaxSize(wxSize(300,-1));
131   int lgth = this->file->GetLength();
132   std::stringstream ss;
133   ss << lgth / 1024;
134   std::string lgths = ss.str() + " KB";
135   wxStaticText* pLengthtc = new wxStaticText(propertiesPanel, wxID_ANY, crea::std2wx(lgths));
136
137   propertiesGridSizer->Add(pLocation, 0, wxALIGN_RIGHT | wxALIGN_TOP);
138   propertiesGridSizer->Add(pLocationtc, 1, wxEXPAND);
139   propertiesGridSizer->Add(pLength, 0, wxALIGN_RIGHT | wxALIGN_TOP);
140   propertiesGridSizer->Add(pLengthtc, 1, wxEXPAND);
141
142   propertiesGridSizer->AddGrowableCol(1,1);
143
144   propertiesPanelSizer -> Add(propertiesGridSizer, 1, wxEXPAND);
145   propertiesPanel->SetSizer(propertiesPanelSizer);
146   propertiesPanelSizer->Fit(propertiesPanel);
147   propertiesBox->Add(propertiesPanel, 1, wxALL|wxEXPAND, 5);
148
149   sizer->Add(propertiesBox, 0, wxEXPAND | wxALL, 10);
150
151
152   //Actions
153   wxStaticBoxSizer* actionsBox = new wxStaticBoxSizer(wxHORIZONTAL, this, wxT("&Actions"));
154   wxPanel* actionsPanel = new wxPanel(this);
155   wxBoxSizer* actionsPanelSizer = new wxBoxSizer(wxHORIZONTAL);
156   //actionsGrid Sizer
157   wxFlexGridSizer* actionsGridSizer = new wxFlexGridSizer(1, 2, 9, 15);
158
159   wxButton* openCommandbt = new wxButton(actionsPanel, ID_BUTTON_OPEN_COMMAND, _T("Open with Command"));
160   openCommandbt->SetToolTip(wxT("Open this file executing a command in a terminal/command line."));
161   actionsGridSizer->Add(openCommandbt, 1, wxALL | wxEXPAND, 5);
162   wxButton* openFolderbt = new wxButton(actionsPanel, ID_BUTTON_OPEN_FOLDER, _T("Open Containing Folder"));
163   openFolderbt->SetToolTip(wxT("Open the folder where this file is located in the file explorer."));
164   actionsGridSizer->Add(openFolderbt, 1, wxALL | wxEXPAND, 5);
165
166   actionsGridSizer->AddGrowableCol(0,1);
167   actionsGridSizer->AddGrowableCol(1,1);
168
169   actionsPanelSizer->Add(actionsGridSizer, 1, wxEXPAND, 0);
170   actionsPanel->SetSizer(actionsPanelSizer);
171   actionsPanelSizer->Fit(actionsPanel);
172   actionsBox->Add(actionsPanel, 1, wxEXPAND);
173   sizer -> Add(actionsBox, 0, wxEXPAND | wxALL, 10);
174
175   //Assign sizer
176   SetSizer(sizer);
177   sizer->SetSizeHints(this);
178 }
179
180 void wxCDMFileDescriptionPanel::OnBtnReturn(wxHyperlinkEvent& event)
181 {
182   std::vector<modelCDMIProjectTreeNode*> parents = this->file->GetParents();
183   std::string parentURL = crea::wx2std(((wxHyperlinkCtrl*)event.GetEventObject())->GetURL());
184   //std::cout << parentURL << std::endl;
185   for (int i = 0; i < (int)(parents.size()); i++)
186     {
187       if (parents[i]->GetPath() == parentURL)
188         {
189           wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_DISPLAY_CHANGED);
190           newEvent->SetClientData(parents[i]);
191           newEvent->SetId(0);
192           wxPostEvent(this->GetParent(), *newEvent);
193         }
194     }
195 }
196
197 void wxCDMFileDescriptionPanel::OnBtnOpenFolder(wxCommandEvent& event)
198 {
199   std::string* result;
200   if(!this->file->OpenInFileExplorer(result))
201     wxMessageBox(crea::std2wx(*result),_T("Open Folder - Error!"),wxOK | wxICON_ERROR);
202 }
203
204 void wxCDMFileDescriptionPanel::OnBtnOpenWithCommand(wxCommandEvent& event)
205 {
206   //get command
207   wxString commandEx = wxGetTextFromUser(
208       _T("Enter the command to execute file"),
209       _T("Execute File - creaDevManager"),
210       _T("")
211   );
212   //check name
213   if(commandEx.Len() > 0)
214     {
215       std::string* result;
216       if(!this->file->OpenFile(result, crea::wx2std(commandEx)))
217         wxMessageBox(crea::std2wx(*result),_T("Execute File - Error!"),wxOK | wxICON_ERROR);
218     }
219 }