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 * wxCDMCodeFileDescriptionPanel.cpp
31 * Created on: Jun 24, 2013
32 * Author: Daniel Felipe Gonzalez Obando
35 #include "wxCDMCodeFileDescriptionPanel.h"
39 #include "wxCDMMainFrame.h"
41 #include "creaDevManagerIds.h"
42 #include "images/CFIcon64.xpm"
44 BEGIN_EVENT_TABLE(wxCDMCodeFileDescriptionPanel, wxPanel)
45 EVT_HYPERLINK(ID_BUTTON_PREV, wxCDMCodeFileDescriptionPanel::OnBtnReturn)
46 EVT_BUTTON(ID_BUTTON_OPEN_FILE, wxCDMCodeFileDescriptionPanel::OnBtnOpenInEditor)
47 EVT_BUTTON(ID_BUTTON_OPEN_COMMAND, wxCDMCodeFileDescriptionPanel::OnBtnOpenWithCommand)
48 EVT_BUTTON(ID_BUTTON_OPEN_FOLDER, wxCDMCodeFileDescriptionPanel::OnBtnOpenFolder)
51 wxCDMCodeFileDescriptionPanel::wxCDMCodeFileDescriptionPanel(
53 modelCDMCodeFile* codefile,
55 const wxString& caption,
61 wxCDMCodeFileDescriptionPanel::Create(parent, codefile, id, caption, pos, size, style);
64 wxCDMCodeFileDescriptionPanel::~wxCDMCodeFileDescriptionPanel()
68 bool wxCDMCodeFileDescriptionPanel::Create(
70 modelCDMCodeFile* codefile,
72 const wxString& caption,
78 wxPanel::Create(parent, id, pos, size, style);
79 this->codeFile = codefile;
81 // this part makes the scrollbars show up
82 this->FitInside(); // ask the sizer about the needed size
84 //EED 2017-09-16 Migration wxWidgets 2.8 to 3.0
85 #if wxMAJOR_VERSION <= 2
86 this->SetScrollRate(5, 5);
88 printf ("EED wxCDMPackageDescriptionPanel::Create Change 05\n");
95 void wxCDMCodeFileDescriptionPanel::CreateControls()
97 wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
100 wxBoxSizer *linksSizer = new wxBoxSizer(wxHORIZONTAL);
101 std::vector<modelCDMIProjectTreeNode*> parents = this->codeFile->GetParents();
102 for (int i = 0; i < (int)(parents.size()); i++)
104 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);
105 returnLnk->SetWindowStyle(wxNO_BORDER);
106 returnLnk->SetToolTip(crea::std2wx("Return to " + parents[parents.size()-1-i]->GetName() + "."));
107 linksSizer->Add(returnLnk, 0, wxALIGN_CENTER_VERTICAL | wxLEFT | wxRIGHT, 5);
108 linksSizer->Add(new wxStaticText(this,wxID_ANY, wxT("/")), 0, wxALIGN_CENTER, 0);
111 linksSizer->Add(new wxStaticText(this, wxID_ANY, crea::std2wx(this->codeFile->GetName())), 0, wxALIGN_CENTER, 0);
113 sizer->Add(linksSizer, 0, wxALIGN_CENTER | wxALL, 5);
116 wxBoxSizer* headerSizer = new wxBoxSizer(wxHORIZONTAL);
119 headerSizer->Add(new wxStaticBitmap(this, -1, wxBitmap(CFIcon64)),0, wxALIGN_CENTER, 0);
120 wxBoxSizer* textSizer = new wxBoxSizer(wxVERTICAL);
122 textSizer->Add(new wxStaticText(this, -1, _("Code File")),0, wxALIGN_LEFT, 0);
124 textSizer->Add(new wxStaticText(this, -1, crea::std2wx(this->codeFile->GetName())),0, wxALIGN_LEFT, 0);
125 headerSizer->Add(textSizer, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
127 sizer->Add(headerSizer, 0, wxALIGN_CENTER);
130 wxStaticBoxSizer* propertiesBox = new wxStaticBoxSizer(wxVERTICAL, this, wxT("&Properties"));
131 wxPanel* propertiesPanel = new wxPanel(this);
132 wxBoxSizer* propertiesPanelSizer = new wxBoxSizer(wxVERTICAL);
133 wxFlexGridSizer* propertiesGridSizer = new wxFlexGridSizer(4, 2, 9, 15);
135 wxStaticText *pLocation = new wxStaticText(propertiesPanel, -1, wxT("Location"));
136 wxStaticText *pLength = new wxStaticText(propertiesPanel, -1, wxT("File Size"));
138 wxStaticText* pLocationtc = new wxStaticText(propertiesPanel, wxID_ANY, crea::std2wx(this->codeFile->GetPath()));
139 pLocationtc->SetMaxSize(wxSize(300,-1));
140 int lgth = this->codeFile->GetLength();
141 std::stringstream ss;
143 std::string lgths = ss.str() + " KB";
144 wxStaticText* pLengthtc = new wxStaticText(propertiesPanel, wxID_ANY, crea::std2wx(lgths));
146 propertiesGridSizer->Add(pLocation, 0, wxALIGN_RIGHT | wxALIGN_TOP);
147 propertiesGridSizer->Add(pLocationtc, 1, wxEXPAND);
148 propertiesGridSizer->Add(pLength, 0, wxALIGN_RIGHT | wxALIGN_TOP);
149 propertiesGridSizer->Add(pLengthtc, 1, wxEXPAND);
151 propertiesGridSizer->AddGrowableCol(1,1);
153 propertiesPanelSizer -> Add(propertiesGridSizer, 1, wxEXPAND);
154 propertiesPanel->SetSizer(propertiesPanelSizer);
155 propertiesPanelSizer->Fit(propertiesPanel);
156 propertiesBox->Add(propertiesPanel, 1, wxALL|wxEXPAND, 5);
158 sizer->Add(propertiesBox, 0, wxEXPAND | wxALL, 10);
162 wxStaticBoxSizer* actionsBox = new wxStaticBoxSizer(wxHORIZONTAL, this, wxT("&Actions"));
163 wxPanel* actionsPanel = new wxPanel(this);
164 wxBoxSizer* actionsPanelSizer = new wxBoxSizer(wxHORIZONTAL);
166 wxFlexGridSizer* actionsGridSizer = new wxFlexGridSizer(2, 2, 9, 15);
168 wxButton* editfilebt = new wxButton(actionsPanel, ID_BUTTON_OPEN_FILE, _T("Open File"));
169 editfilebt->SetToolTip(wxT("Open the code file in the default text editor."));
170 actionsGridSizer->Add(editfilebt, 1, wxALL | wxEXPAND, 5);
171 wxButton* openFolderbt = new wxButton(actionsPanel, ID_BUTTON_OPEN_FOLDER, _T("Open Containing Folder"));
172 openFolderbt->SetToolTip(wxT("Open the folder where the code file is located in the file explorer."));
173 actionsGridSizer->Add(openFolderbt, 1, wxALL | wxEXPAND, 5);
174 wxButton* openfilebt = new wxButton(actionsPanel, ID_BUTTON_OPEN_COMMAND, _T("Open With Command"));
175 openfilebt->SetToolTip(wxT("Open the code file with a specific command."));
176 actionsGridSizer->Add(openfilebt, 1, wxALL | wxEXPAND, 5);
178 actionsGridSizer->AddGrowableCol(0,1);
179 actionsGridSizer->AddGrowableCol(1,1);
181 actionsPanelSizer->Add(actionsGridSizer, 1, wxEXPAND, 0);
182 actionsPanel->SetSizer(actionsPanelSizer);
183 actionsPanelSizer->Fit(actionsPanel);
184 actionsBox->Add(actionsPanel, 1, wxEXPAND);
185 sizer -> Add(actionsBox, 0, wxEXPAND | wxALL, 10);
189 sizer->SetSizeHints(this);
192 void wxCDMCodeFileDescriptionPanel::OnBtnReturn(wxHyperlinkEvent& event)
194 std::vector<modelCDMIProjectTreeNode*> parents = this->codeFile->GetParents();
195 std::string parentURL = crea::wx2std(((wxHyperlinkCtrl*)event.GetEventObject())->GetURL());
196 //std::cout << parentURL << std::endl;
197 for (int i = 0; i < (int)(parents.size()); i++)
199 if (parents[i]->GetPath() == parentURL)
201 wxCommandEvent* newEvent = new wxCommandEvent(wxEVT_DISPLAY_CHANGED);
202 newEvent->SetClientData(parents[i]);
204 wxPostEvent(this->GetParent(), *newEvent);
209 void wxCDMCodeFileDescriptionPanel::OnBtnOpenInEditor(wxCommandEvent& event)
212 if(!this->codeFile->OpenFile(result))
213 wxMessageBox(crea::std2wx(*result),_T("Open Code File - Error!"),wxOK | wxICON_ERROR);
216 void wxCDMCodeFileDescriptionPanel::OnBtnOpenWithCommand(wxCommandEvent& event)
219 wxString commandEx = wxGetTextFromUser(
220 _T("Enter the command to execute file"),
221 _T("Execute File - creaDevManager"),
225 if(commandEx.Len() > 0)
228 if(!((modelCDMFile*)this->codeFile)->OpenFile(result, crea::wx2std(commandEx)))
229 wxMessageBox(crea::std2wx(*result),_T("Execute Code File - Error!"),wxOK | wxICON_ERROR);
233 void wxCDMCodeFileDescriptionPanel::OnBtnOpenFolder(wxCommandEvent& event)
236 if(!this->codeFile->OpenInFileExplorer(result))
237 wxMessageBox(crea::std2wx(*result),_T("Open File in Folder - Error!"),wxOK | wxICON_ERROR);