2 # ---------------------------------------------------------------------
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
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
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.
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
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 # ------------------------------------------------------------------------
29 * wxCDMBlackBoxDescriptionPanel.cpp
31 * Created on: Nov 27, 2012
32 * Author: Daniel Felipe Gonzalez Obando
35 #include "wxCDMFileDescriptionPanel.h"
39 #include "wxCDMMainFrame.h"
41 #include "creaDevManagerIds.h"
42 #include "images/FlIcon64.xpm"
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)
50 wxCDMFileDescriptionPanel::wxCDMFileDescriptionPanel(
54 const wxString& caption,
60 wxCDMFileDescriptionPanel::Create(parent, file, id, caption, pos, size, style);
63 wxCDMFileDescriptionPanel::~wxCDMFileDescriptionPanel()
67 bool wxCDMFileDescriptionPanel::Create(
71 const wxString& caption,
77 wxPanel::Create(parent, id, pos, size, style);
83 void wxCDMFileDescriptionPanel::CreateControls()
85 wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
88 wxBoxSizer *linksSizer = new wxBoxSizer(wxHORIZONTAL);
89 std::vector<modelCDMIProjectTreeNode*> parents = this->file->GetParents();
90 for (int i = 0; i < (int)(parents.size()); i++)
92 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);
93 returnLnk->SetWindowStyle(wxNO_BORDER);
94 returnLnk->SetToolTip(crea::std2wx("Return to " + parents[parents.size()-1-i]->GetName() + "."));
95 linksSizer->Add(returnLnk, 0, wxALIGN_CENTER_VERTICAL | wxLEFT | wxRIGHT, 5);
96 if (i < (int)(parents.size())-1)
98 linksSizer->Add(new wxStaticText(this,wxID_ANY, wxT("/")), 0, wxALIGN_CENTER, 0);
101 sizer->Add(linksSizer, 0, wxALIGN_CENTER | wxALL, 5);
104 wxBoxSizer* headerSizer = new wxBoxSizer(wxHORIZONTAL);
107 headerSizer->Add(new wxStaticBitmap(this, -1, wxBitmap(FlIcon64)),0, wxALIGN_CENTER, 0);
108 wxBoxSizer* textSizer = new wxBoxSizer(wxVERTICAL);
110 textSizer->Add(new wxStaticText(this, -1, _("File")),0, wxALIGN_LEFT, 0);
112 textSizer->Add(new wxStaticText(this, -1, crea::std2wx(this->file->GetName())),0, wxALIGN_LEFT, 0);
113 headerSizer->Add(textSizer, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
115 sizer->Add(headerSizer, 0, wxALIGN_CENTER);
118 wxStaticBoxSizer* propertiesBox = new wxStaticBoxSizer(wxVERTICAL, this, wxT("&Properties"));
119 wxPanel* propertiesPanel = new wxPanel(this);
120 wxBoxSizer* propertiesPanelSizer = new wxBoxSizer(wxVERTICAL);
121 wxFlexGridSizer* propertiesGridSizer = new wxFlexGridSizer(4, 2, 9, 15);
123 wxStaticText *pLocation = new wxStaticText(propertiesPanel, -1, wxT("Location"));
124 wxStaticText *pLength = new wxStaticText(propertiesPanel, -1, wxT("File Size"));
126 wxStaticText* pLocationtc = new wxStaticText(propertiesPanel, wxID_ANY, crea::std2wx(this->file->GetPath()));
127 pLocationtc->SetMaxSize(wxSize(350,-1));
128 int lgth = this->file->GetLength();
129 std::stringstream ss;
131 std::string lgths = ss.str() + " KB";
132 wxStaticText* pLengthtc = new wxStaticText(propertiesPanel, wxID_ANY, crea::std2wx(lgths));
134 propertiesGridSizer->Add(pLocation, 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL);
135 propertiesGridSizer->Add(pLocationtc, 1, wxEXPAND);
136 propertiesGridSizer->Add(pLength, 0, wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL);
137 propertiesGridSizer->Add(pLengthtc, 1, wxEXPAND);
139 propertiesGridSizer->AddGrowableCol(1,1);
141 propertiesPanelSizer -> Add(propertiesGridSizer, 1, wxEXPAND);
142 propertiesPanel->SetSizer(propertiesPanelSizer);
143 propertiesPanelSizer->Fit(propertiesPanel);
144 propertiesBox->Add(propertiesPanel, 1, wxALL|wxEXPAND, 5);
146 sizer->Add(propertiesBox, 0, wxEXPAND | wxALL, 10);
150 wxStaticBoxSizer* actionsBox = new wxStaticBoxSizer(wxHORIZONTAL, this, wxT("&Actions"));
151 wxPanel* actionsPanel = new wxPanel(this);
152 wxBoxSizer* actionsPanelSizer = new wxBoxSizer(wxHORIZONTAL);
154 wxFlexGridSizer* actionsGridSizer = new wxFlexGridSizer(1, 2, 9, 15);
156 wxButton* openCommandbt = new wxButton(actionsPanel, ID_BUTTON_OPEN_COMMAND, _T("Open with Command"));
157 openCommandbt->SetToolTip(wxT("Open this file executing a command in a terminal/command line."));
158 actionsGridSizer->Add(openCommandbt, 1, wxALL | wxEXPAND, 5);
159 wxButton* openFolderbt = new wxButton(actionsPanel, ID_BUTTON_OPEN_FOLDER, _T("Open Containing Folder"));
160 openFolderbt->SetToolTip(wxT("Open the folder where this file is located in the file explorer."));
161 actionsGridSizer->Add(openFolderbt, 1, wxALL | wxEXPAND, 5);
163 actionsGridSizer->AddGrowableCol(0,1);
164 actionsGridSizer->AddGrowableCol(1,1);
166 actionsPanelSizer->Add(actionsGridSizer, 1, wxEXPAND, 0);
167 actionsPanel->SetSizer(actionsPanelSizer);
168 actionsPanelSizer->Fit(actionsPanel);
169 actionsBox->Add(actionsPanel, 1, wxEXPAND);
170 sizer -> Add(actionsBox, 0, wxEXPAND | wxALL, 10);
174 sizer->SetSizeHints(this);
177 void wxCDMFileDescriptionPanel::OnBtnReturn(wxHyperlinkEvent& event)
179 std::vector<modelCDMIProjectTreeNode*> parents = this->file->GetParents();
180 std::string parentURL = crea::wx2std(((wxHyperlinkCtrl*)event.GetEventObject())->GetURL());
181 //std::cout << parentURL << std::endl;
182 for (int i = 0; i < (int)(parents.size()); i++)
184 if (parents[i]->GetPath() == parentURL)
186 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_DISPLAY_CHANGED);
187 newEvent->SetClientData(parents[i]);
189 wxPostEvent(this->GetParent(), *newEvent);
194 void wxCDMFileDescriptionPanel::OnBtnOpenFolder(wxCommandEvent& event)
197 if(!this->file->OpenInFileExplorer(result))
198 wxMessageBox(crea::std2wx(*result),_T("Open Folder - Error!"),wxOK | wxICON_ERROR);
201 void wxCDMFileDescriptionPanel::OnBtnOpenWithCommand(wxCommandEvent& event)
204 wxString commandEx = wxGetTextFromUser(
205 _T("Enter the command to execute file"),
206 _T("Execute File - creaDevManager"),
210 if(commandEx.Len() > 0)
213 if(!this->file->OpenFile(result, crea::wx2std(commandEx)))
214 wxMessageBox(crea::std2wx(*result),_T("Execute File - Error!"),wxOK | wxICON_ERROR);