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

Go to the SVN repository for this file.

1 /* $Id: macrofloweditorapp.cpp 38070 06/07/2017 15:12:46 17:48:35Z Igor Filippov$
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: Igor Filippov
27  */
28 #include <ncbi_pch.hpp>
29 #include <corelib/ncbiapp.hpp>
30 #include <corelib/ncbiargs.hpp>
40 #include <serial/objistr.hpp>
41 #include <serial/objostr.hpp>
42 #include <serial/objectio.hpp>
43 #include <objmgr/scope.hpp>
45 #include <util/format_guess.hpp>
46 
47 
48 // For compilers that support precompilation, includes "wx/wx.h".
49 #include "wx/wxprec.h"
50 
51 #ifdef __BORLANDC__
52 #pragma hdrstop
53 #endif
54 
55 #ifndef WX_PRECOMP
56 #include "wx/wx.h"
57 #endif
58 
59 #include "wx/imaglist.h"
60 #include <wx/artprov.h>
61 #include <wx/evtloop.h>
62 #include <wx/wfstream.h>
63 #include <wx/stdpaths.h>
64 #include <wx/display.h>
65 #include <wx/txtstrm.h>
66 #include <wx/bmpbuttn.h>
67 
70 
71 
73 
74 /*
75  * CMacroFlowEditor type definition
76  */
77 
79 
80 
81 /*
82  * CMacroFlowEditor event table definition
83  */
84 
85 BEGIN_EVENT_TABLE( CMacroFlowEditor, wxFrame )
86 
87 ////@begin CMacroFlowEditor event table entries
89 
91 
94 
97 
100 
104 
106 
109 
111 
114 
117 
120 
123 
126 
129 
132 
135 
138 
141 
144 
147 
150  EVT_TEXT_ENTER( ID_TEXTCTRL, CMacroFlowEditor::OnFindClick )
151 
154 
155  EVT_TREE_ITEM_ACTIVATED( ID_TREECTRL, CMacroFlowEditor::OnTreectrlItemActivated )
156  EVT_TREE_BEGIN_DRAG( ID_TREECTRL, CMacroFlowEditor::OnTreectrlItemDrag )
158  EVT_TREE_ITEM_MENU( ID_TREECTRL, CMacroFlowEditor::OnTreectrlMenu )
159 
164 
169 
171 
176 
177 // EVT_CHECKBOX(ID_MACROFLOW_LOCK_DRAG, CMacroFlowEditor::OnLockDrag)
179 
180  EVT_CLOSE(CMacroFlowEditor::OnClose)
181  EVT_AUINOTEBOOK_PAGE_CLOSE(ID_NOTEBOOK, CMacroFlowEditor::OnPageClose)
182  EVT_AUINOTEBOOK_PAGE_CHANGED(ID_NOTEBOOK, CMacroFlowEditor::OnPageChanged)
183  EVT_AUINOTEBOOK_PAGE_CHANGING(ID_NOTEBOOK, CMacroFlowEditor::OnPageChanging)
184 
185  EVT_COLLAPSIBLEPANE_CHANGED(ID_COLLAPSIBLE_PANE, CMacroFlowEditor::OnCollapsiblePane)
186 
192 ////@end CMacroFlowEditor event table entries
193 
195 
196 
197 /*
198  * CMacroFlowEditor constructors
199  */
200 
202 {
203  Init();
204 }
205 
206 CMacroFlowEditor::CMacroFlowEditor( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
207  : m_standalone(true), m_HideLibrary(false), m_width(-1), m_height(-1), m_pos_x(-1), m_pos_y(-1),
208  m_width_add_macro(-1), m_height_add_macro(-1), m_pos_x_add_macro(-1), m_pos_y_add_macro(-1)
209 {
210  SetRegistryPath("Dialogs.Edit.MacroFlowEditor");
211  LoadSettings();
212 
213  Init();
214  Create( parent, id, caption, pos, size, style );
216  NMacroStats::ReportUsage(caption, "open");
217 }
218 
219 CMacroFlowEditor::CMacroFlowEditor( wxWindow* parent, CRef<IGuiCoreHelper> gui_core_helper,
220  wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
221  : m_gui_core_helper(gui_core_helper), m_standalone(false), m_HideLibrary(false), m_width(-1), m_height(-1), m_pos_x(-1), m_pos_y(-1),
222  m_width_add_macro(-1), m_height_add_macro(-1), m_pos_x_add_macro(-1), m_pos_y_add_macro(-1)
223 {
224  SetRegistryPath("Dialogs.Edit.MacroFlowEditor");
225  LoadSettings();
226 
227  Init();
228  Create( parent, id, caption, pos, size, style );
230  NMacroStats::ReportUsage(caption, "open");
231 }
232 
234 
236  wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
237 {
238  if (!m_Instance)
239  m_Instance = new CMacroFlowEditor( parent, gui_core_helper, id, caption, pos, size, style);
240  m_Instance->Show(true);
241  m_Instance->Restore();
242  m_Instance->Raise();
243  m_Instance->SetFocus();
244  return m_Instance;
245 }
246 
247 /*
248  * CMacroFlowEditor creator
249  */
250 
251 bool CMacroFlowEditor::Create( wxWindow* parent, wxWindowID id, const wxString& caption, const wxPoint& pos, const wxSize& size, long style )
252 {
253 ////@begin CMacroFlowEditor creation
254  wxFrame::Create( parent, id, caption, pos, size, style );
255 
256  CreateControls();
257  Centre();
258  m_colpane_width = 400 + 10;
259  if (m_HideLibrary) {
260  m_CollapsiblePanel->Collapse();
261  wxSize sz = GetSize();
262  SetSize(sz.GetWidth() - m_colpane_width, sz.GetHeight());
263  }
264  else {
265  m_CollapsiblePanel->Expand();
266  }
267 
268 ////@end CMacroFlowEditor creation
269  return true;
270 }
271 
272 
273 /*
274  * CMacroFlowEditor destructor
275  */
276 
278 {
279  if (m_UndoManager && m_undo_tse)
280  {
283  m_undo_tse.Reset();
284  }
285  if (m_MacroEditor) {
286  m_MacroEditor->Destroy();
287  }
288  m_Instance = NULL;
289  SaveSettings();
290 }
291 
292 void CMacroFlowEditor::SetRegistryPath(const string& reg_path)
293 {
294  m_RegPath = reg_path;
295 }
296 
298 {
299  return CSysPath::ResolvePath( wxT("<home>/macroflow_editor_settings.asn") );
300 }
301 
302 static const char* kOpenedScripts = "OpenedScriptList";
303 static const char* kDefaultLibrary = "DefaultLibrary";
304 static const char* kHideLibrary = "HideLibrary";
305 static const char* kDefaultLibraryLocation = "<std>/etc/macro_scripts/default_library.mql";
306 static const char* kFrameWidth = "Frame Width";
307 static const char* kFrameHeight = "Frame Height";
308 static const char* kFramePosX = "Frame Position X";
309 static const char* kFramePosY = "Frame Position Y";
310 static const char* kAddMacroWidth = "Add Macro Width";
311 static const char* kAddMacroHeight = "Add Macro Height";
312 static const char* kAddMacroPosX = "Add Macro Position X";
313 static const char* kAddMacroPosY = "Add Macro Position Y";
314 
316 {
317  if (m_RegPath.empty())
318  return;
319 
322 
323  view.Set(kFrameWidth,GetScreenRect().GetWidth());
324  view.Set(kFrameHeight,GetScreenRect().GetHeight());
325  view.Set(kFramePosX,GetScreenPosition().x);
326  view.Set(kFramePosY,GetScreenPosition().y);
327 
332 
335  view.Set(kHideLibrary, m_CollapsiblePanel->IsCollapsed());
336 
337  wxString path = GetSettingsPath();
338  if( !path.IsEmpty() )
339  {
340  CNcbiOfstream ostr( path.fn_str() );
341  gui_reg.Write( ostr , CGuiRegistry::ePriority_Local - 5);
342  }
343 }
344 
345 
347 {
348  if (m_RegPath.empty())
349  return;
350  wxString path = GetSettingsPath();
351  if( path.IsEmpty() )
352  return;
353 
354  if( !wxFileName::FileExists( path ) )
355  return;
356 
357  CNcbiIfstream istr( path.fn_str() );
358  if( !istr )
359  return;
360 
362  gui_reg.AddSite(istr, CGuiRegistry::ePriority_Local - 5);
363 
364  CRegistryReadView view = gui_reg.GetReadView(m_RegPath);
365 
366  m_width = view.GetInt(kFrameWidth, -1);
367  m_height = view.GetInt(kFrameHeight, -1);
368  m_pos_x = view.GetInt(kFramePosX, -1);
369  m_pos_y = view.GetInt(kFramePosY, -1);
370 
375 
376  m_opened_scripts.clear();
379  m_HideLibrary = view.GetBool(kHideLibrary, false);
380 }
381 
383 {
384  if (m_width >= 0 && m_height >= 0)
385  SetSize(wxSize(m_width, m_height));
386 
387  int width = GetScreenRect().GetWidth();
388  int height = GetScreenRect().GetHeight();
389  if (m_pos_x >= 0 && m_pos_y >= 0)
390  {
391  int max_x = 0;
392  for (auto i = 0; i < wxDisplay::GetCount(); i++) // also see gui/widgets/wx/wx_utils.cpp:CorrectWindowRect() for alternative window position validation
393  {
394  wxDisplay display(i);
395  max_x += display.GetGeometry().GetWidth();
396  }
397  if (m_pos_x + width > max_x) m_pos_x = wxGetDisplaySize().GetWidth()-width-5;
398  if (m_pos_y + height > wxGetDisplaySize().GetHeight()) m_pos_y = wxGetDisplaySize().GetHeight()-height-5;
399 
400  SetPosition(wxPoint(m_pos_x, m_pos_y));
401  }
402 }
403 
404 /*
405  * Member initialisation
406  */
407 
409 {
410 ////@begin CMacroFlowEditor member initialisation
413  m_TreeCtrl = NULL;
414  m_Notebook = NULL;
417  // m_LockDrag = NULL;
418  m_script_count = 0;
419  m_stop = false;
420  m_running = false;
421  m_found = 0;
422  m_loading_script = false;
423  m_loading_library = false;
424  m_MacroEditor = nullptr;
426  m_Lock = true;
427  m_SynFileCtrl = nullptr;
428 ////@end CMacroFlowEditor member initialisation
429 }
430 
431 
432 /*
433  * Control creation for CMacroFlowEditor
434  */
435 
437 {
438 ////@begin CMacroFlowEditor content construction
439  wxMenuBar* menuBar = new wxMenuBar;
440  wxMenu* itemMenu3 = new wxMenu;
441  itemMenu3->Append(ID_MACROFLOW_NEW, _("New Script\tCtrl+N"), wxEmptyString, wxITEM_NORMAL);
442  itemMenu3->Append(ID_MACROFLOW_OPEN, _("Open Script...\tCtrl+O"), wxEmptyString, wxITEM_NORMAL);
443  itemMenu3->Append(ID_MACROFLOW_SAVE, _("Save Script\tCtrl+S"), wxEmptyString, wxITEM_NORMAL);
444  itemMenu3->Append(ID_MACROFLOW_SAVE_AS, _("Save Script As..."), wxEmptyString, wxITEM_NORMAL);
445  itemMenu3->Append(ID_MACROFLOW_EXPORT_STEPS, _("Export Script Summary..."), wxEmptyString, wxITEM_NORMAL);
446 
447  m_recent_submenu = new wxMenu();
448  itemMenu3->AppendSubMenu(m_recent_submenu, _("Recent Scripts"));
449 
451  m_recent_submenu->Bind(wxEVT_MENU, &CMacroFlowEditor::OnRecent, this);
452  itemMenu3->AppendSeparator();
453 
454  wxMenu* autofix_menu = new wxMenu;
455  itemMenu3->AppendSubMenu(autofix_menu, "Save Autofix Scripts");
456  autofix_menu->Append(ID_MACROFLOW_SAVEAUTOFIXGB, _("Autofix GB"), wxEmptyString, wxITEM_NORMAL);
457  autofix_menu->Append(ID_MACROFLOW_SAVEAUTOFIXWGS, _("Autofix WGS"), wxEmptyString, wxITEM_NORMAL);
458  autofix_menu->Append(ID_MACROFLOW_SAVEAUTOFIXTSA, _("Autofix TSA"), wxEmptyString, wxITEM_NORMAL);
459  autofix_menu->Append(ID_MACROFLOW_SAVESYN, _("Default substitution file (\"synonyms.txt\")"), wxEmptyString, wxITEM_NORMAL);
460  itemMenu3->AppendSeparator();
461 
462  itemMenu3->Append(ID_IMPORT_MENU, _("Import Library..."), wxEmptyString, wxITEM_NORMAL);
463  itemMenu3->Append(ID_EXPORT_MENU, _("Export Library..."), wxEmptyString, wxITEM_NORMAL);
464  itemMenu3->Append(ID_SET_LIB_MENU, _("Set Default Library..."), wxEmptyString, wxITEM_NORMAL);
465  itemMenu3->Append(ID_EDIT_LIB_MENU, _("Edit Library"), wxEmptyString, wxITEM_NORMAL);
466  itemMenu3->Append(wxID_EXIT, _("Exit\tCtrl+Q"), wxEmptyString, wxITEM_NORMAL);
467  menuBar->Append(itemMenu3, _("File"));
468 
469  wxMenu* itemMenu8 = new wxMenu;
470  itemMenu8->Append(ID_MACROFLOW_CUT, _("Cut\tCtrl+X"), wxEmptyString, wxITEM_NORMAL);
471  itemMenu8->Append(ID_MACROFLOW_COPY, _("Copy\tCtrl+C"), wxEmptyString, wxITEM_NORMAL);
472  itemMenu8->Append(ID_MACROFLOW_PASTE, _("Paste\tCtrl+V"), wxEmptyString, wxITEM_NORMAL);
473  itemMenu8->Append(ID_MACROFLOW_DELETE, _("Delete\tDel"), wxEmptyString, wxITEM_NORMAL);
474  itemMenu8->Append(ID_MACROFLOW_DUPLICATE, _("Duplicate\tCtrl+D"), wxEmptyString, wxITEM_NORMAL);
475  itemMenu8->Append(ID_MACROFLOW_APPEND, _("Add To Library\tAlt+A"), wxEmptyString, wxITEM_NORMAL);
476  itemMenu8->Append(ID_MACROFLOW_ADD, _("Add New Macro..."), wxEmptyString, wxITEM_NORMAL);
477  itemMenu8->Append(ID_MACROFLOW_ZOOM_IN, _("Increase Font\tAlt+I"), wxEmptyString, wxITEM_NORMAL);
478  itemMenu8->Append(ID_MACROFLOW_ZOOM_OUT, _("Decrease Font\tAlt+D"), wxEmptyString, wxITEM_NORMAL);
479 
480  menuBar->Append(itemMenu8, _("Edit"));
481  wxMenu* itemMenu16 = new wxMenu;
482  itemMenu16->Append(ID_MACROFLOW_FORWARD, _("Run script\tF5"), wxEmptyString, wxITEM_NORMAL);
483  itemMenu16->Append(ID_MACROFLOW_STOP, _("Stop script\tF1"), wxEmptyString, wxITEM_NORMAL);
484  itemMenu16->Append(ID_SKIP_STEP, _("Enable/Disable Step\tF3"), wxEmptyString, wxITEM_NORMAL);
485  if (!m_standalone)
486  {
487  itemMenu16->Append(ID_MACROFLOW_UNDO, _("Revert data edits\tCtrl+Z"), wxEmptyString, wxITEM_NORMAL);
488  }
489  menuBar->Append(itemMenu16, _("Run"));
490  SetMenuBar(menuBar);
491 
492  wxArtProvider::Push( new CwxSplittingArtProvider() );
493  wxFileArtProvider* provider = new wxFileArtProvider();
494  wxArtProvider::Push(provider);
495  provider->AddDirectory( CSysPath::ResolvePath( wxT("<res>") ));
496  provider->RegisterFileAlias(wxT("menu::dm_start"), wxT("play.png"));
497  provider->RegisterFileAlias(wxT("menu::dm_stop"), wxT("stop.png"));
498  provider->RegisterFileAlias(wxT("menu::search"), wxT("search.png"));
499  provider->RegisterFileAlias(wxT("menu::file_open"), wxT("file_open.png"));
500  provider->RegisterFileAlias(wxT("menu::plus"), wxT("plus.png"));
501  provider->RegisterFileAlias(wxT("menu::delete"), wxT("delete.png"));
502  provider->RegisterFileAlias(wxT("menu::lock"), wxT("lock.png"));
503  provider->RegisterFileAlias(wxT("menu::unlock"), wxT("unlock.png"));
504  provider->RegisterFileAlias(wxT("menu::dm_undo"), wxT("undo.png"));
505 
506  wxPanel* itemFrame1 = new wxPanel(this, wxID_ANY);
507  wxBoxSizer* itemBoxSizer2 = new wxBoxSizer(wxVERTICAL);
508  itemFrame1->SetSizer(itemBoxSizer2);
509 
510  m_toolbar = CreateToolBar( wxTB_FLAT|wxTB_HORIZONTAL, ID_TOOLBAR );
511  if (m_standalone)
512  {
513  wxStaticText* itemStaticText22 = new wxStaticText( m_toolbar, wxID_STATIC, _("Input File(s): "), wxDefaultPosition, wxDefaultSize, 0 );
514  m_toolbar->AddControl(itemStaticText22);
515 
516  m_InputFileText = new wxTextCtrl( m_toolbar, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize(200, -1), wxTE_READONLY );
517  m_toolbar->AddControl(m_InputFileText);
518 
519  wxBitmap itemtool20Bitmap(wxArtProvider::GetBitmap(wxT("menu::file_open"), wxART_TOOLBAR, wxSize(16,16))); // wxART_FILE_OPEN, wxART_TOOLBAR
520  wxBitmap itemtool20BitmapDisabled;
521  m_toolbar->AddTool(ID_FILECTRL, _("File"), itemtool20Bitmap, itemtool20BitmapDisabled, wxITEM_NORMAL, _("Input ASN.1 files"), wxEmptyString);
522  m_toolbar->AddSeparator();
523 
524  wxStaticText* itemStaticText24 = new wxStaticText( m_toolbar, wxID_STATIC, _("Output Dir: "), wxDefaultPosition, wxDefaultSize, 0 );
525  m_toolbar->AddControl(itemStaticText24);
526 
527  m_OutputFolder = new wxDirPickerCtrl( m_toolbar, ID_DIRPICKERCTRL, wxEmptyString, wxEmptyString, wxDefaultPosition, wxSize(200, -1), wxDIRP_DEFAULT_STYLE );
528  m_toolbar->AddControl(m_OutputFolder);
529 
531  m_OutputFolder->SetToolTip(_("Folder for output ASN.1 files"));
532  m_toolbar->AddSeparator();
533  }
534  m_Search = new wxTextCtrl( m_toolbar, ID_TEXTCTRL, wxEmptyString, wxDefaultPosition, wxSize(150, -1), wxTE_PROCESS_ENTER );
535  m_toolbar->AddControl(m_Search);
536 
537  wxBitmap itemtool21Bitmap(wxArtProvider::GetBitmap(wxT("menu::search"), wxART_TOOLBAR, wxSize(16,16)));
538  wxBitmap itemtool21BitmapDisabled;
539  m_toolbar->AddTool(ID_MACROFLOW_FIND, _("Search"), itemtool21Bitmap, itemtool21BitmapDisabled, wxITEM_NORMAL, _("Search for macro in the current script and the library"), wxEmptyString);
540  m_toolbar->AddSeparator();
541 
542  m_PlusBitmap = wxArtProvider::GetBitmap(wxT("menu::plus"), wxART_TOOLBAR, wxSize(16,16));
543  wxBitmap itemtool22BitmapDisabled;
544  m_toolbar->AddTool(ID_MACROFLOW_ADD, _("Add"), m_PlusBitmap, itemtool22BitmapDisabled, wxITEM_NORMAL, _("Add a new macro to the script"), wxEmptyString);
545 
546  if (!m_standalone) {
547  wxBitmap itemtool25Bitmap(wxArtProvider::GetBitmap(wxT("menu::dm_undo"), wxART_TOOLBAR, wxSize(16,16)));
548  wxBitmap itemtool25BitmapDisabled;
549  m_toolbar->AddTool(ID_MACROFLOW_UNDO, _("Revert data edits"), itemtool25Bitmap, itemtool25BitmapDisabled, wxITEM_NORMAL, _("Revert data edits"), wxEmptyString);
550  }
551 
552  wxBitmap itemtool23Bitmap(wxArtProvider::GetBitmap(wxT("menu::dm_start"), wxART_TOOLBAR, wxSize(16,16))); //wxART_GO_FORWARD, wxART_TOOLBAR
553  wxBitmap itemtool23BitmapDisabled;
554  m_toolbar->AddTool(ID_MACROFLOW_FORWARD, _("Run"), itemtool23Bitmap, itemtool23BitmapDisabled, wxITEM_NORMAL, _("Run script"), wxEmptyString);
555  wxBitmap itemtool24Bitmap(wxArtProvider::GetBitmap(wxT("menu::dm_stop"), wxART_TOOLBAR, wxSize(16,16))); // wxART_ERROR, wxART_TOOLBAR
556  wxBitmap itemtool24BitmapDisabled;
557  m_toolbar->AddTool(ID_MACROFLOW_STOP, _("Stop"), itemtool24Bitmap, itemtool24BitmapDisabled, wxITEM_NORMAL, _("Stop script"), wxEmptyString);
558 
559  m_LockBitmap = wxArtProvider::GetBitmap(wxT("menu::lock"), wxART_TOOLBAR, wxSize(16,16));
560  m_UnlockBitmap = wxArtProvider::GetBitmap(wxT("menu::unlock"), wxART_TOOLBAR, wxSize(16,16));
561  wxBitmap itemtool25BitmapDisabled;
562  m_toolbar->AddTool(ID_MACROFLOW_LOCK_DRAG, _("Lock dragging"), m_LockBitmap, itemtool25BitmapDisabled, wxITEM_NORMAL, _("Lock dragging"), wxEmptyString);
563  m_toolbar->AddSeparator();
564 
565  if (!m_standalone) {
566  wxStaticText* syn_text = new wxStaticText(m_toolbar, wxID_STATIC, _("Substitution File:"), wxDefaultPosition, wxDefaultSize, 0);
567  m_toolbar->AddControl(syn_text);
568 
569  m_SynFileCtrl = new wxTextCtrl(m_toolbar, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize(300, -1));
570  m_toolbar->AddControl(m_SynFileCtrl);
571 
572  wxBitmap synBitmap(wxArtProvider::GetBitmap(wxT("menu::file_open"), wxART_TOOLBAR, wxSize(16, 16)));
573  wxBitmap synBitmapDisabled;
574  m_toolbar->AddTool(ID_MACROFLOW_OPENSYNFILE, _("Select File"), synBitmap, synBitmapDisabled, wxITEM_NORMAL, _("Input text file"), wxEmptyString);
575  m_toolbar->EnableTool(ID_MACROFLOW_OPENSYNFILE, true);
576 
577  wxButton* updatesynfile = new wxButton(m_toolbar, ID_MACROFLOW_UPDATESYNFILE, _("Update Script"), wxDefaultPosition, wxDefaultSize, 0);
578  m_toolbar->AddControl(updatesynfile);
579 
580  wxButton* reportsynfile = new wxButton(m_toolbar, ID_MACROFLOW_REPORTSYNFILE, _("Report Status"), wxDefaultPosition, wxDefaultSize, 0);
581  reportsynfile->SetToolTip("Lookup existing word substitution files in the script");
582  m_toolbar->AddControl(reportsynfile);
583  }
584  else {
585  // mimick a second toolbar, as wxToolbar::SetRows(int) does not work
586  wxBoxSizer* syn_sizer = new wxBoxSizer(wxHORIZONTAL);
587  itemBoxSizer2->Add(syn_sizer, 0, wxGROW | wxALL, 0);
588 
589  wxStaticText* syn_text = new wxStaticText(itemFrame1, wxID_STATIC, _("Substitution File:"), wxDefaultPosition, wxDefaultSize, 0);
590  syn_sizer->Add(syn_text, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
591 
592  m_SynFileCtrl = new wxTextCtrl(itemFrame1, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize(300, -1));
593  syn_sizer->Add(m_SynFileCtrl, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
594 
595  wxButton* syn_btn = new wxBitmapButton(itemFrame1, ID_MACROFLOW_OPENSYNFILE, wxArtProvider::GetBitmap(wxT("menu::file_open")), wxDefaultPosition, wxDefaultSize);
596  syn_btn->SetToolTip(wxT("Choose a word substitution file..."));
597  syn_sizer->Add(syn_btn, 0, wxALIGN_CENTER_VERTICAL | wxTOP|wxBOTTOM, 3);
598 
599  wxButton* updatesynfile = new wxButton(itemFrame1, ID_MACROFLOW_UPDATESYNFILE, _("Update Script"), wxDefaultPosition, wxDefaultSize, 0);
600  syn_sizer->Add(updatesynfile, 0, wxALIGN_CENTER_VERTICAL | wxALL, 5);
601 
602  wxButton* reportsynfile = new wxButton(itemFrame1, ID_MACROFLOW_REPORTSYNFILE, _("Report Status"), wxDefaultPosition, wxDefaultSize, 0);
603  reportsynfile->SetToolTip("Lookup existing word substitution files in the script");
604  syn_sizer->Add(reportsynfile, 0, wxALIGN_CENTER_VERTICAL | wxTOP|wxBOTTOM, 5);
605  }
606 
607  //m_LockDrag = new wxCheckBox( m_toolbar, ID_MACROFLOW_LOCK_DRAG, _("Lock dragging"), wxDefaultPosition, wxDefaultSize);
608  //m_LockDrag->SetValue(true);
609  //m_toolbar->AddControl(m_LockDrag);
610 
611  m_toolbar->Realize();
612  SetToolBar(m_toolbar);
613 
614  wxStatusBar* statusbar = CreateStatusBar();
615  SetStatusBar(statusbar);
616 
617  wxBoxSizer* itemBoxSizer25 = new wxBoxSizer(wxHORIZONTAL);
618  itemBoxSizer2->Add(itemBoxSizer25, 1, wxGROW|wxALL, 0);
619 
620  m_CollapsiblePanel = new wxCollapsiblePane(itemFrame1, ID_COLLAPSIBLE_PANE, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxCP_DEFAULT_STYLE | wxFULL_REPAINT_ON_RESIZE);
621  itemBoxSizer25->Add(m_CollapsiblePanel, 0, wxGROW|wxALL, 0);
622 
624  wxBoxSizer* itemBoxSizer27 = new wxBoxSizer(wxVERTICAL);
625  m_CollapsibleWindow->SetSizer(itemBoxSizer27);
626 
627  wxStaticText* itemStaticText1 = new wxStaticText( m_CollapsibleWindow, wxID_STATIC, _("Library"), wxDefaultPosition, wxDefaultSize, 0 );
628  itemBoxSizer27->Add(itemStaticText1, 0, wxALIGN_CENTER_HORIZONTAL|wxALL, 5);
629 
630  m_TreeCtrl = new wxTreeCtrl(m_CollapsibleWindow, ID_TREECTRL, wxDefaultPosition, wxSize(400, -1), wxTR_DEFAULT_STYLE|wxTR_HIDE_ROOT|wxTR_SINGLE|wxTR_FULL_ROW_HIGHLIGHT|wxTR_NO_LINES );
631  itemBoxSizer27->Add(m_TreeCtrl, 1, wxGROW|wxALL, 5);
632 
633 
634  m_Notebook = new wxAuiNotebook( itemFrame1, ID_NOTEBOOK, wxDefaultPosition, wxDefaultSize, wxAUI_NB_DEFAULT_STYLE );
635  itemBoxSizer25->Add(m_Notebook, 1, wxGROW|wxALL, 5);
636 
637  wxBoxSizer* itemBoxSizer66 = new wxBoxSizer(wxHORIZONTAL);
638  itemBoxSizer2->Add(itemBoxSizer66, 0, wxGROW|wxALL, 5);
639 
640  m_Progress = new wxGauge( itemFrame1, wxID_ANY, 100, wxDefaultPosition, wxSize(-1, 5), wxGA_HORIZONTAL);
641  m_Progress->SetValue(0);
642  itemBoxSizer66->Add(m_Progress, 1, wxALIGN_BOTTOM|wxALL, 0);
643 
644 ////@end CMacroFlowEditor content construction
645 
646  if (m_standalone && wxTheApp->argc == 2)
647  {
648  wxString script = wxTheApp->argv[0];
649  wxString dir = wxTheApp->argv[1];
650  if (!script.IsEmpty()) {
651  OpenScript(script, false, true);
652  }
653  else {
654  CScriptPanel* page = new CScriptPanel(m_Notebook);
655  m_Notebook->AddPage(page, wxT("New script"), false);
656  }
657  if (!dir.IsEmpty()) {
658  m_DefaultDir = dir;
659  }
660  }
661  else {
662  CScriptPanel* page = new CScriptPanel(m_Notebook);
663  m_Notebook->AddPage(page, wxT("New script"), false);
664  }
665 
666  if (m_DefaultLibrary.empty())
667  {
669  }
670  ImportLibrary(wxString(m_DefaultLibrary), false);
671 
672  itemBoxSizer27->SetSizeHints(m_CollapsibleWindow);
673  itemBoxSizer2->SetSizeHints(itemFrame1);
674 }
675 
676 
678 {
680  if (library.IsEmpty())
681  return;
682  wxStandardPaths stdp = wxStandardPaths::Get();
683  const string doc_dir(stdp.GetDocumentsDir().ToUTF8());
684  const string macro_dir = CDirEntry::ConcatPathEx(doc_dir, "GbenchMacro");
685 
686  CDir dir(macro_dir);
687  if (!dir.Exists()) {
688  if (!dir.Create()) {
689  LOG_POST(Error << "Cannot create directory '" << macro_dir << "'");
690  return;
691  }
692  }
693  string name = "default_library";
694  string macro_file = CDirEntry::ConcatPathEx(macro_dir, name + ".mql");
695  CFile file(macro_file);
696  size_t i = 1;
697  while (file.Exists()) {
698  wxString str;
699  str << name << " (" << i << ")" << ".mql";
700  macro_file = CDirEntry::ConcatPathEx(macro_dir, str.ToStdString());
701  file = CFile(macro_file);
702  i++;
703  }
704 
705  CFile orig_file(ToStdString(library));
706  if (orig_file.Copy(macro_file)) {
707  m_DefaultLibrary = macro_file;
708  }
709 }
710 
712 {
713  for (auto id_path : m_id_to_path) {
714  m_recent_submenu->Delete(id_path.first);
715  }
717  for (auto path_it = m_opened_scripts.rbegin(); path_it != m_opened_scripts.rend(); ++path_it) {
718  wxFileName filename(*path_it);
719  wxMenuItem *script_item = new wxMenuItem(m_recent_submenu, wxID_ANY, filename.GetFullName(), wxEmptyString, wxITEM_NORMAL);
720  m_recent_submenu->Append(script_item);
721  m_id_to_path[script_item->GetId()] = *path_it;
722  }
723 }
724 
725 /*
726  * Should we show tooltips?
727  */
728 
730 {
731  return true;
732 }
733 
734 /*
735  * Get bitmap resources
736  */
737 
738 wxBitmap CMacroFlowEditor::GetBitmapResource( const wxString& name )
739 {
740  // Bitmap retrieval
741 ////@begin CMacroFlowEditor bitmap retrieval
742  wxUnusedVar(name);
743  return wxNullBitmap;
744 ////@end CMacroFlowEditor bitmap retrieval
745 }
746 
747 /*
748  * Get icon resources
749  */
750 
751 wxIcon CMacroFlowEditor::GetIconResource( const wxString& name )
752 {
753  // Icon retrieval
754 ////@begin CMacroFlowEditor icon retrieval
755  wxUnusedVar(name);
756  return wxNullIcon;
757 ////@end CMacroFlowEditor icon retrieval
758 }
759 
760 
761 /*
762  * wxEVT_COMMAND_MENU_SELECTED event handler for ID_MACROFLOW_NEW
763  */
764 
765 void CMacroFlowEditor::OnNewClick( wxCommandEvent& event )
766 {
767  wxString title = _("New script ");
768  m_script_count++;
769  title << m_script_count;
770  CScriptPanel* page = new CScriptPanel(m_Notebook);
771  m_Notebook->AddPage(page, title, true);
772 }
773 
774 
775 /*
776  * wxEVT_COMMAND_MENU_SELECTED event handler for ID_MACROFLOW_OPEN
777  */
778 
779 void CMacroFlowEditor::OnOpenClick( wxCommandEvent& event )
780 {
781  wxFileDialog file(this, wxT("Load macro script"), m_DefaultDir, wxEmptyString, _("All files (*.*)|*.*"), wxFD_OPEN | wxFD_FILE_MUST_EXIST);
782  if (file.ShowModal() != wxID_OK)
783  return;
784  wxString path = file.GetPath();
785  OpenScript(path, true, false);
786 }
787 
788 void CMacroFlowEditor::OpenScript(const wxString &path, bool recent_scripts, bool allow_empty)
789 {
790  if (path.IsEmpty())
791  return;
792 
793  m_loading_script = true;
794  wxFileName filename(path);
795  if (recent_scripts) {
796  m_opened_scripts.remove(path.ToStdString());
797  }
798  if (!filename.FileExists() && !allow_empty) {
799  NcbiErrorBox("Script not found");
800  m_loading_script = false;
801  return;
802  }
803 
804  if (recent_scripts) {
805  m_opened_scripts.push_back(path.ToStdString());
806  if (m_opened_scripts.size() > 10)
807  m_opened_scripts.pop_front();
809  }
810  m_DefaultDir = filename.GetPath();
811  {
812  wxBusyCursor wait;
813  wxYield();
814  macro::CMacroEngine engine;
815  vector<CRef<macro::CMacroRep>> macro_list;
816  bool status = engine.ReadAndParseMacros(path.ToStdString(), macro_list);
817  if (!status) {
818  macro_list.clear();
819  }
820  if (!allow_empty && macro_list.empty()) {
821  NcbiErrorBox("Error loading macro script");
822  m_loading_script = false;
823  return;
824  }
825 
826  CScriptPanel* page = new CScriptPanel(m_Notebook);
827  m_Notebook->AddPage(page, filename.GetFullName(), true);
828  page->SetPath(path);
829  SetStatusText(path);
830  m_Notebook->Refresh();
831  size_t i = 0;
832  size_t total = macro_list.size();
833 
834  page->Hide();
835  page->Freeze();
836  size_t step = total / 100;
837  if (step < 1)
838  step = 1;
839 
840  for (auto &p : macro_list) {
841  page->AddMacro(p);
842  if (i % step == 0) {
843  Pulse(static_cast<int>(100 * i / total));
844  }
845  i++;
846  }
847  page->FitPage();
848  page->Thaw();
849  page->Show();
850 
851  m_Progress->SetValue(0);
852 
853  page->Refresh();
854  page->LookupSynonymFiles();
856  }
857  m_loading_script = false;
858 }
859 
860 void CMacroFlowEditor::OnRecent( wxCommandEvent& event)
861 {
862  int id = event.GetId();
863  if (m_id_to_path.find(id) == m_id_to_path.end())
864  return;
865  wxString path = m_id_to_path[id];
866  OpenScript(path, true, false);
867 }
868 
869 
870 void CMacroFlowEditor::OnSaveAsClick( wxCommandEvent& event )
871 {
872  wxWindow *win = m_Notebook->GetCurrentPage();
873  if (!win)
874  return;
875 
876  CScriptPanel *page = dynamic_cast<CScriptPanel*>(win);
877  if (!page)
878  return;
879 
880  int page_num = m_Notebook->GetPageIndex(win);
881 
882  const vector<pair<CRef<macro::CMacroRep>, bool> >& script = page->GetScript();
883  if (script.empty())
884  return;
885 
886  wxFileDialog file(this, wxT("Save macro script"), m_DefaultDir, m_Notebook->GetPageText(page_num), _("All files (*.*)|*.*"), wxFD_SAVE | wxFD_OVERWRITE_PROMPT);
887  if (file.ShowModal() != wxID_OK)
888  return;
889 
890  wxString path = file.GetPath();
891  if (path.IsEmpty())
892  return;
893 
894  wxFileName filename(path);
895  m_opened_scripts.remove(path.ToStdString());
896  m_opened_scripts.push_back(path.ToStdString());
897  if (m_opened_scripts.size() > 10)
898  m_opened_scripts.pop_front();
900  m_DefaultDir = filename.GetPath();
901  m_Notebook->SetPageText(page_num, filename.GetFullName());
902  page->SetPath(path);
903  SetStatusText(path);
904  SaveScript(path, script);
905  page->SetModified(false);
906 }
907 
908 void CMacroFlowEditor::OnSaveAsUpdate( wxUpdateUIEvent& event )
909 {
910  wxWindow *win = m_Notebook->GetCurrentPage();
911  if (win)
912  {
913  CScriptPanel *page = dynamic_cast<CScriptPanel*>(win);
914  if (page && !page->IsDragging())
915  {
916  const vector<pair<CRef<macro::CMacroRep>, bool> >& script = page->GetScript();
917  if (!script.empty() && !m_loading_script)
918  {
919  event.Enable(true);
920  return;
921  }
922  }
923  }
924  event.Enable(false);
925 }
926 
927 static const char* sSaveLocalCopies[] = {
928  "<std>/etc/macro_scripts/autofix_gb.mql",
929  "<std>/etc/macro_scripts/autofix_wgs.mql",
930  "<std>/etc/macro_scripts/autofix_tsa.mql",
931  "<std>/etc/synonyms.txt",
932  NULL
933 };
934 
935 void CMacroFlowEditor::OnSaveCopies(wxCommandEvent& event)
936 {
937  int index = -1;
938  string title;
939  switch (event.GetId())
940  {
942  index = 0;
943  title = "Save Autofix GenBank macro";
944  break;
946  index = 1;
947  title = "Save Autofix WGS macro";
948  break;
950  index = 2;
951  title = "Save Autofix TSA macro";
952  break;
954  index = 3;
955  title = "Save Default Synonym File";
956  break;
957  default:
958  index = 4;
959  break;
960  }
961 
962  if (!sSaveLocalCopies[index])
963  return;
964 
965  string filename;
966  wxString in_path = CSysPath::ResolvePathExisting(wxString::FromUTF8(sSaveLocalCopies[index]));
967  if (!in_path.IsEmpty()) {
968  filename = string(in_path.ToUTF8());
969  }
970  else {
971  NcbiMessageBox(string(sSaveLocalCopies[index]) + " was not found");
972  return;
973  }
974 
975  CNcbiIfstream in_str(filename.data(), ios::in);
976 
977  wxFileDialog save_dlg(this, ToWxString(title),
978  m_DefaultDir, wxEmptyString, _("TXT files (*.txt)|*.txt|All files (*.*)|*.*"), wxFD_SAVE | wxFD_OVERWRITE_PROMPT);
979 
980  if (save_dlg.ShowModal() == wxID_OK) {
981  wxString out_path = save_dlg.GetPath();
982  if (!out_path.IsEmpty()) {
983  bool saved = false;
984  try {
985  CNcbiOfstream out_str(out_path.fn_str(), ios::out);
986  if (in_str.good() && out_str.good()) {
987  NcbiStreamCopyThrow(out_str, in_str);
988  saved = true;
989  }
990  }
991  catch (const CException& e) {
992  LOG_POST(Error << "Failed to save synonym file: " << e.GetMsg());
993  }
994  catch (const exception& e) {
995  LOG_POST(Error << "Failed to save synonym file: " << e.what());
996  }
997 
998  if (!saved) {
999  NcbiErrorBox("Submission file cannot be saved");
1000  CFile fh(ToStdString(out_path));
1001  if (fh.Exists() && fh.IsFile()) {
1003  }
1004  }
1005  }
1006  }
1007 }
1008 
1009 void CMacroFlowEditor::OpenSynonymFile(wxCommandEvent& event)
1010 {
1011  wxFileDialog file_dlg(this, _("Select Word Substitution File"), wxEmptyString, wxEmptyString, _("All files (*.*)|*.*"), wxFD_OPEN | wxFD_FILE_MUST_EXIST);
1012  if (file_dlg.ShowModal() == wxID_OK) {
1013  auto mapped_path = GetAbsolutePath(file_dlg.GetPath());
1014  m_SynFileCtrl->ChangeValue(mapped_path);
1015  m_SynFileCtrl->SetInsertionPoint(m_SynFileCtrl->GetLastPosition());
1016  }
1017 }
1018 
1019 static bool s_ReplaceInPlaceBetweenQuotes(string& str, const string& search, const string& replace)
1020 {
1021  bool modified = false;
1022 
1023  size_t pos = NStr::FindNoCase(str, search);
1024  while (pos != string::npos) {
1025  size_t right_end = pos + search.length();
1026  if (pos > 0 && str.c_str()[pos - 1] == '"' && str.data()[right_end] == '"') {
1027  string this_replace = replace;
1028  str = str.substr(0, pos) + this_replace + str.substr(right_end);
1029  right_end = pos + this_replace.length();
1030  modified = true;
1031  }
1032  pos = NStr::FindNoCase(str, search, right_end);
1033  }
1034 
1035  return modified;
1036 }
1037 
1038 void CMacroFlowEditor::OnUpdateSynonymFile(wxCommandEvent& event)
1039 {
1040  CScriptPanel* page = x_GetCurrentPage();
1041  if (!page)
1042  return;
1043 
1044  TVecMacroRep script = page->GetMacros();
1045  if (script.empty())
1046  return;
1047 
1048  string new_syn_file = ToStdString(m_SynFileCtrl->GetValue());
1049  if (new_syn_file.empty()) {
1050  NcbiErrorBox("New word substitution file is empty");
1051  return;
1052  }
1053 
1054  macro::CMacroEngine macro_engine;
1055  vector<string> syn_files = macro_engine.GetSynonymFilenames(script);
1056 
1057  if (syn_files.empty()) {
1058  NcbiInfoBox("No word substitution file is found in the script");
1059  page->SetSynonymFile(kEmptyStr);
1060  }
1061  else {
1062  EDialogReturnValue ret = eYes;
1063  if (syn_files.size() > 1) {
1064  string msg = "Multiple word substitution files are found:";
1065  for (const auto& it : syn_files) {
1066  msg += "\n" + it;
1067  }
1068  msg += "\nWould you like to replace all of them?";
1069  ret = NcbiMessageBox(msg, eDialog_YesNo, eIcon_Question, "Info");
1070  }
1071  if (ret == eNo) {
1073  }
1074  else if (ret == eYes) {
1075  for (const auto& syn_it : syn_files) {
1076  for (auto& it : script) {
1077  string macro_str = it->GetSource();
1078  s_ReplaceInPlaceBetweenQuotes(macro_str, syn_it, new_syn_file);
1079  it->SetSource(macro_str);
1080  }
1081  }
1082  if (page->UpdateMacroSources(script)) {
1083  page->SetSynonymFile(new_syn_file);
1084  page->SetModified(true);
1086  NcbiInfoBox("Word substitution file instances were successfully replaced");
1087  }
1088  else {
1089  NcbiErrorBox("Failed to update the word substitution filenames");
1090  }
1091  }
1092  }
1093 }
1094 
1096 {
1097  CScriptPanel* page = x_GetCurrentPage();
1098  if (!page)
1099  return;
1100 
1101  auto syn_file = page->GetSynonymFile();
1102  if (syn_file.empty()) {
1103  m_SynFileCtrl->Clear();
1104  } else {
1105  m_SynFileCtrl->ChangeValue(ToWxString(syn_file));
1106  m_SynFileCtrl->SetInsertionPoint(m_SynFileCtrl->GetLastPosition());
1107  }
1108 }
1109 
1110 void CMacroFlowEditor::OnUpdateSynFileUpdate(wxUpdateUIEvent& event)
1111 {
1112  event.Enable(!m_SynFileCtrl->IsEmpty());
1113 }
1114 
1115 void CMacroFlowEditor::OnReportSynFileStatus(wxCommandEvent& event)
1116 {
1117  CScriptPanel* page = x_GetCurrentPage();
1118  if (!page)
1119  return;
1120 
1121  TVecMacroRep script = page->GetMacros();
1122  if (script.empty())
1123  return;
1124 
1125  macro::CMacroEngine macro_engine;
1126  vector<string> syn_files = macro_engine.GetSynonymFilenames(script);
1127  if (syn_files.empty()) {
1128  NcbiInfoBox("No word substitution file is found in the script");
1129  }
1130  else {
1131  string msg;
1132  if (syn_files.size() > 1) {
1133  msg = "Multiple word substitution files are found:";
1134  for (const auto& it : syn_files) {
1135  msg += "\n" + it;
1136  }
1137  }
1138  else {
1139  msg = "One word substitution file is found:\n";
1140  msg += syn_files.front();
1141  }
1142 
1143  CGenericReportDlg* report = new CGenericReportDlg(this);
1144  report->SetTitle(wxT("Report existing word substitutions files"));
1145  report->SetText(ToWxString(msg));
1146  report->Show(true);
1147  report->SetFocus();
1148  }
1149 }
1150 
1152 {
1153  CScriptPanel* page = nullptr;
1154  wxWindow* win = m_Notebook->GetCurrentPage();
1155  if (win) {
1156  page = dynamic_cast<CScriptPanel*>(win);
1157  }
1158  return page;
1159 }
1160 
1161 void CMacroFlowEditor::OnExportStepsClick( wxCommandEvent& event )
1162 {
1163  CScriptPanel* page = x_GetCurrentPage();
1164  if (!page)
1165  return;
1166 
1167  const vector<pair<CRef<macro::CMacroRep>, bool> >& script = page->GetScript();
1168  if (script.empty())
1169  return;
1170 
1171  wxFileDialog file(this, wxT("Export script steps"), m_DefaultDir, wxEmptyString, _("Text files (*.txt)|*.txt"), wxFD_SAVE | wxFD_OVERWRITE_PROMPT);
1172  if (file.ShowModal() != wxID_OK)
1173  return;
1174 
1175  wxString path = file.GetPath();
1176  if (path.IsEmpty())
1177  return;
1178 
1179  wxFileName filename(path);
1180  m_DefaultDir = filename.GetPath();
1181  {{
1182  wxFFileOutputStream output( path );
1183  wxTextOutputStream text_out( output );
1184  size_t total = script.size();
1185  for (size_t i = 0; i < total; i++)
1186  {
1187  wxString step;
1188  step << i + 1;
1189  text_out << step << ". ";
1190  text_out << script[i].first->GetTitle() << endl;
1191  if (i % 10 == 0)
1192  Pulse(static_cast<int>(100 * i / total));
1193  }
1194  m_Progress->SetValue(0);
1195  }}
1196 }
1197 
1198 void CMacroFlowEditor::OnSaveClick( wxCommandEvent& event )
1199 {
1200  wxWindow *win = m_Notebook->GetCurrentPage();
1201  if (!win)
1202  return;
1203 
1204  CScriptPanel *page = dynamic_cast<CScriptPanel*>(win);
1205  if (!page)
1206  return;
1207 
1208  const vector<pair<CRef<macro::CMacroRep>, bool> >& script = page->GetScript();
1209  if (script.empty())
1210  return;
1211 
1212  wxString path = page->GetPath();
1213  if (path.IsEmpty())
1214  return;
1215 
1216  SaveScript(path, script);
1217  page->SetModified(false);
1218 }
1219 
1220 void CMacroFlowEditor::SaveScript(const wxString &path, const vector<pair<CRef<macro::CMacroRep>, bool> >& script)
1221 {
1222  {{
1223  CNcbiOfstream os(path.fn_str(), ios::out);
1224  size_t i = 0;
1225  size_t total = script.size();
1226  for (auto& it : script)
1227  {
1228  os << it.first->GetSource();
1229  if ( i % 10 == 0)
1230  Pulse(static_cast<int>(100 * i / total));
1231  i++;
1232  }
1233  }}
1234  m_Progress->SetValue(0);
1235  if (path == m_CurrentLibrary)
1236  {
1237  LibraryModified();
1238  }
1239 }
1240 
1241 void CMacroFlowEditor::OnSaveUpdate( wxUpdateUIEvent& event )
1242 {
1243  wxWindow *win = m_Notebook->GetCurrentPage();
1244  if (win)
1245  {
1246  CScriptPanel *page = dynamic_cast<CScriptPanel*>(win);
1247  if (page && !page->IsDragging())
1248  {
1249  const vector<pair<CRef<macro::CMacroRep>, bool> >& script = page->GetScript();
1250  if (!script.empty() && !m_loading_script && !page->GetPath().IsEmpty())
1251  {
1252  event.Enable(true);
1253  return;
1254  }
1255  }
1256  }
1257  event.Enable(false);
1258 }
1259 
1260 
1261 /*
1262  * wxEVT_COMMAND_MENU_SELECTED event handler for wxID_EXIT
1263  */
1264 
1265 void CMacroFlowEditor::OnExitClick( wxCommandEvent& event )
1266 {
1267 ////@begin wxEVT_COMMAND_MENU_SELECTED event handler for wxID_EXIT in CMacroFlowEditor.
1268  // Before editing this code, remove the block markers.
1269  Close();
1270 ////@end wxEVT_COMMAND_MENU_SELECTED event handler for wxID_EXIT in CMacroFlowEditor.
1271 }
1272 
1273 void CMacroFlowEditor::OnClose(wxCloseEvent& event)
1274 {
1275  bool modified = false;
1276  for (size_t i = 0; i < m_Notebook->GetPageCount(); i++)
1277  {
1278  wxWindow* win = m_Notebook->GetPage(i);
1279  if (!win)
1280  continue;
1281  CScriptPanel *page = dynamic_cast<CScriptPanel*>(win);
1282  if (page && page->IsModified())
1283  {
1284  modified = true;
1285  break;
1286  }
1287  }
1288  if ( event.CanVeto() && modified)
1289  {
1290  if ( wxMessageBox("You have unsaved modified scripts, continue closing?", "Please confirm", wxICON_QUESTION | wxYES_NO) != wxYES )
1291  {
1292  event.Veto();
1293  return;
1294  }
1295  }
1296  event.Skip();
1297 }
1298 
1299 void CMacroFlowEditor::OnPageClose(wxAuiNotebookEvent& event)
1300 {
1301  int sel = event.GetSelection();
1302  if (sel == wxNOT_FOUND)
1303  return;
1304  wxWindow* win = m_Notebook->GetPage(sel);
1305  if (!win)
1306  return;
1307  if (m_loading_script || m_running) {
1308  wxBell();
1309  event.Veto();
1310  return;
1311  }
1312  bool modified = false;
1313  CScriptPanel *page = dynamic_cast<CScriptPanel*>(win);
1314 
1315  if (page && page->IsModified()) {
1316  modified = true;
1317  }
1318  if (modified) {
1319  if ( wxMessageBox("The script has been modified, continue closing?", "Please confirm", wxICON_QUESTION | wxYES_NO) != wxYES )
1320  {
1321  event.Veto();
1322  return;
1323  }
1324  }
1325  if (m_MacroEditor) {
1326  m_MacroEditor->Destroy();
1327  m_MacroEditor = nullptr;
1328  }
1329  SetStatusText(wxEmptyString);
1330  event.Skip();
1331 }
1332 
1333 void CMacroFlowEditor::OnPageChanging(wxAuiNotebookEvent& event)
1334 {
1335  int sel = event.GetOldSelection();
1336  if (sel == wxNOT_FOUND)
1337  return;
1338  wxWindow* win = m_Notebook->GetPage(sel);
1339  if (!win)
1340  return;
1341  CScriptPanel *page = dynamic_cast<CScriptPanel*>(win);
1342  page->SaveScrollPos();
1343  event.Skip();
1344 }
1345 
1346 void CMacroFlowEditor::OnPageChanged(wxAuiNotebookEvent& event)
1347 {
1348  int sel = event.GetSelection();
1349  if (sel == wxNOT_FOUND)
1350  return;
1351 
1352  wxWindow* win = m_Notebook->GetPage(sel);
1353  if (!win)
1354  return;
1355  CScriptPanel *page = dynamic_cast<CScriptPanel*>(win);
1356  wxString path = page->GetPath();
1357  SetStatusText(path);
1359  CallAfter(&CMacroFlowEditor::LoadScrollPos);
1360  event.Skip();
1361 }
1362 
1364 {
1365  wxWindow *win = m_Notebook->GetCurrentPage();
1366  if (!win)
1367  return;
1368  CScriptPanel *page = dynamic_cast<CScriptPanel*>(win);
1369  if (!page)
1370  return;
1371  page->LoadScrollPos();
1372 }
1373 
1374 /*
1375  * wxEVT_COMMAND_MENU_SELECTED event handler for wxID_CUT
1376  */
1377 
1378 void CMacroFlowEditor::OnCutClick( wxCommandEvent& event )
1379 {
1380  wxWindow *win = m_Notebook->GetCurrentPage();
1381  if (!win)
1382  return;
1383  CScriptPanel *page = dynamic_cast<CScriptPanel*>(win);
1384  if (!page)
1385  return;
1386 
1387  m_clipboard.clear();
1388  m_clipboard_skipped.clear();
1390  for (auto &label : labels)
1391  {
1392  m_clipboard.push_back(label.second->GetMacro());
1393  m_clipboard_skipped.push_back(label.second->IsSkipped());
1394  }
1395  if (!m_clipboard.empty()) {
1396  m_LastEventId = event.GetId();
1397  }
1398  page->DeleteSelected();
1399  page->SetModified(true);
1400 }
1401 
1402 
1403 /*
1404  * wxEVT_UPDATE_UI event handler for wxID_CUT
1405  */
1406 
1407 void CMacroFlowEditor::OnEditUpdate( wxUpdateUIEvent& event )
1408 {
1409  wxWindow *win = m_Notebook->GetCurrentPage();
1410  if (win)
1411  {
1412  CScriptPanel *page = dynamic_cast<CScriptPanel*>(win);
1413  if (page && !page->IsDragging() && page->IsMacroSelected() && !m_running && !m_loading_script && !m_loading_library)
1414  {
1415  event.Enable(true);
1416  return;
1417  }
1418  }
1419  event.Enable(false);
1420 }
1421 
1422 
1423 /*
1424  * wxEVT_COMMAND_MENU_SELECTED event handler for wxID_COPY
1425  */
1426 
1427 void CMacroFlowEditor::OnCopyClick( wxCommandEvent& event )
1428 {
1429  wxWindow *win = m_Notebook->GetCurrentPage();
1430  if (!win)
1431  return;
1432  CScriptPanel *page = dynamic_cast<CScriptPanel*>(win);
1433  if (!page)
1434  return;
1435  m_clipboard.clear();
1436  m_clipboard_skipped.clear();
1438  for (auto &label : labels)
1439  {
1440  m_clipboard.push_back(label.second->GetMacro());
1441  m_clipboard_skipped.push_back(label.second->IsSkipped());
1442  }
1443 
1444  if (!m_clipboard.empty()) {
1445  m_LastEventId = event.GetId();
1446  }
1447  page->UnselectMacro();
1448 }
1449 
1450 /*
1451  * wxEVT_COMMAND_MENU_SELECTED event handler for wxID_PASTE
1452  */
1453 
1454 void CMacroFlowEditor::OnPasteClick( wxCommandEvent& event )
1455 {
1456  if (m_clipboard.empty())
1457  return;
1458  wxWindow *win = m_Notebook->GetCurrentPage();
1459  if (!win)
1460  return;
1461  CScriptPanel *page = dynamic_cast<CScriptPanel*>(win);
1462  if (!page)
1463  return;
1465  vector<CMacroLabel*> added;
1466  if (!labels.empty())
1467  {
1468  CMacroLabel* label = labels.begin()->second;
1469  size_t index = page->GetIndex(label);
1470  for (auto &macro : m_clipboard)
1471  {
1472  CMacroLabel* add = page->InsertMacro(macro, index);
1473  added.push_back(add);
1474  index++;
1475  }
1476  }
1477  else
1478  {
1479  for (auto &macro : m_clipboard)
1480  {
1481  CMacroLabel* add = page->AddMacro(macro);
1482  added.push_back(add);
1483  }
1484  }
1485  page->FitPage();
1486  for (size_t i = 0; i < added.size(); i++)
1487  {
1488  if (m_clipboard_skipped[i])
1489  page->ToggleSkip(added[i]);
1490  }
1491  page->SetModified(true);
1492  page->LookupSynonymFiles();
1494 
1496  // save the pasted script only if it was copied earlier
1497  string macros;
1498  for (auto& it : m_clipboard) {
1499  macros += it->GetSource();
1500  macros += "\n";
1501  }
1502  if (!macros.empty()) macros.pop_back();
1503  //NMacroStats::SaveScript(macros);
1504  }
1505  m_LastEventId = 0;
1506 }
1507 
1508 void CMacroFlowEditor::OnPasteUpdate( wxUpdateUIEvent& event )
1509 {
1510  wxWindow *win = m_Notebook->GetCurrentPage();
1511  if (win)
1512  {
1513  CScriptPanel *page = dynamic_cast<CScriptPanel*>(win);
1514  if (page && !page->IsDragging() && !m_running && !m_clipboard.empty() && !m_loading_script)
1515  {
1516  event.Enable(true);
1517  return;
1518  }
1519  }
1520  event.Enable(false);
1521 }
1522 
1523 /*
1524  * wxEVT_COMMAND_MENU_SELECTED event handler for wxID_DELETE
1525  */
1526 
1527 void CMacroFlowEditor::OnDeleteClick( wxCommandEvent& event )
1528 {
1529  wxWindow *win = m_Notebook->GetCurrentPage();
1530  if (!win)
1531  return;
1532  CScriptPanel *page = dynamic_cast<CScriptPanel*>(win);
1533  if (!page)
1534  return;
1535  page->DeleteSelected();
1536  page->SetModified(true);
1537  page->LookupSynonymFiles();
1539 }
1540 
1541 void CMacroFlowEditor::OnDuplicateClick( wxCommandEvent& event )
1542 {
1543  wxWindow *win = m_Notebook->GetCurrentPage();
1544  if (!win)
1545  return;
1546  CScriptPanel *page = dynamic_cast<CScriptPanel*>(win);
1547  if (!page)
1548  return;
1549 
1551  if (labels.size() != 1)
1552  return;
1553 
1554  CMacroLabel* label = labels.begin()->second;
1555  size_t index = page->GetIndex(label);
1556  index++;
1557  CMacroLabel* add = nullptr;
1558  if (index < page->GetCount()) {
1559  add = page->InsertMacro(label->GetMacro(), index);
1560  }
1561  else {
1562  add = page->AddMacro(label->GetMacro());
1563  }
1564 
1565  if (label->IsSkipped() && add) {
1566  page->ToggleSkip(add);
1567  }
1568  page->FitPage();
1569  page->SetModified(true);
1570 }
1571 
1572 void CMacroFlowEditor::OnDuplicateUpdate( wxUpdateUIEvent& event )
1573 {
1574  wxWindow *win = m_Notebook->GetCurrentPage();
1575  if (win)
1576  {
1577  CScriptPanel *page = dynamic_cast<CScriptPanel*>(win);
1578  if (page && !page->IsDragging() &&
1579  page->IsMacroSelected() &&
1582  if (labels.size() == 1) {
1583  event.Enable(true);
1584  return;
1585  }
1586  }
1587  }
1588  event.Enable(false);
1589 }
1590 
1591 void CMacroFlowEditor::OnAppendClick( wxCommandEvent& event )
1592 {
1593  wxWindow *win = m_Notebook->GetCurrentPage();
1594  if (!win)
1595  return;
1596  CScriptPanel *page = dynamic_cast<CScriptPanel*>(win);
1597  if (!page)
1598  return;
1599 
1600  if (m_CurrentLibrary.empty())
1601  return;
1602 
1603  wxString path(m_CurrentLibrary);
1604  {{
1605  set<string> existing;
1606  for (auto& it : m_id_to_macro)
1607  {
1608  existing.insert(it.second->GetSource());
1609  }
1610  CNcbiOfstream os(path.fn_str(), ios::out | ios::app);
1611 
1613  size_t i = 0;
1614  size_t total = labels.size();
1615  for (auto &label : labels)
1616  {
1617  string source = label.second->GetMacro()->GetSource();
1618  if (existing.find(source) == existing.end())
1619  {
1620  os << source;
1621  }
1622  if (i % 10 == 0)
1623  Pulse(static_cast<int>(100 * i / total));
1624  i++;
1625  }
1626 
1627  page->UnselectMacro();
1628  }}
1629  Freeze();
1630  set<string> expanded_nodes;
1631  GetExpandedNodes(m_TreeCtrl->GetRootItem(), expanded_nodes);
1632  ImportLibrary(path, false);
1633  SetExpandedNodes(m_TreeCtrl->GetRootItem(), expanded_nodes);
1634  Thaw();
1635 }
1636 
1637 void CMacroFlowEditor::OnIncreaseFont( wxCommandEvent& event )
1638 {
1639  wxWindow *win = m_Notebook->GetCurrentPage();
1640  if (!win)
1641  return;
1642  CScriptPanel *page = dynamic_cast<CScriptPanel*>(win);
1643  if (!page)
1644  return;
1645  page->IncreaseFont();
1646 }
1647 
1648 void CMacroFlowEditor::OnDecreaseFont( wxCommandEvent& event )
1649 {
1650  wxWindow *win = m_Notebook->GetCurrentPage();
1651  if (!win)
1652  return;
1653  CScriptPanel *page = dynamic_cast<CScriptPanel*>(win);
1654  if (!page)
1655  return;
1656  page->DecreaseFont();
1657 }
1658 
1659 void CMacroFlowEditor::OnManualEditMacro(wxCommandEvent& event)
1660 {
1661  wxWindow *win = m_Notebook->GetCurrentPage();
1662  if (!win)
1663  return;
1664  CScriptPanel *page = dynamic_cast<CScriptPanel*>(win);
1665  if (!page)
1666  return;
1667 
1669  if (labels.size() != 1)
1670  return;
1671 
1672  CMacroLabel* label = labels.begin()->second;
1673  page->SaveScrollPos();
1674  NMacroStats::ReportUsage(wxT("ScriptPanel"), "view macro step");
1675  CRef<macro::CMacroRep> macro = label->GetMacro();
1676  CMacroSimple dlg(NULL, macro->GetSource());
1677  if (dlg.ShowModal() != wxID_OK) {
1678  page->LoadScrollPos();
1679  return;
1680  }
1681  label->UpdateMacro(dlg.GetMacro());
1682  page->LoadScrollPos();
1683  page->LookupSynonymFiles();
1685 }
1686 
1687 void CMacroFlowEditor::OnManualEditMacroUpdate(wxUpdateUIEvent& event)
1688 {
1689  wxWindow *win = m_Notebook->GetCurrentPage();
1690  if (win)
1691  {
1692  CScriptPanel *page = dynamic_cast<CScriptPanel*>(win);
1693  if (page && !page->IsDragging() &&
1694  page->IsMacroSelected() &&
1697  if (labels.size() == 1) {
1698  event.Enable(true);
1699  return;
1700  }
1701  }
1702  }
1703  event.Enable(false);
1704 }
1705 
1706 /*
1707  * wxEVT_COMMAND_MENU_SELECTED event handler for wxID_ADD
1708  */
1709 
1710 void CMacroFlowEditor::OnAddClick( wxCommandEvent& event )
1711 {
1712  if (m_MacroEditor) {
1713  m_MacroEditor->Iconize(false);
1714  m_MacroEditor->SetFocus();
1715  m_MacroEditor->Raise();
1716  m_MacroEditor->Show(true);
1717  }
1718  else {
1720  m_MacroEditor->Show(true);
1721  }
1722 }
1723 
1725 {
1726  if (m_MacroEditor) {
1727  //TODO - pass the macro when the editor is already opened
1728  m_MacroEditor->Iconize(false);
1729  m_MacroEditor->SetFocus();
1730  m_MacroEditor->Raise();
1731  m_MacroEditor->Show(true);
1732  }
1733  else {
1734  try {
1736  m_MacroEditor->Show(true);
1737  }
1738  catch (const CException& e) {
1739  NcbiWarningBox("Macro cannot be opened in the editor: " + e.GetMsg() + ". Please modify it manually.");
1740  }
1741  }
1742 }
1743 
1745 {
1746  wxWindow* win = m_Notebook->GetCurrentPage();
1747  if (win) {
1748  CScriptPanel* page = dynamic_cast<CScriptPanel*>(win);
1749  if (page) {
1750  return page->GetSynonymFile();
1751  }
1752  }
1753  return kEmptyStr;
1754 }
1755 
1756 void CMacroFlowEditor::SetSynonymFile(const string& filename)
1757 {
1758  if (!filename.empty())
1759  return;
1760 
1761  wxWindow* win = m_Notebook->GetCurrentPage();
1762  if (win) {
1763  CScriptPanel* page = dynamic_cast<CScriptPanel*>(win);
1764  if (page) {
1765  auto orig_file = page->GetSynonymFile();
1766  if (!orig_file.empty()) {
1767  m_SynFileCtrl->ChangeValue("Multiple Files");
1768  }
1769  else {
1770  page->SetSynonymFile(filename);
1771  m_SynFileCtrl->ChangeValue(ToWxString(filename));
1772  m_SynFileCtrl->SetInsertionPoint(m_SynFileCtrl->GetLastPosition());
1773  }
1774  }
1775  }
1776 }
1777 
1778 void CMacroFlowEditor::SaveAddMacroSizeAndPosition(int w, int h, int x, int y)
1779 {
1780  m_width_add_macro = w;
1781  m_height_add_macro = h;
1782  m_pos_x_add_macro = x;
1783  m_pos_y_add_macro = y;
1784 }
1785 
1786 void CMacroFlowEditor::RemoveEditor(bool scroll_to_end)
1787 {
1788  m_MacroEditor = nullptr;
1789  wxWindow *win = m_Notebook->GetCurrentPage();
1790  if (!win)
1791  return;
1792  CScriptPanel *page = dynamic_cast<CScriptPanel*>(win);
1793  if (!page)
1794  return;
1795 
1796  if (scroll_to_end) {
1797  // after adding one/multiple new macro(s), scroll to the end of the macro script
1798  page->ScrollToBottom();
1799  }
1800  else {
1801  // after editing an existing macro, scroll to the edited macro
1802  page->LoadScrollPos();
1803  }
1804 }
1805 
1806 void CMacroFlowEditor::OnAddUpdate( wxUpdateUIEvent& event )
1807 {
1808  wxWindow *win = m_Notebook->GetCurrentPage();
1809  if (win)
1810  {
1811  CScriptPanel *page = dynamic_cast<CScriptPanel*>(win);
1812  if (page && !page->IsDragging() && !m_running && !m_loading_script)
1813  {
1814  event.Enable(true);
1815  return;
1816  }
1817  }
1818  event.Enable(false);
1819 }
1820 
1821 /*
1822  * wxEVT_COMMAND_MENU_SELECTED event handler for wxID_FORWARD
1823  */
1824 
1825 void CMacroFlowEditor::OnForwardClick( wxCommandEvent& event )
1826 {
1827  wxWindow *win = m_Notebook->GetCurrentPage();
1828  if (!win)
1829  return;
1830 
1831  CScriptPanel *page = dynamic_cast<CScriptPanel*>(win);
1832  if (!page)
1833  return;
1834  const vector<pair<CRef<macro::CMacroRep>, bool> >& script = page->GetScript();
1835  if (m_standalone)
1836  {
1837  RunScriptStandalone(script, page);
1838  }
1839  else
1840  {
1841  RunScriptInWidget(script, page);
1842  }
1843 }
1844 
1845 void CMacroFlowEditor::RunScriptStandalone( const vector<pair<CRef<macro::CMacroRep>, bool> >& script, CScriptPanel *page)
1846 {
1847  size_t num_files = m_InputFiles.GetCount();
1848  bool shown = false;
1849  bool aborted = false;
1850  wxString log;
1851  wxString last_out_file;
1852  for (size_t i = 0; i < num_files; i++)
1853  {
1854  wxString path = m_InputFiles[i];
1855  if( !wxFileName::FileExists( path ) )
1856  continue;
1857 
1858  unique_ptr<CNcbiIstream> InputStream(new CNcbiIfstream (path.fn_str(), ios::binary));
1859 
1862  continue;
1863 
1864  unique_ptr<CObjectIStream> in;
1866  InputStream.release();
1867 
1868  CRef<objects::CScope> scope(new objects::CScope (*objects::CObjectManager::GetInstance()));
1869  scope->AddDefaults();
1870 
1871  wxFileName out_file(m_OutputFolder->GetDirName().GetPath(), "");
1872  wxFileName in_file(path);
1873  out_file.SetFullName(in_file.GetFullName());
1874 
1875  if (out_file == in_file && !shown)
1876  {
1877  wxMessageBox(wxT("Output file cannot be the same as input file"), wxT("Warning"), wxOK | wxICON_WARNING);
1878  shown = true;
1879  continue;
1880  }
1881  last_out_file = out_file.GetFullPath();
1882  string header = in->ReadFileHeader();
1883  CRef<objects::CSeq_entry> se(new objects::CSeq_entry);
1884  try
1885  {
1886  unique_ptr<CObjectOStream> out(CObjectOStream::Open(out_file.GetFullPath().ToStdString(), CFormatGuess::eBinaryASN == format ? eSerial_AsnBinary : eSerial_AsnText));
1887  if ( "Seq-submit" == header )
1888  {
1889  CRef<objects::CSeq_submit> ss(new objects::CSeq_submit);
1891 
1892  if (!ss->GetData().IsEntrys())
1893  continue;
1894  size_t num_entries = ss->GetData().GetEntrys().size();
1895  NON_CONST_ITERATE(objects::CSeq_submit::TData::TEntrys, se_it, ss->SetData().SetEntrys())
1896  {
1897  objects::CSeq_entry_Handle seh = scope->AddTopLevelSeqEntry(**se_it);
1898  RunScript(script, page, log, num_files, num_entries, seh, ss);
1899  }
1900  out->Write(ss, ss->GetThisTypeInfo());
1901  }
1902  else if ( "Seq-entry" == header )
1903  {
1905  objects::CSeq_entry_Handle seh = scope->AddTopLevelSeqEntry(*se);
1906  RunScript(script, page, log, num_files, 1, seh);
1907  out->Write(se, se->GetThisTypeInfo());
1908  }
1909  else if ( "Bioseq-set" == header )
1910  {
1911  objects::CBioseq_set& bioseqset = se->SetSet();
1912  in->Read(ObjectInfo(bioseqset), CObjectIStream::eNoFileHeader);
1913  objects::CSeq_entry_Handle seh = scope->AddTopLevelSeqEntry(*se);
1914  RunScript(script, page, log, num_files, 1, seh);
1915  out->Write(&bioseqset, bioseqset.GetThisTypeInfo());
1916  }
1917  else if ( "Bioseq" == header )
1918  {
1919  objects::CBioseq& bioseq = se->SetSeq();
1921  objects::CSeq_entry_Handle seh = scope->AddTopLevelSeqEntry(*se);
1922  RunScript(script, page, log, num_files, 1, seh);
1923  out->Write(&bioseq, bioseq.GetThisTypeInfo());
1924  }
1925 
1926  }
1927  catch(const CStopWorkException&)
1928  {
1929  wxRemoveFile(out_file.GetFullPath());
1930  log.Clear();
1931  wxMessageBox(wxT("Running script has been aborted"), wxT("Warning"), wxOK | wxICON_WARNING);
1932  aborted = true;
1933  }
1934  if (aborted)
1935  break;
1936  }
1937  m_running = false;
1938  m_stop = false;
1939  m_Progress->SetValue(0);
1940  if (!log.IsEmpty())
1941  {
1942  OpenFileBrowser(last_out_file);
1943  CGenericReportDlg* report = new CGenericReportDlg(this);
1944  report->SetTitle(wxT("Macro Script Report"));
1945  report->SetText(log);
1946  report->Show(true);
1947  report->SetFocus();
1948  }
1949  else if (!aborted)
1950  {
1951  wxMessageBox(wxT("No changes"), wxT("Information"), wxOK | wxICON_INFORMATION);
1952  }
1953 }
1954 
1955 static const char* kExclusiveEditDescr = "The macro editor requires exclusive access to a project";
1956 
1957 void CMacroFlowEditor::RunScriptInWidget( const vector<pair<CRef<macro::CMacroRep>, bool> >& script, CScriptPanel *page)
1958 {
1960 
1961  objects::CSeq_entry_Handle tse = m_gui_core_helper->GetTopSeqEntry();
1964  if (!tse || !cmdProcessor)
1965  return;
1966 
1967 
1968  bool aborted = false;
1969  wxString log;
1970  CRef<CCmdComposite> cmd(new CCmdComposite("Composite macro script"));
1971  bool status = true;
1972  try
1973  {
1974  status = RunScript(script, page, log, 1, 1, tse, seq_submit, cmd);
1975  }
1976  catch(const CStopWorkException&)
1977  {
1978  cmd->Execute(); // this call resets state to let Unexecute be run
1979  cmd->Unexecute();
1980  cmd.Reset();
1981  log.Clear();
1982  wxMessageBox(wxT("Running script has been aborted"), wxT("Warning"), wxOK | wxICON_WARNING);
1983  aborted = true;
1984  }
1985 
1986  if (!status) {
1987  cmd->Execute(); // this call resets state to let Unexecute be run
1988  cmd->Unexecute();
1989  cmd.Reset();
1990  log.Clear();
1991  }
1992 
1993  m_running = false;
1994  m_stop = false;
1995  m_Progress->SetValue(0);
1996  if (cmd)
1997  {
1998  if (m_UndoManager && m_undo_tse)
1999  {
2001  m_undo_tse.Reset();
2002  m_UndoManager = NULL;
2003  }
2004  IUndoManager* undoManager = dynamic_cast<IUndoManager*>(cmdProcessor);
2005  if (undoManager && undoManager->RequestExclusiveEdit(this, kExclusiveEditDescr))
2006  {
2007  undoManager->Execute(cmd, this);
2008  m_UndoManager = undoManager;
2009  m_undo_tse = tse;
2010  }
2011  }
2012 
2013  if (!log.IsEmpty())
2014  {
2015  CGenericReportDlg* report = new CGenericReportDlg(this);
2016  report->SetTitle(wxT("Macro Script Report"));
2017  report->SetText(log);
2018  report->Show(true);
2019  report->SetFocus();
2020  }
2021  else if (!aborted && status)
2022  {
2023  wxMessageBox(wxT("No changes"), wxT("Information"), wxOK | wxICON_INFORMATION);
2024  }
2025 }
2026 
2027 void CMacroFlowEditor::OnUndo( wxCommandEvent& event )
2028 {
2029  if (!m_UndoManager || !m_undo_tse)
2030  return;
2031  if (m_UndoManager->CanUndo())
2032  m_UndoManager->Undo(this);
2034  m_UndoManager = NULL;
2035  m_undo_tse.Reset();
2036 }
2037 
2038 void CMacroFlowEditor::OnUndoUpdate( wxUpdateUIEvent& event )
2039 {
2040  bool enable = (m_UndoManager && m_undo_tse && !m_loading_script && !m_running);
2041  event.Enable(enable);
2042 }
2043 
2044 bool CMacroFlowEditor::RunScript(const vector<pair<CRef<macro::CMacroRep>, bool> >& script, CScriptPanel *page, wxString &log, size_t num_files, size_t num_entries, objects::CSeq_entry_Handle seh,
2046 {
2047  page->ResetCounters();
2048 
2049  m_running = true;
2050  size_t i = 0;
2051  size_t total = script.size();
2052  int prev = m_Progress->GetValue();
2053  double interval = 100. / num_files;
2054  interval /= num_entries;
2056 
2057  bool lookup_synfile = true;
2058  macro::CMacroEngine macroEngine(false, lookup_synfile);
2059  bool status = true;
2060  for (auto macro = script.begin(); macro != script.end() && status; ++macro)
2061  {
2062  i++;
2063  if (!macro->second)
2064  continue;
2065 
2066  CRef<CMacroCmdComposite> macro_cmd(new CMacroCmdComposite("Macro script"));
2067  CRef<macro::CMacroRep> macroRep = macro->first;
2068  macro::CMacroBioData bioData(seh, submit);
2069  try
2070  {
2071  macroEngine.Exec(*macroRep, bioData, macro_cmd, true);
2072  }
2073  catch(const CStopWorkException&) // when running the macro is aborted by the user
2074  {
2075  macro_cmd->Execute(); // this call resets state to let Unexecute be run
2076  macro_cmd->Unexecute();
2077  macro_cmd.Reset();
2078  throw;
2079  }
2080  catch (const CException& e)
2081  {
2082  status = false;
2083  macro_cmd->Execute(); // this call resets state to let Unexecute be run
2084  macro_cmd->Unexecute();
2085  macro_cmd.Reset();
2086 
2087  string msg = "Execution of the macro has failed at '" + macroRep->GetTitle() + "' step:";
2088 
2089  CMacroErrorDlg errorDlg(nullptr);
2090  errorDlg.SetException(msg, e);
2091  errorDlg.ShowModal();
2092  }
2093 
2094  Pulse(prev + int(interval * i / total));
2095  const auto& macro_stat = macroEngine.GetStatistics();
2096  size_t counter = macro_stat.GetCounter();
2097  UpdateCounter(page, i - 1, counter);
2098 
2099  const auto& report = macro_stat.GetMacroReport();
2100  if (status) {
2101  if (!report.GetLog().empty()) {
2102  log << report.GetName() << ":\n" << report.GetLog();
2103  }
2104  else {
2105  const auto& logs = macro_stat.GetFunctionsLog();
2106  if (!logs.empty()) {
2107  log << report.GetName() << ":\n";
2108  }
2109  for (const auto& it : logs) {
2110  log << it->Print() << "\n";
2111  }
2112  }
2113 
2114  if (!report.GetErrorLog().empty()) {
2115  log << "\nERRORS:\n" << report.GetErrorLog();
2116  }
2117 
2118  const auto& unmatched_entries = macro_stat.GetUnmatchedTableEntries();
2119  if (!unmatched_entries.empty()) {
2120  log << "\nUnmatched entries:\n";
2121  log << unmatched_entries.front().first;
2122  }
2123  }
2124 
2125  if (cmd && macro_cmd)
2126  cmd->AddCommand(*macro_cmd);
2127  }
2128  return status;
2129 }
2130 
2131 void CMacroFlowEditor::UpdateCounter(CScriptPanel *page, size_t i, size_t counter)
2132 {
2133  page->UpdateCounter(i, counter);
2134 }
2135 
2136 /*
2137  * wxEVT_UPDATE_UI event handler for wxID_FORWARD
2138  */
2139 
2140 void CMacroFlowEditor::OnForwardUpdate( wxUpdateUIEvent& event )
2141 {
2142  wxWindow *win = m_Notebook->GetCurrentPage();
2143  if (win)
2144  {
2145  CScriptPanel *page = dynamic_cast<CScriptPanel*>(win);
2146  if (page && !page->IsDragging())
2147  {
2148  const vector<pair<CRef<macro::CMacroRep>, bool> >& script = page->GetScript();
2149  if (!script.empty() && !m_loading_script && !m_running)
2150  {
2151  if (m_standalone)
2152  {
2153  event.Enable(!m_InputFiles.IsEmpty() && m_OutputFolder->GetDirName().DirExists());
2154  return;
2155  }
2156  else
2157  {
2158  event.Enable(true);
2159  return;
2160  }
2161  }
2162  }
2163  }
2164  event.Enable(false);
2165 }
2166 
2168 {
2169  m_Progress->SetValue(c);
2170  if (wxTheApp && wxTheApp->GetMainLoop())
2171  {
2172  if (wxUpdateUIEvent::CanUpdate(m_toolbar))
2173  m_toolbar->UpdateWindowUI(wxUPDATE_UI_FROMIDLE);
2174  if (!wxTheApp->GetMainLoop()->IsYielding())
2175  wxTheApp->Yield(true);
2176  wxTheApp->ProcessPendingEvents();
2177  }
2178 
2179  if (m_stop)
2180  {
2181  m_stop = false;
2182  m_running = false;
2183  m_Progress->SetValue(0);
2184  throw CStopWorkException();
2185  }
2186 }
2187 
2188 
2189 
2190 /*
2191  * wxEVT_COMMAND_MENU_SELECTED event handler for wxID_STOP
2192  */
2193 
2194 void CMacroFlowEditor::OnStopClick( wxCommandEvent& event )
2195 {
2196  if (m_running)
2197  m_stop = true;
2198 }
2199 
2200 
2201 /*
2202  * wxEVT_UPDATE_UI event handler for wxID_STOP
2203  */
2204 
2205 void CMacroFlowEditor::OnStopUpdate( wxUpdateUIEvent& event )
2206 {
2207  event.Enable(m_running);
2208 }
2209 
2210 void CMacroFlowEditor::OnInputFile( wxCommandEvent& event )
2211 {
2212  wxFileDialog file(this, _("Open Input Files"), m_DefaultDir,
2213  wxEmptyString, _("All files (*.*)|*.*"), wxFD_OPEN | wxFD_FILE_MUST_EXIST | wxFD_MULTIPLE);
2214  if (file.ShowModal() != wxID_OK)
2215  return;
2216  file.GetPaths(m_InputFiles);
2217  if (!m_InputFiles.IsEmpty())
2218  {
2219  wxArrayString filenames;
2220  file.GetFilenames(filenames);
2221  wxString path = m_InputFiles[0];
2222  wxFileName filename(path);
2223  m_DefaultDir = filename.GetPath();
2224  m_InputFileText->SetValue(filenames[0]);
2225  for (size_t i = 1; i < filenames.GetCount(); i++)
2226  *m_InputFileText << _(", ") << filenames[i];
2227  }
2228 }
2229 
2230 /*
2231  * wxEVT_COMMAND_MENU_SELECTED event handler for wxID_FIND
2232  */
2233 
2234 void CMacroFlowEditor::OnFindClick( wxCommandEvent& event )
2235 {
2236  if (m_Search->GetValue().IsEmpty())
2237  return;
2238 
2239  m_TreeCtrl->UnselectAll();
2240 
2241  string pattern = m_Search->GetValue().ToStdString();
2242  if (pattern != m_prev_search)
2243  {
2244  m_found = 0;
2245  m_prev_search = pattern;
2246  }
2247  if (pattern.empty())
2248  return;
2249 
2250  size_t i = 0;
2251 
2252  wxWindow *win = m_Notebook->GetCurrentPage();
2253  if (win)
2254  {
2255  CScriptPanel *page = dynamic_cast<CScriptPanel*>(win);
2256  if (page)
2257  {
2258  page->UnselectMacro();
2259  const vector<pair<CRef<macro::CMacroRep>, bool> >& script = page->GetScript();
2260  size_t j = 0;
2261  for (auto &it : script)
2262  {
2263  const string &value = it.first->GetTitle();
2264  if (value.empty())
2265  continue;
2266 
2267  auto pos = NStr::FindNoCase(value, pattern);
2268  if (pos != NPOS) {
2269  if (m_found == i) {
2270  page->SelectItem(j);
2271  m_found++;
2272  return;
2273  }
2274  i++;
2275  }
2276  j++;
2277  }
2278  }
2279  }
2280 
2281 
2282  for (auto& id : m_all_ids) {
2283  const string &value = m_id_to_macro[id]->GetTitle();
2284  if (value.empty())
2285  continue;
2286 
2287  auto pos = NStr::FindNoCase(value, pattern);
2288  if (pos != NPOS) {
2289  if (m_found == i) {
2290  m_TreeCtrl->SelectItem(id);
2291  m_found++;
2292  return;
2293  }
2294  i++;
2295  }
2296  }
2297 
2298  m_found = 0;
2299  if (i > 0)
2300  wxMessageBox(wxT("No more matches found, wrapping over"), wxT("Information"), wxOK | wxICON_INFORMATION);
2301  else
2302  wxMessageBox(wxT("No match found"), wxT("Information"), wxOK | wxICON_INFORMATION);
2303 }
2304 
2305 
2306 /*
2307  * wxEVT_UPDATE_UI event handler for wxID_FIND
2308  */
2309 
2310 void CMacroFlowEditor::OnFindUpdate( wxUpdateUIEvent& event )
2311 {
2312  bool script_avail = false;
2313  wxWindow *win = m_Notebook->GetCurrentPage();
2314  if (win)
2315  {
2316  CScriptPanel *page = dynamic_cast<CScriptPanel*>(win);
2317  if (page && !page->IsDragging() && !m_running && !m_loading_script)
2318  {
2319  script_avail = true;
2320  }
2321  }
2322 
2323  bool lib_avail = !m_id_to_macro.empty() && !m_loading_library;
2324 
2325  event.Enable(lib_avail || script_avail);
2326 }
2327 
2328 
2329 /*
2330  * wxEVT_UPDATE_UI event handler for wxID_ADD
2331  */
2332 
2333 /*
2334  * wxEVT_COMMAND_TREE_ITEM_ACTIVATED event handler for ID_TREECTRL
2335  */
2336 
2338 {
2339  wxWindow *win = m_Notebook->GetCurrentPage();
2340  if (!win)
2341  {
2342  event.Skip();
2343  return;
2344  }
2345  CScriptPanel *page = dynamic_cast<CScriptPanel*>(win);
2346 
2347  wxTreeItemId id = event.GetItem();
2348  if (m_id_to_macro.find(id) == m_id_to_macro.end())
2349  {
2350  event.Skip();
2351  return;
2352  }
2353 
2354  page->AddMacro(m_id_to_macro[id]);
2355  page->FitPage();
2356  page->SetModified(true);
2357  // logging
2359 }
2360 
2361 void CMacroFlowEditor::OnTreectrlItemDrag( wxTreeEvent& event )
2362 {
2363  wxWindow *win = m_Notebook->GetCurrentPage();
2364  if (!win) {
2365  event.Skip();
2366  return;
2367  }
2368  CScriptPanel *page = dynamic_cast<CScriptPanel*>(win);
2369 
2370  wxTreeItemId id = event.GetItem();
2371  if (m_id_to_macro.find(id) == m_id_to_macro.end()) {
2372  event.Skip();
2373  return;
2374  }
2375 
2376  wxPoint pos = m_TreeCtrl->ScreenToClient(wxGetMousePosition());
2377  int w, h;
2378  m_TreeCtrl->GetClientSize( &w, &h );
2379  if (pos.x > w - 20 && pos.y > 0 && pos.y < h) {
2380  page->AddMacro(m_id_to_macro[id]);
2381  page->FitPage();
2382  page->SetModified(true);
2383  m_drag_id.Unset();
2384  return;
2385  }
2386  event.Allow();
2387  event.Skip();
2388  m_drag_id = id;
2389 }
2390 
2391 void CMacroFlowEditor::OnTreectrlItemDrop( wxTreeEvent& event )
2392 {
2393  wxWindow *win = m_Notebook->GetCurrentPage();
2394  if (!win)
2395  {
2396  event.Skip();
2397  return;
2398  }
2399  CScriptPanel *page = dynamic_cast<CScriptPanel*>(win);
2400 
2401  if (!m_drag_id.IsOk() || m_id_to_macro.find(m_drag_id) == m_id_to_macro.end())
2402  {
2403  event.Skip();
2404  return;
2405  }
2406  wxPoint pos = m_TreeCtrl->ScreenToClient(wxGetMousePosition());
2407  int w, h;
2408  m_TreeCtrl->GetClientSize( &w, &h );
2409  if (pos.x > w - 20 && pos.y > 0 && pos.y < h)
2410  {
2412  page->FitPage();
2413  page->SetModified(true);
2414  // logging
2416  }
2417  event.Skip();
2418  m_drag_id.Unset();
2419 }
2420 
2421 void CMacroFlowEditor::OnTreectrlMenu( wxTreeEvent& event )
2422 {
2423  wxMenu menu;
2424  menu.Append(ID_MACROFLOW_DEL_FROM_LIB, _("Delete"), wxEmptyString, wxITEM_NORMAL);
2425  menu.Append(ID_MACROFLOW_LIB_TO_SCRIPT, _("Add to script"), wxEmptyString, wxITEM_NORMAL);
2426  menu.Append(ID_MACROFLOW_LIB_EXPAND, _("Expand all"), wxEmptyString, wxITEM_NORMAL);
2427  menu.Append(ID_MACROFLOW_LIB_COLLAPSE, _("Collapse all"), wxEmptyString, wxITEM_NORMAL);
2428  PopupMenu(&menu);
2429 }
2430 
2431 void CMacroFlowEditor::OnLibToScript( wxCommandEvent& event )
2432 {
2433  wxWindow *win = m_Notebook->GetCurrentPage();
2434  if (!win) {
2435  return;
2436  }
2437  CScriptPanel *page = dynamic_cast<CScriptPanel*>(win);
2438 
2439  wxTreeItemId id = m_TreeCtrl->GetFocusedItem();
2440  if (!id.IsOk() || m_id_to_macro.find(id) == m_id_to_macro.end()) {
2441  return;
2442  }
2443 
2444  page->AddMacro(m_id_to_macro[id]);
2445  page->FitPage();
2446  page->SetModified(true);
2447 }
2448 
2449 void CMacroFlowEditor::OnLibToScriptUpdate( wxUpdateUIEvent& event )
2450 {
2451  wxWindow *win = m_Notebook->GetCurrentPage();
2452  if (win)
2453  {
2454  CScriptPanel *page = dynamic_cast<CScriptPanel*>(win);
2455  if (page)
2456  {
2457  wxTreeItemId id = m_TreeCtrl->GetFocusedItem();
2458 
2459  if (id.IsOk() && m_id_to_macro.find(id) != m_id_to_macro.end())
2460  {
2461  event.Enable(true);
2462  return;
2463  }
2464  }
2465  }
2466  event.Enable(false);
2467 }
2468 
2470 {
2471  if (!macro_rep)
2472  return;
2473 
2474  wxWindow *win = m_Notebook->GetCurrentPage();
2475  if (!win) {
2476  return;
2477  }
2478 
2479  CScriptPanel *page = dynamic_cast<CScriptPanel*>(win);
2480  if (page) {
2481  page->AddMacro(macro_rep);
2482  page->FitPage();
2483  page->SetModified(true);
2484  page->LookupSynonymFiles();
2486  }
2487 }
2488 
2490 {
2491  if (!macro_rep)
2492  return;
2493 
2494  wxWindow *win = m_Notebook->GetCurrentPage();
2495  if (!win) {
2496  return;
2497  }
2498  CScriptPanel *page = dynamic_cast<CScriptPanel*>(win);
2499  if (!page)
2500  return;
2501 
2503  if (labels.size() != 1)
2504  return;
2505 
2506  CMacroLabel* label = labels.begin()->second;
2507  label->UpdateMacro(macro_rep);
2508  page->LookupSynonymFiles();
2510 }
2511 
2512 /*
2513  * wxEVT_COMMAND_MENU_SELECTED event handler for ID_IMPORT_MENU
2514  */
2515 
2516 void CMacroFlowEditor::OnImportMenuClick( wxCommandEvent& event )
2517 {
2518 
2519  wxFileDialog file(this, wxT("Import Macro Library"), m_DefaultDir, wxEmptyString, _("All files (*.*)|*.*"), wxFD_OPEN | wxFD_FILE_MUST_EXIST);
2520  if (file.ShowModal() != wxID_OK)
2521  return;
2522 
2523  wxString path = file.GetPath();
2524  wxFileName filename(path);
2525  m_DefaultDir = filename.GetPath();
2526 
2527  ImportLibrary(path, true);
2528 }
2529 
2530 void CMacroFlowEditor::ImportLibrary(const wxString &path, bool report)
2531 {
2532  if (path.IsEmpty())
2533  return;
2534  m_loading_library = true;
2535  wxBusyCursor wait;
2536  wxYield();
2537 
2538  macro::CMacroEngine engine;
2539  vector<CRef<macro::CMacroRep>> macro_list;
2540  bool status = engine.ReadAndParseMacros(path.ToStdString(), macro_list);
2541 
2542  if (!status || macro_list.empty())
2543  {
2544  if (report)
2545  wxMessageBox(wxT("Error importing macro library"), wxT("Error"), wxOK | wxICON_ERROR);
2546  m_loading_library = false;
2547  return;
2548  }
2550  for (auto &p : macro_list)
2551  {
2552  string target = p->GetForEachString();
2553  string title = p->GetTitle();
2554  string action, dummy;
2555  NStr::SplitInTwo(title, " ", action, dummy);
2556  for_type_macro[ NStr::ToLower(target)][NStr::ToLower(action)][NStr::ToLower(title)].push_back(p);
2557  }
2558  m_TreeCtrl->DeleteAllItems();
2559  m_id_to_macro.clear();
2560  m_all_ids.clear();
2561  wxTreeItemId root = m_TreeCtrl->AddRoot(wxEmptyString);
2562  for (auto &t : for_type_macro)
2563  {
2564  string target = t.second.begin()->second.begin()->second.front()->GetForEachString();
2565  wxTreeItemId parent = m_TreeCtrl->AppendItem(root,wxString(target));
2566  wxColour bg = CMacroLabel::GetLabelColour(target);
2567  m_TreeCtrl->SetItemBackgroundColour(parent, bg);
2568  for (auto &a : t.second)
2569  {
2570  string title = a.second.begin()->second.front()->GetTitle();
2571  string action, dummy;
2572  NStr::SplitInTwo(title, " ", action, dummy);
2573  wxTreeItemId second = m_TreeCtrl->AppendItem(parent, wxString(action));
2574  m_TreeCtrl->SetItemBackgroundColour(second, bg);
2575  for (auto &m : a.second)
2576  {
2577  for (auto &n : m.second)
2578  {
2579  wxTreeItemId id = m_TreeCtrl->AppendItem(second, wxString(n->GetTitle()));
2580  m_TreeCtrl->SetItemBackgroundColour(id, bg);
2581  m_id_to_macro[id] = n;
2582  m_all_ids.push_back(id);
2583  }
2584  }
2585  }
2586  }
2587  m_TreeCtrl->Refresh();
2588  m_CurrentLibrary = path.ToStdString();
2589  m_loading_library = false;
2590 }
2591 
2592 
2593 /*
2594  * wxEVT_COMMAND_MENU_SELECTED event handler for ID_EXPORT_MENU
2595  */
2596 
2597 void CMacroFlowEditor::OnExportMenuClick( wxCommandEvent& event )
2598 {
2599  wxFileDialog file(this, wxT("Export Macro Library"), m_DefaultDir,
2600  wxEmptyString, _("All files (*.*)|*.*"), wxFD_SAVE | wxFD_OVERWRITE_PROMPT);
2601  if (file.ShowModal() != wxID_OK)
2602  return;
2603 
2604  wxString path = file.GetPath();
2605  if (path.IsEmpty())
2606  return;
2607  wxFileName filename(path);
2608  m_DefaultDir = filename.GetPath();
2609  {{
2610  CNcbiOfstream os(path.fn_str(), ios::out);
2611  size_t i = 0;
2612  size_t total = m_id_to_macro.size();
2613  for (auto& it : m_id_to_macro)
2614  {
2615  os << it.second->GetSource();
2616  if (i % 10 == 0)
2617  Pulse(static_cast<int>(100 * i / total));
2618  i++;
2619  }
2620  m_Progress->SetValue(0);
2621  }}
2622 }
2623 
2624 void CMacroFlowEditor::OnExportUpdate( wxUpdateUIEvent& event )
2625 {
2626  event.Enable(!m_id_to_macro.empty() && !m_loading_library);
2627 }
2628 
2629 void CMacroFlowEditor::OnEditLibrary( wxCommandEvent& event )
2630 {
2631  wxString library = wxString(m_CurrentLibrary);
2632  if (library.IsEmpty())
2633  return;
2634  OpenScript(library, false, false);
2635 }
2636 
2637 void CMacroFlowEditor::OnEditLibraryUpdate( wxUpdateUIEvent& event )
2638 {
2639  event.Enable(!m_id_to_macro.empty() && !m_loading_library && !m_CurrentLibrary.empty() );
2640 }
2641 
2642 void CMacroFlowEditor::OnDeleteFromLibrary( wxCommandEvent& event )
2643 {
2644  wxTreeItemId id = m_TreeCtrl->GetFocusedItem();
2645  if (!id.IsOk())
2646  return;
2647 
2648  wxString path = wxString(m_CurrentLibrary);
2649  if (path.IsEmpty())
2650  return;
2651  wxMessageDialog msgBox(this, wxT("Delete from library?"), wxT("Delete"), wxYES_NO | wxICON_NONE);
2652  int result = msgBox.ShowModal();
2653  if (result != wxID_YES)
2654  return;
2655 
2656  m_id_to_macro.erase(id);
2657  DeleteNode(id);
2658  {{
2659  CNcbiOfstream os(path.fn_str(), ios::out);
2660  size_t i = 0;
2661  size_t total = m_id_to_macro.size();
2662  for (auto& it : m_id_to_macro)
2663  {
2664  os << it.second->GetSource();
2665  if (i % 10 == 0)
2666  Pulse(static_cast<int>(100 * i / total));
2667  i++;
2668  }
2669  m_Progress->SetValue(0);
2670  }}
2671 
2672  Freeze();
2673  set<string> expanded_nodes;
2674  GetExpandedNodes(m_TreeCtrl->GetRootItem(), expanded_nodes);
2676  SetExpandedNodes(m_TreeCtrl->GetRootItem(), expanded_nodes);
2677  Thaw();
2678 }
2679 
2680 void CMacroFlowEditor::OnDeleteFromLibraryUpdate( wxUpdateUIEvent& event )
2681 {
2682  wxTreeItemId id = m_TreeCtrl->GetFocusedItem();
2683  event.Enable(id.IsOk() && !m_id_to_macro.empty() && !m_loading_library && !m_CurrentLibrary.empty());
2684 }
2685 
2686 void CMacroFlowEditor::OnLibExpand( wxCommandEvent& event )
2687 {
2688  m_TreeCtrl->ExpandAll();
2689 }
2690 
2691 void CMacroFlowEditor::OnLibCollapse( wxCommandEvent& event )
2692 {
2693  m_TreeCtrl->CollapseAll();
2694 }
2695 
2696 void CMacroFlowEditor::OnLibraryExpandUpdate( wxUpdateUIEvent& event )
2697 {
2698  event.Enable(!m_id_to_macro.empty() && !m_loading_library);
2699 }
2700 
2701 void CMacroFlowEditor::DeleteNode(wxTreeItemId &id)
2702 {
2703  if (!m_TreeCtrl->ItemHasChildren(id))
2704  return;
2705 
2706  wxTreeItemIdValue cookie;
2707  wxTreeItemId child = m_TreeCtrl->GetFirstChild(id, cookie);
2708  while (child.IsOk())
2709  {
2710  m_id_to_macro.erase(child);
2711  if (m_TreeCtrl->ItemHasChildren(child))
2712  {
2713  DeleteNode(child);
2714  }
2715  child = m_TreeCtrl->GetNextChild(id, cookie);
2716  }
2717 }
2718 
2720 {
2721  wxMessageDialog msgBox(this, wxT("Library has been modified, reload?"), wxT("Library modified"), wxYES_NO | wxICON_NONE);
2722  int result = msgBox.ShowModal();
2723  if (result == wxID_YES) {
2724  Freeze();
2725  set<string> expanded_nodes;
2726  GetExpandedNodes(m_TreeCtrl->GetRootItem(), expanded_nodes);
2728  SetExpandedNodes(m_TreeCtrl->GetRootItem(), expanded_nodes);
2729  Thaw();
2730  }
2731 }
2732 
2733 void CMacroFlowEditor::GetExpandedNodes(wxTreeItemId id, set<string> &expanded_nodes, string label)
2734 {
2735  label += "/";
2736  if (id.IsOk() && m_TreeCtrl->ItemHasChildren(id)) {
2737  if (id != m_TreeCtrl->GetRootItem()) {
2738  label += m_TreeCtrl->GetItemText(id).ToStdString();
2739  if (m_TreeCtrl->IsExpanded(id)) {
2740  expanded_nodes.insert(label);
2741  }
2742  }
2743  wxTreeItemIdValue cookie;
2744  wxTreeItemId child = m_TreeCtrl->GetFirstChild(id, cookie);
2745  while (child.IsOk()) {
2746  GetExpandedNodes(child, expanded_nodes, label);
2747  child = m_TreeCtrl->GetNextChild(id, cookie);
2748  }
2749  }
2750 }
2751 
2752 void CMacroFlowEditor::SetExpandedNodes(wxTreeItemId id, const set<string> &expanded_nodes, string label)
2753 {
2754  label += "/";
2755  if (id.IsOk() && m_TreeCtrl->ItemHasChildren(id)) {
2756  if (id != m_TreeCtrl->GetRootItem()) {
2757  label += m_TreeCtrl->GetItemText(id).ToStdString();
2758  if (expanded_nodes.find(label) != expanded_nodes.end())
2759  m_TreeCtrl->Expand(id);
2760  else
2761  m_TreeCtrl->Collapse(id);
2762  }
2763  wxTreeItemIdValue cookie;
2764  wxTreeItemId child = m_TreeCtrl->GetFirstChild(id, cookie);
2765  while (child.IsOk()) {
2766  SetExpandedNodes(child, expanded_nodes, label);
2767  child = m_TreeCtrl->GetNextChild(id, cookie);
2768  }
2769  }
2770 }
2771 
2772 /*
2773  * wxEVT_COMMAND_MENU_SELECTED event handler for ID_SKIP_STEP
2774  */
2775 
2776 void CMacroFlowEditor::OnSkipStepClick( wxCommandEvent& event )
2777 {
2778  wxWindow *win = m_Notebook->GetCurrentPage();
2779  if (!win)
2780  return;
2781 
2782  CScriptPanel *page = dynamic_cast<CScriptPanel*>(win);
2783  if (!page)
2784  return;
2785  page->ToggleSkip();
2786 }
2787 
2788 
2789 /*
2790  * wxEVT_UPDATE_UI event handler for ID_SKIP_STEP
2791  */
2792 
2793 void CMacroFlowEditor::OnSkipStepUpdate( wxUpdateUIEvent& event )
2794 {
2795  wxWindow *win = m_Notebook->GetCurrentPage();
2796  if (win)
2797  {
2798  CScriptPanel *page = dynamic_cast<CScriptPanel*>(win);
2799  if (page && !page->IsDragging() && page->IsMacroSelected() && !m_loading_script && !m_running)
2800  {
2801  event.Enable(true);
2802  return;
2803  }
2804  }
2805  event.Enable(false);
2806 }
2807 
2808 void CMacroFlowEditor::OnSetDefaultLibrary( wxCommandEvent& event )
2809 {
2810  wxMessageDialog msgBox(this, wxEmptyString, wxT("Set Default Library"), wxYES_NO | wxCANCEL | wxICON_NONE);
2811  msgBox.SetYesNoCancelLabels(_("&Set current library as default"), _("&Reset default library"), _("&Cancel"));
2812  int result = msgBox.ShowModal();
2813  if (result == wxID_CANCEL)
2814  {
2815  return;
2816  }
2817  if (result == wxID_YES)
2818  {
2820  }
2821  if (result == wxID_NO)
2822  {
2823  m_DefaultLibrary.clear();
2824  m_CurrentLibrary.clear();
2826  ImportLibrary(wxString(m_DefaultLibrary), true);
2827  }
2828 }
2829 
2830 void CMacroFlowEditor::OnLockDrag( wxCommandEvent& event )
2831 {
2832  // event.Skip();
2833  m_Lock = !m_Lock;
2834  if (m_Lock)
2835  m_toolbar->SetToolNormalBitmap(ID_MACROFLOW_LOCK_DRAG, m_LockBitmap);
2836  else
2837  m_toolbar->SetToolNormalBitmap(ID_MACROFLOW_LOCK_DRAG, m_UnlockBitmap);
2838 }
2839 
2841 {
2842  wxPoint pos = GetPosition();
2843  SetPosition(wxPoint(pos.x + 5, pos.y));
2844 
2845  if (wxTheApp && wxTheApp->GetMainLoop()) {
2846  if (!wxTheApp->GetMainLoop()->IsYielding())
2847  wxTheApp->Yield(true);
2848  wxTheApp->ProcessPendingEvents();
2849  }
2850  wxMilliSleep(100);
2851  SetPosition(wxPoint(pos.x - 5, pos.y));
2852 
2853  if (wxTheApp && wxTheApp->GetMainLoop()) {
2854  if (!wxTheApp->GetMainLoop()->IsYielding())
2855  wxTheApp->Yield(true);
2856  wxTheApp->ProcessPendingEvents();
2857  }
2858  wxMilliSleep(100);
2859  SetPosition(pos);
2860 }
2861 
2862 void CMacroFlowEditor::OnCollapsiblePane(wxCollapsiblePaneEvent& event)
2863 {
2864  bool maximized = IsMaximized();
2865  if (maximized)
2866  {
2867  Maximize(false);
2868  }
2869  wxSize sz = GetSize();
2870  if (event.GetCollapsed())
2871  {
2872  SetSize(sz.GetWidth() - m_colpane_width, sz.GetHeight());
2873  }
2874  else
2875  {
2876 // m_colpane_width = m_CollapsibleWindow->GetSize().GetWidth();
2877  SetSize(sz.GetWidth() + m_colpane_width, sz.GetHeight());
2878  }
2879  if (maximized)
2880  {
2881  Maximize(true);
2882  }
2883 }
2884 
EVT_UPDATE_UI(eCmdAlnShowMethodsDlg, CAlnMultiWidget::OnUpdateShowMethodDlg) EVT_UPDATE_UI(eCmdMethodProperties
static CBioSource dummy
CDir –.
Definition: ncbifile.hpp:1695
CFile –.
Definition: ncbifile.hpp:1604
EFormat
The formats are checked in the same order as declared here.
@ eBinaryASN
Binary ASN.1.
@ eTextASN
Text ASN.1.
static EFormat Format(const string &path, EOnError onerror=eDefault)
Guess file format.
void SetText(const wxString &text)
CRegistryWriteView GetWriteView(const string &section)
get a read-write view at a particular level.
Definition: registry.cpp:462
void Write(CNcbiOstream &ostr, int priority=ePriority_Local) const
Write the local policy to a specified stream.
Definition: registry.cpp:124
static CGuiRegistry & GetInstance()
access the application-wide singleton
Definition: registry.cpp:400
CRegistryReadView GetReadView(const string &section) const
get a read-only view at a particular level.
Definition: registry.cpp:428
CRef< CRegistryFile > AddSite(CNcbiIstream &istr, int priority)
Add a site-specific repository.
Definition: registry.cpp:83
implements special composite command, which does not call to its internal commands when run the very ...
void SetException(const string &message, const CException &error)
void OnLibraryExpandUpdate(wxUpdateUIEvent &event)
bool Create(wxWindow *parent, wxWindowID id=15000, const wxString &caption=_("Macro Flow Editor"), const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(1500, 1000), long style=wxCAPTION|wxRESIZE_BORDER|wxSYSTEM_MENU|wxMINIMIZE_BOX|wxMAXIMIZE_BOX|wxCLOSE_BOX)
void OnLibToScript(wxCommandEvent &event)
void OnPageChanging(wxAuiNotebookEvent &event)
void OnEditUpdate(wxUpdateUIEvent &event)
wxEVT_UPDATE_UI event handler for wxID_CUT
vector< CRef< macro::CMacroRep > > m_clipboard
map< wxTreeItemId, CRef< macro::CMacroRep > > m_id_to_macro
void OnOpenClick(wxCommandEvent &event)
wxEVT_COMMAND_MENU_SELECTED event handler for wxID_OPEN
void RunScriptStandalone(const vector< pair< CRef< macro::CMacroRep >, bool > > &script, CScriptPanel *page)
void OnAddUpdate(wxUpdateUIEvent &event)
wxEVT_UPDATE_UI event handler for wxID_ADD
void OnExportMenuClick(wxCommandEvent &event)
wxEVT_COMMAND_MENU_SELECTED event handler for ID_EXPORT_MENU
void OnForwardUpdate(wxUpdateUIEvent &event)
wxEVT_UPDATE_UI event handler for wxID_FORWARD
wxTreeItemId m_drag_id
void OnEditLibrary(wxCommandEvent &event)
wxArrayString m_InputFiles
void OnPageChanged(wxAuiNotebookEvent &event)
void OnStopUpdate(wxUpdateUIEvent &event)
wxEVT_UPDATE_UI event handler for wxID_STOP
CRef< IGuiCoreHelper > m_gui_core_helper
void OnSaveAsClick(wxCommandEvent &event)
wxTextCtrl * m_InputFileText
void OnDeleteClick(wxCommandEvent &event)
wxEVT_COMMAND_MENU_SELECTED event handler for wxID_DELETE
void OnTreectrlItemDrag(wxTreeEvent &event)
void OnDeleteFromLibrary(wxCommandEvent &event)
wxWindow * m_CollapsibleWindow
void OnCutClick(wxCommandEvent &event)
wxEVT_COMMAND_MENU_SELECTED event handler for wxID_CUT
void RemoveEditor(bool scroll_to_end)
void OnEditLibraryUpdate(wxUpdateUIEvent &event)
void OnPasteClick(wxCommandEvent &event)
wxEVT_COMMAND_MENU_SELECTED event handler for wxID_PASTE
void OnPageClose(wxAuiNotebookEvent &event)
void OnTreectrlItemDrop(wxTreeEvent &event)
void OnUpdateSynFileUpdate(wxUpdateUIEvent &event)
void OnExportUpdate(wxUpdateUIEvent &event)
void OnIncreaseFont(wxCommandEvent &event)
void OpenEditor(CRef< macro::CMacroRep > macro_rep)
void OnRecent(wxCommandEvent &event)
wxIcon GetIconResource(const wxString &name)
Retrieves icon resources.
void SetSynonymFile(const string &filename)
void OnSetDefaultLibrary(wxCommandEvent &event)
void OnTreectrlItemActivated(wxTreeEvent &event)
wxEVT_COMMAND_TREE_ITEM_ACTIVATED event handler for ID_TREECTRL
wxAuiNotebook * m_Notebook
void OnDecreaseFont(wxCommandEvent &event)
void OnUndoUpdate(wxUpdateUIEvent &event)
void OnTreectrlMenu(wxTreeEvent &event)
void OnSaveUpdate(wxUpdateUIEvent &event)
wxEVT_UPDATE_UI event handler for wxID_SAVE
void OnDeleteFromLibraryUpdate(wxUpdateUIEvent &event)
void OnLibToScriptUpdate(wxUpdateUIEvent &event)
void OnAddClick(wxCommandEvent &event)
wxEVT_COMMAND_MENU_SELECTED event handler for wxID_ADD
void OpenSynonymFile(wxCommandEvent &event)
vector< wxTreeItemId > m_all_ids
void RunScriptInWidget(const vector< pair< CRef< macro::CMacroRep >, bool > > &script, CScriptPanel *page)
void OnInputFile(wxCommandEvent &event)
wxTreeCtrl * m_TreeCtrl
wxDirPickerCtrl * m_OutputFolder
void OnCopyClick(wxCommandEvent &event)
wxEVT_COMMAND_MENU_SELECTED event handler for wxID_COPY
wxTextCtrl * m_Search
wxTextCtrl * m_SynFileCtrl
void Init()
Initialises member variables.
void UpdateCounter(CScriptPanel *page, size_t i, size_t counter)
void OnManualEditMacroUpdate(wxUpdateUIEvent &event)
void OnForwardClick(wxCommandEvent &event)
wxEVT_COMMAND_MENU_SELECTED event handler for wxID_FORWARD
const string GetSynonymFile() const
void OnUpdateSynonymFile(wxCommandEvent &event)
void OnLibExpand(wxCommandEvent &event)
void OnImportMenuClick(wxCommandEvent &event)
wxEVT_COMMAND_MENU_SELECTED event handler for ID_IMPORT_MENU
void OnDuplicateUpdate(wxUpdateUIEvent &event)
objects::CSeq_entry_Handle m_undo_tse
static CMacroFlowEditor * GetInstance(wxWindow *parent, CRef< IGuiCoreHelper > gui_core_helper, wxWindowID id=15000, const wxString &caption=_("Macro Flow Editor"), const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(1500, 1000), long style=wxCAPTION|wxRESIZE_BORDER|wxSYSTEM_MENU|wxMINIMIZE_BOX|wxMAXIMIZE_BOX|wxCLOSE_BOX)
virtual void SaveSettings() const
void OnExportStepsClick(wxCommandEvent &event)
map< int, string > m_id_to_path
void SaveScript(const wxString &path, const vector< pair< CRef< macro::CMacroRep >, bool > > &script)
void SaveAddMacroSizeAndPosition(int w, int h, int x, int y)
void GetExpandedNodes(wxTreeItemId id, set< string > &expanded_nodes, string label=kEmptyStr)
void OnDuplicateClick(wxCommandEvent &event)
void AddNewMacro(CRef< macro::CMacroRep > macro_rep)
list< string > m_opened_scripts
CMacroEditor * m_MacroEditor
void OpenScript(const wxString &path, bool recent_scripts, bool allow_empty)
wxBitmap GetBitmapResource(const wxString &name)
Retrieves bitmap resources.
CMacroFlowEditor()
Constructors.
void CreateControls()
Creates the controls and sizers.
void OnCollapsiblePane(wxCollapsiblePaneEvent &event)
static bool ShowToolTips()
Should we show tooltips?
void OnSaveAsUpdate(wxUpdateUIEvent &event)
void OnFindClick(wxCommandEvent &event)
wxEVT_COMMAND_MENU_SELECTED event handler for wxID_FIND
void OnSkipStepUpdate(wxUpdateUIEvent &event)
wxEVT_UPDATE_UI event handler for ID_SKIP_STEP
wxString GetSettingsPath() const
IUndoManager * m_UndoManager
void OnNewClick(wxCommandEvent &event)
@begin CMacroFlowEditor event handler declarations
CScriptPanel::TVecMacroRep TVecMacroRep
CScriptPanel * x_GetCurrentPage() const
void UpdateEditedMacro(CRef< macro::CMacroRep > macro_rep)
void OnLibCollapse(wxCommandEvent &event)
virtual void SetRegistryPath(const string &reg_path)
void OnManualEditMacro(wxCommandEvent &event)
void OnPasteUpdate(wxUpdateUIEvent &event)
void OnExitClick(wxCommandEvent &event)
wxEVT_COMMAND_MENU_SELECTED event handler for wxID_EXIT
void OnStopClick(wxCommandEvent &event)
wxEVT_COMMAND_MENU_SELECTED event handler for wxID_STOP
wxCollapsiblePane * m_CollapsiblePanel
virtual void LoadSettings()
void DeleteNode(wxTreeItemId &id)
void OnSaveClick(wxCommandEvent &event)
wxEVT_COMMAND_MENU_SELECTED event handler for wxID_SAVE
void OnClose(wxCloseEvent &event)
~CMacroFlowEditor()
Destructor.
void OnSkipStepClick(wxCommandEvent &event)
wxEVT_COMMAND_MENU_SELECTED event handler for ID_SKIP_STEP
void SetExpandedNodes(wxTreeItemId id, const set< string > &expanded_nodes, string label=kEmptyStr)
void OnReportSynFileStatus(wxCommandEvent &event)
vector< bool > m_clipboard_skipped
bool RunScript(const vector< pair< CRef< macro::CMacroRep >, bool > > &script, CScriptPanel *page, wxString &log, size_t num_files, size_t num_entries, objects::CSeq_entry_Handle seh, CConstRef< objects::CSeq_submit > submit=CConstRef< objects::CSeq_submit >(NULL), CRef< CCmdComposite > cmd=CRef< CCmdComposite >(NULL))
void OnAppendClick(wxCommandEvent &event)
void OnUndo(wxCommandEvent &event)
static CMacroFlowEditor * m_Instance
void OnFindUpdate(wxUpdateUIEvent &event)
wxEVT_UPDATE_UI event handler for wxID_FIND
void OnSaveCopies(wxCommandEvent &event)
void ImportLibrary(const wxString &path, bool report)
void OnLockDrag(wxCommandEvent &event)
static wxColour GetLabelColour(const string &str)
CRef< macro::CMacroRep > GetMacro()
class CRegistryReadView provides a nested hierarchical view at a particular key.
Definition: reg_view.hpp:58
int GetInt(const string &key, int default_val=0) const
access a named key at this level, with no recursion
Definition: reg_view.cpp:230
bool GetBool(const string &key, bool default_val=false) const
Definition: reg_view.cpp:241
string GetString(const string &key, const string &default_val=kEmptyStr) const
Definition: reg_view.cpp:246
void GetStringList(const string &key, list< string > &val) const
Definition: reg_view.cpp:268
void Set(const string &key, int val)
access a named key at this level, with no recursion
Definition: reg_view.cpp:533
void ScrollToBottom()
void UnselectMacro()
void DecreaseFont()
void SetPath(const wxString &path)
void ResetCounters()
void DeleteSelected()
bool IsDragging()
wxString GetPath()
void SetSynonymFile(const string &filename)
TVecMacroRep GetMacros()
size_t GetIndex(CMacroLabel *label)
void ToggleSkip()
void SetModified(bool modified)
void SaveScrollPos()
void SelectItem(size_t item)
const map< size_t, CMacroLabel * > & GetSelectedMacros()
CMacroLabel * AddMacro(CRef< macro::CMacroRep > macro)
bool IsMacroSelected()
static const string sm_Multiple
Definition: scriptpanel.hpp:81
const string & GetSynonymFile() const
void IncreaseFont()
vector< pair< CRef< macro::CMacroRep >, bool > > GetScript()
bool UpdateMacroSources(const TVecMacroRep &script)
void UpdateCounter(size_t i, size_t counter)
void LoadScrollPos()
bool IsModified()
void LookupSynonymFiles()
CMacroLabel * InsertMacro(CRef< macro::CMacroRep > macro, size_t index)
static wxString ResolvePath(const wxString &path, const wxString &rel_name)
Utility function to hide the platform specifics of locating our standard directories and files.
Definition: sys_path.cpp:106
static wxString ResolvePathExisting(const wxString &path, const wxString &delim=wxT(","))
Utility function to hide the platform specifics of locating our standard directories.
Definition: sys_path.cpp:142
CwxSplittingArtProvider - an adapter for old-style image aliases.
Definition: wx_utils.hpp:255
Undo/Redo interface for editing operations.
virtual void Execute(IEditCommand *command, wxWindow *window=0)=0
virtual void Sync()
objects::CSeq_entry_Handle GetTopSeqEntry()
CConstRef< objects::CSeq_submit > GetSeqSubmit()
ICommandProccessor * GetCmdProcessor()
virtual bool RequestExclusiveEdit(wxWindow *window, const string &descr)=0
virtual bool CanUndo()=0
virtual bool ReleaseExclusiveEdit(wxWindow *window)=0
virtual void Undo(wxWindow *window=0)=0
void erase(iterator pos)
Definition: map.hpp:167
size_type size() const
Definition: map.hpp:148
const_iterator begin() const
Definition: map.hpp:151
const_iterator end() const
Definition: map.hpp:152
bool empty() const
Definition: map.hpp:149
void clear()
Definition: map.hpp:169
const_iterator find(const key_type &key) const
Definition: map.hpp:153
iterator_bool insert(const value_type &val)
Definition: set.hpp:149
const_iterator find(const key_type &key) const
Definition: set.hpp:137
const_iterator end() const
Definition: set.hpp:136
virtual void RegisterFileAlias(const wxArtID &anId, const wxArtClient &aClient, const wxSize &aSize, const wxString &aName, long aType=wxBITMAP_TYPE_ANY, int anIndex=-1)
int AddDirectory(wxString aDirName)
#define _(proto)
Definition: ct_nlmzip_i.h:78
IMPLEMENT_CLASS(CFloatingFrame, CFloatingFrameBaseClass) const static long kFloatFrameStyle
CFloatingFrame.
std::ofstream out("events_result.xml")
main entry point for tests
static CS_COMMAND * cmd
Definition: ct_dynamic.c:26
#define true
Definition: bool.h:35
#define false
Definition: bool.h:36
static DLIST_TYPE *DLIST_NAME() prev(DLIST_LIST_TYPE *list, DLIST_TYPE *item)
Definition: dlist.tmpl.h:61
static void Init(void)
Definition: cursor6.c:76
static SQLCHAR output[256]
Definition: print.c:5
static const char * str(char *buf, int n)
Definition: stats.c:84
#define NON_CONST_ITERATE(Type, Var, Cont)
Non constant version of ITERATE macro.
Definition: ncbimisc.hpp:822
@ eTakeOwnership
An object can take ownership of another.
Definition: ncbi_types.h:136
string
Definition: cgiapp.hpp:687
#define NULL
Definition: ncbistd.hpp:225
#define LOG_POST(message)
This macro is deprecated and it's strongly recomended to move in all projects (except tests) to macro...
Definition: ncbidiag.hpp:226
void Error(CExceptionArgs_Base &args)
Definition: ncbiexpt.hpp:1197
const string & GetMsg(void) const
Get message string.
Definition: ncbiexpt.cpp:461
virtual const char * what(void) const noexcept
Standard report (includes full backlog).
Definition: ncbiexpt.cpp:342
virtual bool Copy(const string &new_path, TCopyFlags flags=fCF_Default, size_t buf_size=0) const
Copy a file.
Definition: ncbifile.cpp:3334
virtual bool Remove(TRemoveFlags flags=eRecursive) const
Remove a directory entry.
Definition: ncbifile.cpp:2595
virtual bool Exists(void) const
Check if directory "dirname" exists.
Definition: ncbifile.hpp:4065
static string ConcatPathEx(const string &first, const string &second)
Concatenate two parts of the path for any OS.
Definition: ncbifile.cpp:791
bool IsFile(EFollowLinks follow=eFollowLinks) const
Check whether a directory entry is a file.
Definition: ncbifile.hpp:3940
bool Create(TCreateFlags flags=fCreate_Default) const
Create the directory using "dirname" passed in the constructor.
Definition: ncbifile.cpp:4071
virtual bool Exists(void) const
Check existence of file.
Definition: ncbifile.hpp:4038
virtual void Execute()
Do the editing action.
virtual void Unexecute()
Undo (opposite to Execute())
EDialogReturnValue NcbiInfoBox(const string &message, const string &title="Info")
specialized Message Box function for reporting general information messages
void NcbiWarningBox(const string &message, const string &title="Warning")
specialized Message Box function for reporting non-critical errors
void NcbiErrorBox(const string &message, const string &title="Error")
specialized Message Box function for reporting critical errors
EDialogReturnValue NcbiMessageBox(const string &message, TDialogType type=eDialog_Ok, EDialogIcon icon=eIcon_Exclamation, const string &title="Error", EDialogTextMode text_mode=eRaw)
Definition: message_box.cpp:48
@ eSerial_AsnText
ASN.1 text.
Definition: serialdef.hpp:73
@ eSerial_AsnBinary
ASN.1 binary.
Definition: serialdef.hpp:74
pair< TObjectPtr, TTypeInfo > ObjectInfo(C &obj)
Definition: objectinfo.hpp:762
static CObjectOStream * Open(ESerialDataFormat format, CNcbiOstream &outStream, bool deleteOutStream)
Create serial object writer and attach it to an output stream.
Definition: objostr.cpp:126
static CObjectIStream * Open(ESerialDataFormat format, CNcbiIstream &inStream, bool deleteInStream)
Create serial object reader and attach it to an input stream.
Definition: objistr.cpp:195
void Reset(void)
Reset reference object.
Definition: ncbiobj.hpp:773
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
void NcbiStreamCopyThrow(CNcbiOstream &os, CNcbiIstream &is)
Same as NcbiStreamCopy() but throws an CCoreException when copy fails.
Definition: ncbistre.cpp:225
IO_PREFIX::ofstream CNcbiOfstream
Portable alias for ofstream.
Definition: ncbistre.hpp:500
IO_PREFIX::ifstream CNcbiIfstream
Portable alias for ifstream.
Definition: ncbistre.hpp:439
#define kEmptyStr
Definition: ncbistr.hpp:123
static SIZE_TYPE FindNoCase(const CTempString str, const CTempString pattern, SIZE_TYPE start, SIZE_TYPE end, EOccurrence which=eFirst)
Find the pattern in the specified range of a string using a case insensitive search.
Definition: ncbistr.cpp:2993
#define NPOS
Definition: ncbistr.hpp:133
static bool SplitInTwo(const CTempString str, const CTempString delim, string &str1, string &str2, TSplitFlags flags=0)
Split a string into two pieces using the specified delimiters.
Definition: ncbistr.cpp:3554
static string & ToLower(string &str)
Convert string to lower case – string& version.
Definition: ncbistr.cpp:405
static const char label[]
@ eIcon_Question
Definition: types.hpp:64
EDialogReturnValue
enumerated return values for dialog boxes, starting from 1 to undermine attempts to cast it "bool"
Definition: types.hpp:71
@ eDialog_YesNo
Definition: types.hpp:49
END_EVENT_TABLE()
FILE * file
int i
yy_size_t n
static bool s_ReplaceInPlaceBetweenQuotes(string &str, const string &search, const string &replace)
static const char * kFramePosX
static const char * sSaveLocalCopies[]
static const char * kFrameHeight
static const char * kHideLibrary
static const char * kOpenedScripts
static const char * kExclusiveEditDescr
static const char * kAddMacroPosX
static const char * kAddMacroWidth
static const char * kDefaultLibraryLocation
static const char * kDefaultLibrary
static const char * kAddMacroPosY
static const char * kFramePosY
static const char * kFrameWidth
static const char * kAddMacroHeight
#define ID_TREECTRL
#define ID_MACROFLOW_UNDO
#define ID_MACROFLOW_LIB_TO_SCRIPT
#define ID_MACROFLOW_UPDATESYNFILE
#define ID_EDIT_LIB_MENU
#define ID_EXPORT_MENU
#define ID_MACROFLOW_REPORTSYNFILE
#define ID_MACROFLOW_STOP
#define ID_MACROFLOW_CUT
#define ID_MACROFLOW_ZOOM_OUT
#define ID_MACROFLOW_SAVEAUTOFIXWGS
#define ID_MACROFLOW_LIB_EXPAND
#define ID_DIRPICKERCTRL
#define ID_COLLAPSIBLE_PANE
#define ID_MACROFLOW_APPEND
#define ID_MACROFLOW_OPENSYNFILE
#define ID_MACROFLOW_ADD
#define ID_MACROFLOW_FIND
#define ID_MACROFLOW_OPEN
#define ID_MACROFLOW_SAVE_AS
#define ID_MACROFLOW_LIB_COLLAPSE
#define ID_NOTEBOOK
#define ID_MACROFLOW_SAVEAUTOFIXGB
#define ID_MACROFLOW_LOCK_DRAG
#define ID_MACROFLOW_DELETE
#define ID_MACROFLOW_EXPORT_STEPS
#define ID_MACROFLOW_SAVESYN
#define ID_FILECTRL
#define ID_TOOLBAR
#define ID_MACROFLOW_COPY
#define ID_SKIP_STEP
#define ID_IMPORT_MENU
#define ID_MACROFLOW_PASTE
#define ID_MACROFLOW_ZOOM_IN
#define ID_MACROFLOW_FORWARD
#define ID_MACROFLOW_SAVEAUTOFIXTSA
#define ID_MACROFLOW_DEL_FROM_LIB
#define ID_MACROFLOW_SAVE
#define ID_MANUALEDITMACRO
#define ID_MACROFLOW_DUPLICATE
#define ID_MACROFLOW_NEW
#define ID_SET_LIB_MENU
#define wxT(x)
Definition: muParser.cpp:41
const TYPE & Get(const CNamedParameterList *param)
void SaveScriptFromLibrary(const string &macro)
Save macro obtained from the library.
void ReportUsage(const wxString &dialog_name, const string &action_name)
Report events in the macro_flow_editor and in the macro_editor.
void ReportMacroExecution()
Report when a macro is executed.
const struct ncbi::grid::netcache::search::fields::SIZE size
const GenericPointer< typename T::ValueType > T2 value
Definition: pointer.h:1227
const CharType(& source)[N]
Definition: pointer.h:1149
unsigned int a
Definition: ncbi_localip.c:102
EIPRangeType t
Definition: ncbi_localip.c:101
Defines the CNcbiApplication and CAppException classes for creating NCBI applications.
Defines command line argument related classes.
static Format format
Definition: njn_ioutil.cpp:53
std::istream & in(std::istream &in_, double &x_)
The Object manager core.
static int filenames
Definition: pcregrep.c:172
static static static wxID_ANY
ViewerWindowBase::OnEditMenu ViewerWindowBase::OnJustification EVT_MENU(MID_SHOW_GEOM_VLTNS, ViewerWindowBase::OnShowGeomVltns) EVT_MENU(MID_FIND_PATTERN
#define ID_TEXTCTRL
else result
Definition: token2.c:20
void OpenFileBrowser(const wxString &path)
Definition: wx_utils.cpp:129
wxString GetAbsolutePath(const wxString &localpath)
Definition: wx_utils.cpp:188
wxString ToWxString(const string &s)
Definition: wx_utils.hpp:173
string ToStdString(const wxString &s)
Definition: wx_utils.hpp:161
wxRect GetScreenRect(const wxWindow &win)
Definition: wx_utils.cpp:783
Modified on Mon Apr 22 04:06:40 2024 by modify_doxy.py rev. 669887