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

Go to the SVN repository for this file.

1 /* $Id: project_load_option_panel.cpp 47464 2023-04-20 00:19:10Z evgeniev $
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 
32 #include <ncbi_pch.hpp>
33 
34 #include <corelib/ncbitime.hpp>
35 
36 ////@begin includes
37 ////@end includes
38 
40 
44 
45 #include <wx/sizer.h>
46 #include <wx/stattext.h>
47 #include <wx/statbox.h>
48 #include <wx/button.h>
49 #include <wx/msgdlg.h>
50 #include <wx/icon.h>
51 #include <wx/filename.h>
52 #include <wx/txtstrm.h>
53 #include <wx/sstream.h>
54 
55 
57 
58 
59 IMPLEMENT_DYNAMIC_CLASS( CProjectLoadOptionPanel, wxPanel )
60 
61 BEGIN_EVENT_TABLE( CProjectLoadOptionPanel, wxPanel )
62 ////@begin CProjectLoadOptionPanel event table entries
63  EVT_LISTBOX_DCLICK( ID_RECENT_LIST, CProjectLoadOptionPanel::OnRecentListDoubleClicked )
64  EVT_HTML_LINK_CLICKED( ID_RECENT_LIST, CProjectLoadOptionPanel::OnRecentListLinkClicked )
65 
66 ////@end CProjectLoadOptionPanel event table entries
68 
69 
71 {
72  Init();
73 }
74 
75 
76 CProjectLoadOptionPanel::CProjectLoadOptionPanel( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style )
77 {
78  Init();
79  Create(parent, id, pos, size, style);
80 }
81 
82 
83 bool CProjectLoadOptionPanel::Create( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style )
84 {
85 ////@begin CProjectLoadOptionPanel creation
86  wxPanel::Create( parent, id, pos, size, style );
87 
89  if (GetSizer())
90  {
91  GetSizer()->SetSizeHints(this);
92  }
93  Centre();
94 ////@end CProjectLoadOptionPanel creation
95  return true;
96 }
97 
99 {
100 ////@begin CProjectLoadOptionPanel destruction
101 ////@end CProjectLoadOptionPanel destruction
102 }
103 
104 
106 {
107 ////@begin CProjectLoadOptionPanel member initialisation
108  m_FilePanel = NULL;
109  m_MRUListBox = NULL;
110 ////@end CProjectLoadOptionPanel member initialisation
111 
112  m_FileMRU = NULL;
113  m_SelectedFilenames.clear();
114 }
115 
116 
118 {
119 ////@begin CProjectLoadOptionPanel content construction
120  CProjectLoadOptionPanel* itemPanel1 = this;
121 
122  wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL);
123  itemPanel1->SetSizer(itemBoxSizer2);
124 
125  wxBoxSizer* itemBoxSizer3 = new wxBoxSizer(wxHORIZONTAL);
126  itemBoxSizer2->Add(itemBoxSizer3, 0, wxGROW, 5);
127 
128  wxStaticText* itemStaticText4 = new wxStaticText( itemPanel1, wxID_STATIC, _("Please select Projects."), wxDefaultPosition, wxDefaultSize, 0 );
129  itemBoxSizer3->Add(itemStaticText4, 0, wxGROW|wxALL, 5);
130 
131  m_FilePanel = new CMultiFileInput( itemPanel1, ID_FILE_PANEL, wxDefaultPosition, wxSize(200, 100), wxSUNKEN_BORDER|wxTAB_TRAVERSAL );
132  itemBoxSizer2->Add(m_FilePanel, 1, wxGROW|wxALL, 5);
133 
134  wxStaticText* itemStaticText6 = new wxStaticText( itemPanel1, wxID_STATIC, _("Recently used Projects:"), wxDefaultPosition, wxDefaultSize, 0 );
135  itemBoxSizer2->Add(itemStaticText6, 0, wxALIGN_LEFT|wxLEFT|wxRIGHT|wxTOP, 5);
136 
137  wxArrayString m_MRUListBoxStrings;
138  m_MRUListBox = new wxSimpleHtmlListBox( itemPanel1, ID_RECENT_LIST, wxDefaultPosition, wxSize(200, 100), m_MRUListBoxStrings, wxHLB_MULTIPLE|wxSUNKEN_BORDER );
139  itemBoxSizer2->Add(m_MRUListBox, 1, wxGROW|wxALL, 5);
140 
141 ////@end CProjectLoadOptionPanel content construction
142 
143  m_FilePanel->SetFocus();
144 
145  static wxString wildcard(wxT("Projects (*.gbp)|*.gbp|Projects(*.gbp)|*.gbp"));
146 
147  m_FilePanel->SetDlgAttrs(wxT("Open Project"), wxEmptyString, wildcard, this);
148 }
149 
150 
151 string sFormatTimePeriod(CTime& t_now, CTime& t_before)
152 {
153  CTimeFormat format("b D, H:m p");
154  return t_before.ToLocalTime().AsString(format);
155 }
156 
157 
159 {
161 
162  if(m_FileMRU) {
163  CTime now(CTime::eCurrent);
164 
165  typedef TFileMRU::TTimeToTMap TMap;
166  const TMap& map = m_FileMRU->GetMap();
167 
168  for( TMap::const_reverse_iterator it = map.rbegin(); it != map.rend(); ++it) {
169  time_t t = it->first;
170  CTime tm(t);
171 
172  wxString name, ext, filename = it->second;
173  if (m_InvalidFiles.find(filename) != m_InvalidFiles.end())
174  continue;
175 
176  wxFileName::SplitPath(filename, 0, &name, &ext);
177  if( ! ext.empty()) {
178  name += wxT(".") + ext;
179  }
180 
181  wxStringOutputStream strstrm;
182  wxTextOutputStream os(strstrm);
183 
184  os << wxT("<b><a href=\"") << (wxInt32)m_MRUListBox->GetCount() << wxT("\">")
185  << name << wxT("</a></b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;")
186  << wxT("<font color=#808080>last&nbsp;used&nbsp;&nbsp;") << ToWxString(sFormatTimePeriod(now, tm)) << wxT("</font><br />")
187  << wxT("<small>") << filename << wxT("</small>");
188 
189  m_MRUListBox->Append(strstrm.GetString());
190  m_MRUFilenames.push_back(filename);
191  }
192  }
193 }
194 
195 
197 {
198  m_FileMRU = &file_mru;
199 
200  m_MRUListBox->Clear();
201  m_MRUFilenames.clear();
202 
203  x_FileMRUList();
204 }
205 
206 
208 {
209  wxCommandEvent new_event(wxEVT_COMMAND_BUTTON_CLICKED, wxID_FORWARD);
210  new_event.SetEventObject(this);
211  AddPendingEvent(new_event);
212 }
213 
214 
216 {
217  const wxHtmlLinkInfo info = event.GetLinkInfo();
218  long index;
219  if (info.GetHref().ToLong(&index))
220  m_MRUListBox->SetSelection(static_cast<int>(index));
221 
222  wxCommandEvent new_event(wxEVT_COMMAND_BUTTON_CLICKED, wxID_FORWARD);
223  new_event.SetEventObject(this);
224  AddPendingEvent(new_event);
225 }
226 
227 
228 
230 {
231  unsigned long cookie;
232  int index = m_MRUListBox->GetFirstSelected(cookie);
233 
234  while(index != wxNOT_FOUND) {
235  filenames.push_back(m_MRUFilenames[index]);
236  index = m_MRUListBox->GetNextSelected(cookie);
237  }
238 }
239 
240 
242 {
243  wxString s;
245  s += *it;
246  }
247  return s;
248 }
249 
250 
252 {
253  vector<wxString> filenames;
256  return x_Finish(filenames);
257 }
258 
259 // finish this page
260 bool CProjectLoadOptionPanel::x_Finish(const vector<wxString>& filenames)
261 {
262  wxString err_msg;
263  set<wxString> invalid_files;
264 
265  if( ! filenames.empty()) {
266  // verify that there is no duplication
267  // verify that files exist
268 
269  set<wxString> processed;
270  set<wxString> duplicates;
271 
272  int ws_count = 0;
273  int prj_count = 0;
274 
275  // gather statistics
276  for( size_t i = 0; i < filenames.size(); i++ ) {
277  wxString filename = filenames[i];
278  if(processed.find(filename) != processed.end()) {
279  duplicates.insert(filename);
280  } else {
281  processed.insert(filename);
282 
283  if (CCompressedFile::FileExists(filename)) {
284  wxString ext;
285  wxFileName::SplitPath(filename, 0, 0, &ext);
286  if (ext == wxT("gbw")) {
287  ws_count++;
288  } else if (ext == wxT("gbp")) {
289  prj_count++;
290  } else {
291  invalid_files.insert(filename);
292  }
293  } else {
294  invalid_files.insert(filename);
295  }
296  }
297  //LOG_POST(" " << filename);
298  }
299 
300  // analyze statistics
301  if( ! duplicates.empty()) {
302  err_msg = wxT("The following files are duplicated :\n\n");
303  err_msg += sFilenameSetToString(duplicates);
304  } else if( ! invalid_files.empty()) {
305  err_msg = wxT("The following files are invalid or do not exist:\n\n");
306  err_msg += sFilenameSetToString(invalid_files);
307  } else {
308  if(ws_count >= 1) {
309  err_msg = wxT("This version of Genome Workbench can't handle workspace files.");
310  } else {
311  _ASSERT((prj_count > 0));
312  }
313  }
314  } else {
315  err_msg = wxT("Please select a Project to load!");
316  }
317  if( ! err_msg.empty()) {
318  wxMessageBox(err_msg, wxT("Errors in input"),
319  wxOK | wxICON_ERROR, this);
320 
321  if( ! invalid_files.empty()) {
322  m_InvalidFiles.insert(invalid_files.begin(), invalid_files.end());
323  m_MRUListBox->DeselectAll();
324  m_MRUListBox->Clear();
325  m_MRUFilenames.clear();
326  x_FileMRUList();
327  }
328  } else {
329  /// everything is Ok, go to the next step
331  return true;
332  //wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, wxID_FORWARD);
333  //event.SetEventObject(this);
334  //AddPendingEvent(event);
335  }
336  return false;
337 }
338 
339 
341 {
343  return;
344 }
345 
346 
348 {
349  return true;
350 }
351 
352 
353 wxBitmap CProjectLoadOptionPanel::GetBitmapResource( const wxString& name )
354 {
355  // Bitmap retrieval
356 ////@begin CProjectLoadOptionPanel bitmap retrieval
357  wxUnusedVar(name);
358  return wxNullBitmap;
359 ////@end CProjectLoadOptionPanel bitmap retrieval
360 }
361 
362 
363 wxIcon CProjectLoadOptionPanel::GetIconResource( const wxString& name )
364 {
365  // Icon retrieval
366 ////@begin CProjectLoadOptionPanel icon retrieval
367  wxUnusedVar(name);
368  return wxNullIcon;
369 ////@end CProjectLoadOptionPanel icon retrieval
370 }
371 
372 
static bool FileExists(const wxString &fileName)
CMultiFileInput.
void GetFilenames(vector< wxString > &filenames) const
void SetDlgAttrs(const wxString &title, const wxString &dir, const wxString &wildcard, wxWindow *parent)
CProjectLoadOptionPanel CProjectLoadOptionPanel - dialog panel for loading Projects and Workspaces.
wxBitmap GetBitmapResource(const wxString &name)
void SetMRU(const TFileMRU &file_mru)
wxIcon GetIconResource(const wxString &name)
void OnRecentListLinkClicked(wxHtmlLinkEvent &event)
void x_GetSelectedMRUFilenames(vector< wxString > &filenames)
void OnRecentListDoubleClicked(wxCommandEvent &event)
wxSimpleHtmlListBox * m_MRUListBox
bool x_Finish(const vector< wxString > &filenames)
bool Create(wxWindow *parent, wxWindowID id=ID_CPROJECTLOADOPTIONPANEL, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(400, 300), long style=wxTAB_TRAVERSAL)
void GetProjectFilenames(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
Definition: set.hpp:45
iterator_bool insert(const value_type &val)
Definition: set.hpp:149
const_iterator begin() const
Definition: set.hpp:135
bool empty() const
Definition: set.hpp:133
const_iterator find(const key_type &key) const
Definition: set.hpp:137
const_iterator end() const
Definition: set.hpp:136
#define _(proto)
Definition: ct_nlmzip_i.h:78
static void Init(void)
Definition: cursor6.c:76
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
Definition: ncbimisc.hpp:815
#define NULL
Definition: ncbistd.hpp:225
#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
END_EVENT_TABLE()
int i
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
EIPRangeType t
Definition: ncbi_localip.c:101
Defines: CTimeFormat - storage class for time format.
static Format format
Definition: njn_ioutil.cpp:53
static int filenames
Definition: pcre2grep.c:247
wxString sFilenameSetToString(const set< wxString > &filenames)
string sFormatTimePeriod(CTime &t_now, CTime &t_before)
#define _ASSERT
wxString ToWxString(const string &s)
Definition: wx_utils.hpp:173
Modified on Fri Sep 20 14:58:00 2024 by modify_doxy.py rev. 669887