]> Creatis software - crea.git/blob - lib/creaDevManagerLib/wxCDMFileDescriptionPanel.cpp
Feature #1711
[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_BUTTON(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   return TRUE;
81 }
82
83 void wxCDMFileDescriptionPanel::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   //Header
93   wxBoxSizer* headerSizer = new wxBoxSizer(wxHORIZONTAL);
94   {
95     //Image
96     headerSizer->Add(new wxStaticBitmap(this, -1, wxBitmap(FlIcon64)),0, wxALIGN_CENTER, 0);
97     wxBoxSizer* textSizer = new wxBoxSizer(wxVERTICAL);
98     //Title
99     textSizer->Add(new wxStaticText(this, -1, _("File")),0, wxALIGN_LEFT, 0);
100     //File Name
101     textSizer->Add(new wxStaticText(this, -1, crea::std2wx(this->file->GetName())),0, wxALIGN_LEFT, 0);
102     headerSizer->Add(textSizer, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
103   }
104   sizer->Add(headerSizer, 0, wxALIGN_CENTER);
105
106   //File Properties
107   wxStaticBoxSizer* propertiesBox = new wxStaticBoxSizer(wxVERTICAL, this, wxT("&Properties"));
108   wxPanel* propertiesPanel = new wxPanel(this);
109   wxBoxSizer* propertiesPanelSizer = new wxBoxSizer(wxVERTICAL);
110   wxFlexGridSizer* propertiesGridSizer = new wxFlexGridSizer(4, 2, 9, 15);
111
112   wxStaticText *pLocation = new wxStaticText(propertiesPanel, -1, wxT("Location"));
113   wxStaticText *pLength = new wxStaticText(propertiesPanel, -1, wxT("File Size"));
114
115   wxStaticText* pLocationtc = new wxStaticText(propertiesPanel, wxID_ANY, crea::std2wx(this->file->GetPath()));
116   pLocationtc->SetMaxSize(wxSize(350,-1));
117   int lgth = this->file->GetLength();
118   std::stringstream ss;
119   ss << lgth / 1024;
120   std::string lgths = ss.str() + " KB";
121   wxStaticText* pLengthtc = new wxStaticText(propertiesPanel, wxID_ANY, crea::std2wx(lgths));
122
123   propertiesGridSizer->Add(pLocation, 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL);
124   propertiesGridSizer->Add(pLocationtc, 1, wxEXPAND);
125   propertiesGridSizer->Add(pLength, 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL);
126   propertiesGridSizer->Add(pLengthtc, 1, wxEXPAND);
127
128   propertiesGridSizer->AddGrowableCol(1,1);
129
130   propertiesPanelSizer -> Add(propertiesGridSizer, 1, wxEXPAND);
131   propertiesPanel->SetSizer(propertiesPanelSizer);
132   propertiesPanelSizer->Fit(propertiesPanel);
133   propertiesBox->Add(propertiesPanel, 0, wxALL, 5);
134
135   sizer->Add(propertiesBox, 0, wxEXPAND | wxALL, 10);
136
137
138   //Actions
139   wxStaticBoxSizer* actionsBox = new wxStaticBoxSizer(wxHORIZONTAL, this, wxT("&Actions"));
140   wxPanel* actionsPanel = new wxPanel(this);
141   wxBoxSizer* actionsPanelSizer = new wxBoxSizer(wxHORIZONTAL);
142   //actionsGrid Sizer
143   wxFlexGridSizer* actionsGridSizer = new wxFlexGridSizer(1, 2, 9, 15);
144
145   wxButton* openCommandbt = new wxButton(actionsPanel, ID_BUTTON_OPEN_COMMAND, _T("Open with Command"));
146   openCommandbt->SetToolTip(wxT("Open this file executing a command in a terminal/command line."));
147   actionsGridSizer->Add(openCommandbt, 1, wxALL | wxEXPAND, 5);
148   wxButton* openFolderbt = new wxButton(actionsPanel, ID_BUTTON_OPEN_FOLDER, _T("Open Containing Folder"));
149   openFolderbt->SetToolTip(wxT("Open the folder where this file is located in the file explorer."));
150   actionsGridSizer->Add(openFolderbt, 1, wxALL | wxEXPAND, 5);
151
152   actionsGridSizer->AddGrowableCol(0,1);
153   actionsGridSizer->AddGrowableCol(1,1);
154
155   actionsPanelSizer->Add(actionsGridSizer, 1, wxEXPAND, 0);
156   actionsPanel->SetSizer(actionsPanelSizer);
157   actionsPanelSizer->Fit(actionsPanel);
158   actionsBox->Add(actionsPanel, 1, wxEXPAND);
159   sizer -> Add(actionsBox, 0, wxEXPAND | wxALL, 10);
160
161   //Assign sizer
162   SetSizer(sizer);
163   sizer->SetSizeHints(this);
164 }
165
166 void wxCDMFileDescriptionPanel::OnBtnReturn(wxCommandEvent& event)
167 {
168   wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_DISPLAY_CHANGED);
169   newEvent->SetInt(((wxCDMMainFrame*)this->GetParent())->GetModel()->GetProject()->GetId());
170   newEvent->SetId(0);
171   wxPostEvent(this->GetParent(), *newEvent);
172 }
173
174 void wxCDMFileDescriptionPanel::OnBtnOpenFolder(wxCommandEvent& event)
175 {
176   std::string* result;
177   if(!this->file->OpenInFileExplorer(result))
178     wxMessageBox(crea::std2wx(*result),_T("Open Folder - Error!"),wxOK | wxICON_ERROR);
179 }
180
181 void wxCDMFileDescriptionPanel::OnBtnOpenWithCommand(wxCommandEvent& event)
182 {
183   //get command
184   wxString commandEx = wxGetTextFromUser(
185       _T("Enter the command to execute file"),
186       _T("Execute File - creaDevManager"),
187       _T("")
188   );
189   //check name
190   if(commandEx.Len() > 0)
191     {
192       std::string* result;
193       if(!this->file->OpenFile(result, crea::wx2std(commandEx)))
194         wxMessageBox(crea::std2wx(*result),_T("Execute File - Error!"),wxOK | wxICON_ERROR);
195     }
196 }