NCBI C++ ToolKit
file_load_option_panel.cpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 /* $Id: file_load_option_panel.cpp 44286 2019-11-22 15:51:34Z katargir $
2  * ===========================================================================
3  *
4  * PUBLIC DOMAIN NOTICE
5  * National Center for Biotechnology Information
6  *
7  * This software/database is a "United States Government Work" under the
8  * terms of the United States Copyright Act. It was written as part of
9  * the author's official duties as a United States Government employee and
10  * thus cannot be copyrighted. This software/database is freely available
11  * to the public for use. The National Library of Medicine and the U.S.
12  * Government have not placed any restriction on its use or reproduction.
13  *
14  * Although all reasonable efforts have been taken to ensure the accuracy
15  * and reliability of the software and data, the NLM and the U.S.
16  * Government do not and cannot warrant the performance or results that
17  * may be obtained by using this software or data. The NLM and the U.S.
18  * Government disclaim all warranties, express or implied, including
19  * warranties of performance, merchantability or fitness for any particular
20  * purpose.
21  *
22  * Please cite the author in any work or product based on this material.
23  *
24  * ===========================================================================
25  *
26  * Authors:
27  *
28  * File Description:
29  *
30  */
31 #include <ncbi_pch.hpp>
32 
39 
40 ////@begin includes
41 ////@end includes
42 
43 
44 #include <wx/sizer.h>
45 #include <wx/choice.h>
46 #include <wx/statbox.h>
47 #include <wx/stattext.h>
48 #include <wx/msgdlg.h>
49 #include <wx/bitmap.h>
50 #include <wx/icon.h>
51 #include <wx/filename.h>
52 #include <wx/txtstrm.h>
53 #include <wx/sstream.h>
54 #include <wx/checkbox.h>
55 #include <wx/settings.h>
56 
57 
59 
60 
61 IMPLEMENT_DYNAMIC_CLASS( CFileLoadOptionPanel, wxPanel )
62 
63 BEGIN_EVENT_TABLE(CFileLoadOptionPanel, wxPanel)
64 ////@begin CFileLoadOptionPanel event table entries
66 
67  EVT_HTML_LINK_CLICKED( ID_HTMLWINDOW, CFileLoadOptionPanel::OnMRUWindowLinkClicked )
68 
69 ////@end CFileLoadOptionPanel event table entries
72 
73 
75  : m_Manager(), m_FileMRU(), m_MRUFileClicked(false), m_MRUFormat(-1)
76 {
77  Init();
78 }
79 
80 
81 CFileLoadOptionPanel::CFileLoadOptionPanel( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style )
82  : m_Manager(), m_FileMRU(), m_MRUFileClicked(false), m_MRUFormat(-1)
83 {
84  Init();
85  Create(parent, id, pos, size, style);
86 }
87 
88 
89 bool CFileLoadOptionPanel::Create( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style )
90 {
91 ////@begin CFileLoadOptionPanel creation
92  wxPanel::Create( parent, id, pos, size, style );
93 
95  if (GetSizer())
96  {
97  GetSizer()->SetSizeHints(this);
98  }
99  Centre();
100 ////@end CFileLoadOptionPanel creation
101  return true;
102 }
103 
104 
106 {
107 ////@begin CFileLoadOptionPanel destruction
108 ////@end CFileLoadOptionPanel destruction
109 }
110 
111 
113 {
114 ////@begin CFileLoadOptionPanel member initialisation
115  m_FormatList = NULL;
117  m_FileInput = NULL;
118  m_MRUWindow = NULL;
119 ////@end CFileLoadOptionPanel member initialisation
120  m_CurrFormat = -1;
121 }
122 
123 
125 {
126 ////@begin CFileLoadOptionPanel content construction
127  CFileLoadOptionPanel* itemPanel1 = this;
128 
129  wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL);
130  itemPanel1->SetSizer(itemBoxSizer2);
131 
132  wxBoxSizer* itemBoxSizer3 = new wxBoxSizer(wxHORIZONTAL);
133  itemBoxSizer2->Add(itemBoxSizer3, 0, wxGROW|wxALL, 0);
134 
135  wxStaticText* itemStaticText4 = new wxStaticText( itemPanel1, wxID_STATIC, _("File Format:"), wxDefaultPosition, wxDefaultSize, 0 );
136  itemBoxSizer3->Add(itemStaticText4, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
137 
138  wxArrayString m_FormatListStrings;
139  m_FormatList = new wxChoice( itemPanel1, ID_CHOICE, wxDefaultPosition, wxDefaultSize, m_FormatListStrings, 0 );
140  itemBoxSizer3->Add(m_FormatList, 1, wxALIGN_CENTER_VERTICAL|wxALL, 5);
141 
142  m_CheckFormat = new wxCheckBox( itemPanel1, ID_CHECKBOX6, _("Verify that the file data match the selected file format"), wxDefaultPosition, wxDefaultSize, 0 );
143  m_CheckFormat->SetValue(false);
144  itemBoxSizer2->Add(m_CheckFormat, 0, wxALIGN_LEFT|wxLEFT|wxRIGHT, 5);
145 
146  wxStaticText* itemStaticText7 = new wxStaticText( itemPanel1, wxID_STATIC, _("Filenames or URLs:"), wxDefaultPosition, wxDefaultSize, 0 );
147  itemBoxSizer2->Add(itemStaticText7, 0, wxALIGN_LEFT|wxLEFT|wxRIGHT|wxTOP, 5);
148 
149  m_FileInput = new CMultiFileInput( itemPanel1, ID_FILE_INPUT, wxDefaultPosition, wxSize(300, 100), wxSUNKEN_BORDER|wxTAB_TRAVERSAL );
150  itemBoxSizer2->Add(m_FileInput, 1, wxGROW|wxALL, 5);
151 
152  wxStaticText* itemStaticText9 = new wxStaticText( itemPanel1, wxID_STATIC, _("Recently used Files:"), wxDefaultPosition, wxDefaultSize, 0 );
153  itemBoxSizer2->Add(itemStaticText9, 0, wxALIGN_LEFT|wxLEFT|wxRIGHT|wxTOP, 5);
154 
155  m_MRUWindow = new CwxHtmlWindow( itemPanel1, ID_HTMLWINDOW, wxDefaultPosition, wxSize(200, 150), wxHW_SCROLLBAR_AUTO|wxSUNKEN_BORDER|wxHSCROLL|wxVSCROLL );
156  itemBoxSizer2->Add(m_MRUWindow, 1, wxGROW|wxALL, 5);
157 
158 ////@end CFileLoadOptionPanel content construction
159 
160  m_MRUWindow->SetBorders(2);
161  m_MRUWindow->SetStandardFonts();
162 }
163 
164 
166 {
167  m_Manager = manager;
168 }
169 
171 {
172  m_MRUFileClicked = false;
173  m_MRUFormat = -1;
174  m_MRUFile.empty();
175 }
176 
178 {
179  m_FileMRU = &file_mru;
180  m_MRUFilenames.clear();
181 
182  x_FillMRUList();
183 }
184 
185 static string sFormatTimePeriod(CTime& t_now, CTime& t_before)
186 {
187  CTimeFormat format("b D, H:m p");
188  return t_before.ToLocalTime().AsString(format);
189 }
190 
192 {
194 
195  if (m_FileMRU) {
196  CTime now(CTime::eCurrent);
197 
198  typedef TFileMRU::TTimeToTMap TMap;
199  const TMap& map = m_FileMRU->GetMap();
200 
201  wxStringOutputStream strstrm;
202  wxTextOutputStream os(strstrm);
203 
204  os << wxT("<html><body>");
205 
206  for( TMap::const_reverse_iterator it = map.rbegin(); it != map.rend(); ++it) {
207  time_t t = it->first;
208  CTime tm(t);
209  wxString name, ext, filename = it->second.GetFileName();
210 
211  wxFileName::SplitPath(filename, 0, &name, &ext);
212  if( ! ext.empty()) {
213  name += wxT(".") + ext;
214  }
215 
216  os << wxT("<b><a href=\"") << (wxInt32)m_MRUFilenames.size() << wxT("\">") << name
217  << wxT("</a></b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;")
218  << wxT("<font color=#808080>last&nbsp;used&nbsp;&nbsp;")
219  << ToWxString(sFormatTimePeriod(now, tm)) << wxT("</font><br />")
220  << wxT("<small>") << filename << wxT("</small><br />");
221 
222  m_MRUFilenames.push_back(it->second);
223  }
224 
225  os << wxT("</body></html>");
226 
227  m_MRUWindow->SetPage(strstrm.GetString());
228  }
229 
230  m_MRUWindow->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW));
231 }
232 
234 {
235  if (index == wxNOT_FOUND)
236  return;
237 
238  wxString filename = m_MRUFilenames[index].GetFileName();
239  string manager_id = m_MRUFilenames[index].GetFileLoaderId();
240  wxString manager_label = m_MRUFilenames[index].GetFileLoaderLabel();
241 
242  if (!CCompressedFile::FileExists(filename)) {
243  wxString err_msg = wxT("The file: \"") + filename + wxT("\" doesn't exist.");
244  wxMessageBox(err_msg, wxT("Error"), wxOK | wxICON_ERROR, this);
245  return;
246  }
247 
248  int format_index = -1;
249  for (size_t i = 0; i < m_Formats.size(); ++i) {
250  if (m_Formats[i].m_Id == manager_id) {
251  format_index = (int)i;
252  break;
253  }
254  }
255 
256  if (format_index < 0) {
257  wxString err_msg = wxT("File loader \"") + manager_label + wxT("\" not found.");
258  wxMessageBox(err_msg, wxT("Error"), wxOK | wxICON_ERROR, this);
259  return;
260  }
261 
262  m_MRUFileClicked = true;
263  m_MRUFormat = format_index;
264  m_MRUFile = filename;
265 
266  wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, wxID_FORWARD);
267  event.SetEventObject(this);
268  AddPendingEvent(event);
269 }
270 
271 void CFileLoadOptionPanel::SetFormats(const vector<CFormatDescriptor>& formats)
272 {
273  m_Formats = formats;
274 
275  size_t n = m_Formats.size();
276 
277  for(size_t i = 0; i < n; i++) {
278  if (!m_Formats[i].m_Hidden) {
279  m_FormatList->Append(m_Formats[i].m_Label, (void*)i);
280  }
281  }
282 
283  if (m_FormatList->GetCount() > 0) {
284  m_FormatList->SetSelection(0);
285  int format = (int)(intptr_t)m_FormatList->GetClientData(0);
287  }
288 }
289 
290 
292 {
294 }
295 
296 void CFileLoadOptionPanel::GetSelectedFormat(wxString& selected_format)
297 {
298  selected_format = m_FormatList->GetString(m_FormatList->GetSelection());
299 }
300 
301 
303 {
305 
306  for (unsigned int i = 0; i < m_FormatList->GetCount(); ++i) {
307  int entryFormat = (int)(intptr_t)m_FormatList->GetClientData(i);
308  if (entryFormat == format) {
309  m_FormatList->SetSelection((int)i);
310  break;
311  }
312  }
313 }
314 
316 {
317  m_CheckFormat->SetValue(value);
318 }
319 
320 
322 {
323  return m_CheckFormat->IsChecked();
324 }
325 
326 
327 void CFileLoadOptionPanel::GetFilenames(vector<wxString>& filenames) const
328 {
329  if (m_MRUFileClicked)
330  filenames.push_back(m_MRUFile);
331  else {
333  }
334 }
335 
336 
337 void CFileLoadOptionPanel::SetFilenames(const vector<wxString>& filenames)
338 {
340 }
341 
342 
344 {
345  return true;
346 }
347 
348 
349 void CFileLoadOptionPanel::OnLoadFiles(wxCommandEvent& event)
350 {
351  bool ok = true;
352  if(ok) {
353  wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, wxID_FORWARD);
354  event.SetEventObject(this);
355  AddPendingEvent(event);
356  }
357 }
358 
359 
360 void CFileLoadOptionPanel::OnFormatListSelected( wxCommandEvent& event )
361 {
362  int index = m_FormatList->GetSelection();
363  if (index >= 0) {
364  int format = (int)(intptr_t)m_FormatList->GetClientData((unsigned int)index);
367  }
368 }
369 
370 
372 {
373  m_CurrFormat = index;
374  m_FileInput->SetWildcard(m_Formats[index].m_WildCards);
375  m_FileInput->SetSingleMode(m_Formats[index].m_SingleFile);
376 }
377 
378 void CFileLoadOptionPanel::OnMRUWindowLinkClicked( wxHtmlLinkEvent& event )
379 {
380  const wxHtmlLinkInfo info = event.GetLinkInfo();
381  long index;
382  if (info.GetHref().ToLong(&index))
383  x_LoadMRUFile((int)index);
384 }
385 
386 wxBitmap CFileLoadOptionPanel::GetBitmapResource( const wxString& name )
387 {
388 ////@begin CFileLoadOptionPanel bitmap retrieval
389  wxUnusedVar(name);
390  return wxNullBitmap;
391 ////@end CFileLoadOptionPanel bitmap retrieval
392 }
393 
394 
395 wxIcon CFileLoadOptionPanel::GetIconResource( const wxString& name )
396 {
397 ////@begin CFileLoadOptionPanel icon retrieval
398  wxUnusedVar(name);
399  return wxNullIcon;
400 ////@end CFileLoadOptionPanel icon retrieval
401 }
402 
static bool FileExists(const wxString &fileName)
CFileLoadManager CFileLoadManager - a Loader Manager implementing "File" option in "Open" dialog.
virtual void OnFormatChanged()
called by File Format panel when a user selects a format
wxIcon GetIconResource(const wxString &name)
void SetFilenames(const vector< wxString > &filenames)
void SetMRU(const TFileMRU &file_mru)
bool Create(wxWindow *parent, wxWindowID id=ID_CFILELOADOPTIONPANEL, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(400, 300), long style=wxTAB_TRAVERSAL)
void OnFormatListSelected(wxCommandEvent &event)
void SetManager(CFileLoadManager *manager)
vector< CFormatDescriptor > m_Formats
void GetFilenames(vector< wxString > &filenames) const
void SetCheckFormat(bool value=true)
void OnMRUWindowLinkClicked(wxHtmlLinkEvent &event)
wxBitmap GetBitmapResource(const wxString &name)
vector< CFileLoadManager::CFileDescriptor > m_MRUFilenames
void OnLoadFiles(wxCommandEvent &event)
void SetFormats(const vector< CFormatDescriptor > &formats)
CMultiFileInput.
void GetFilenames(vector< wxString > &filenames) const
void SetWildcard(const wxString &wildcard)
void SetSingleMode(bool single)
void SetFilenames(const vector< wxString > &filenames)
CTimeFormat –.
Definition: ncbitime.hpp:131
const TTimeToTMap & GetMap() const
Definition: mru_list.hpp:149
CTime –.
Definition: ncbitime.hpp:296
Definition: map.hpp:338
#define _(proto)
Definition: ct_nlmzip_i.h:78
static string sFormatTimePeriod(CTime &t_now, CTime &t_before)
#define false
Definition: bool.h:36
static void Init(void)
Definition: cursor6.c:76
#define NULL
Definition: ncbistd.hpp:225
int intptr_t
Definition: ncbitype.h:185
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
CTime & ToLocalTime(void)
Convert the time into local time.
Definition: ncbitime.hpp:2464
string AsString(const CTimeFormat &format=kEmptyStr, TSeconds out_tz=eCurrentTimeZone) const
Transform time to string.
Definition: ncbitime.cpp:1512
@ eCurrent
Use current time. See also CCurrentTime.
Definition: ncbitime.hpp:300
unsigned int
A callback function used to compare two keys in a database.
Definition: types.hpp:1210
#define ID_CHOICE
END_EVENT_TABLE()
int i
yy_size_t n
static MDB_envinfo info
Definition: mdb_load.c:37
#define wxT(x)
Definition: muParser.cpp:41
const struct ncbi::grid::netcache::search::fields::SIZE size
const GenericPointer< typename T::ValueType > T2 value
Definition: pointer.h:1227
EIPRangeType t
Definition: ncbi_localip.c:101
static Format format
Definition: njn_ioutil.cpp:53
static int filenames
Definition: pcre2grep.c:247
#define _ASSERT
wxString ToWxString(const string &s)
Definition: wx_utils.hpp:173
Modified on Fri Sep 20 14:58:08 2024 by modify_doxy.py rev. 669887