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

Go to the SVN repository for this file.

1 /* $Id: pt_project_folder.cpp 47479 2023-05-02 13:24:02Z ucko $
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: Roman Katargin
27  *
28  * File Description:
29  *
30  */
31 
32 #include <ncbi_pch.hpp>
33 
34 #include <objects/general/Date.hpp>
37 
39 #include <gui/core/pt_project.hpp>
42 #include <gui/core/pt_utils.hpp>
46 
48 
51 
52 #include <wx/treectrl.h>
53 #include <wx/wupdlock.h>
54 
55 #include <serial/iterator.hpp>
56 
58 
59 using namespace PT;
60 
61 
62 
63 void CProjectFolder::ExpandCompacted(wxTreeCtrl& treeCtrl, wxTreeItemId& compacted_node, CGBDocument& doc, IStatusBarService* sb_srv, ICanceled* cancel)
64 {
65  wxTreeItemData* data = treeCtrl.GetItemData(compacted_node);
66  PT::CProjectFolder* folder = dynamic_cast<PT::CProjectFolder*>(data);
67  if (!folder || !folder->IsCompacted())
68  return;
69  auto parent_folder = dynamic_cast<PT::CProjectFolder*>(treeCtrl.GetItemData(treeCtrl.GetItemParent(compacted_node)));
70  if (!parent_folder)
71  return;
72  auto folder_data = folder->GetData();
73  auto total = folder_data->SetItems().size();
74  wxString str;
75  int cnt = 0;
76  for (auto& it : folder_data->SetItems()) {
77  if (cancel && cancel->IsCanceled())
78  break;
79  objects::CProjectItem& prj_item = *it;
80  if (sm_HideDisabledItems && !prj_item.IsEnabled())
81  continue;
82  CProjectItem* new_item = new CProjectItem(CRef<objects::CProjectItem>(&prj_item));
83  parent_folder->AppendChildItem(treeCtrl, *new_item);
84  new_item->Initialize(treeCtrl, doc);
85  if (++cnt % 3000 == 0 && sb_srv) {
86  str.Printf(wxT("Expanding project items (%d out of %d)"), cnt, total);
87  sb_srv->SetStatusMessage(string(str.mb_str()));
88  }
89  }
90  if (sb_srv)
91  sb_srv->SetStatusMessage("");
92  treeCtrl.Delete(compacted_node);
93 
94 }
95 
96 
97 void CProjectFolder::Initialize(wxTreeCtrl& treeCtrl, CGBDocument& doc)
98 {
100 
101  objects::CProjectFolder& folder = *GetData();
102 
103 
104  treeCtrl.SetItemImage(m_TreeItemId,
106  wxTreeItemIcon_Normal);
107  treeCtrl.SetItemImage(m_TreeItemId,
109  wxTreeItemIcon_Expanded);
110 
111  const objects::CFolderInfo& info = folder.GetInfo();
112  wxString name = ToWxString(info.GetTitle());
113  treeCtrl.SetItemText(m_TreeItemId, name);
114 
115  bool is_open = info.IsSetOpen() ? info.GetOpen() : false;
116 
117  if (folder.CanGetFolders()) {
118  NON_CONST_ITERATE(objects::CProjectFolder::TFolders, it, folder.SetFolders()) {
119  objects::CProjectFolder& sub_folder = **it;
120  CProjectFolder* new_item = new CProjectFolder(CRef<objects::CProjectFolder>(&sub_folder));
121  AppendChildItem(treeCtrl, *new_item);
122  new_item->Initialize(treeCtrl, doc);
123  }
124  }
125 
126  if (folder.CanGetItems()) {
127  size_t count = 0;
128  wxTreeItemId collapsed_node;
129  NON_CONST_ITERATE(objects::CProjectFolder::TItems, it, folder.SetItems()) {
130  objects::CProjectItem& prj_item = **it;
131  if (sm_HideDisabledItems && !prj_item.IsEnabled())
132  continue;
133  CProjectItem* new_item = new CProjectItem(CRef<objects::CProjectItem>(&prj_item));
134  AppendChildItem(treeCtrl, *new_item);
135  new_item->Initialize(treeCtrl, doc);
136  ++count;
137  if (count >= 2500 && collapsed_node.IsOk() == false) {
138  auto prj_folder = Ref(new objects::CProjectFolder);
139  prj_folder->SetInfo().SetCreateDate(CTime(CTime::eCurrent));
140  prj_folder->SetInfo().SetTitle("");
141  int cnt = 0;
142  while (++it != folder.SetItems().end()) {
143  objects::CProjectItem& prj_item = **it;
144  if (sm_HideDisabledItems && !prj_item.IsEnabled())
145  continue;
146  prj_folder->AddChildItem(prj_item);
147  ++cnt;
148  }
149  prj_folder->SetParentFolder(&folder);
150  CProjectFolder* data_item = new CProjectFolder(prj_folder);
151  data_item->SetCompacted(true);
152  wxString s;
153  s.Printf(wxT("Double-click to show %d additional items"), cnt);
154  data_item->m_TreeItemId = collapsed_node = treeCtrl.AppendItem(m_TreeItemId, s, -1, -1, data_item);
155  treeCtrl.SetItemImage(collapsed_node, icons.GetImageIndex(CPTIcons::eHiddenItemsIcon), wxTreeItemIcon_Normal);
156  //treeCtrl.SetItemImage(collapsed_node, icons.GetImageIndex(CPTIcons::eHiddenItemsIcon), wxTreeItemIcon_Expanded);
157  break;
158  }
159  wxYield();
160  }
161  }
162 
163  if (is_open)
164  treeCtrl.Expand(m_TreeItemId);
165  else
166  treeCtrl.Collapse(m_TreeItemId);
167 }
168 
169 static size_t s_CountDisabledItems(objects::CProjectFolder& folder)
170 {
171  size_t count = 0;
172  if (folder.CanGetItems()) {
173  ITERATE(objects::CProjectFolder::TItems, it, folder.GetItems()) {
174  if (!(*it)->IsEnabled())
175  ++count;
176  }
177  }
178  return count;
179 }
180 
181 size_t CProjectFolder::CountDisabledItems(wxTreeCtrl& treeCtrl)
182 {
183  size_t count = 0;
184  for (CChildIterator it(treeCtrl, *this); it; ++it) {
185  if ((*it).GetType() == eProjectFolder)
186  count += static_cast<CProjectFolder&>(*it).CountDisabledItems(treeCtrl);
187  }
188  count += s_CountDisabledItems(*GetData());
189  return count;
190 }
191 
192 void CProjectFolder::OnItemExpandedCollapsed(wxTreeCtrl& treeCtrl)
193 {
194  objects::CProjectFolder& folder = *GetData();
195  folder.SetInfo().SetOpen(treeCtrl.IsExpanded(m_TreeItemId));
196 }
197 
198 static bool s_EditFolder(objects::CFolderInfo& info, const string& title, string reg_path,
199  bool readonly, IFNameValidator& validator)
200 {
201  CFolderEditDlg dlg(NULL, wxID_ANY, ToWxString(title));
202  dlg.SetRegistryPath(reg_path);
203 
204  dlg.SetReadOnly(readonly);
205  dlg.SetNameValidator(&validator);
206 
207  dlg.SetFolderName(ToWxString(info.GetTitle()));
208 
209  string descr;
210  if (info.CanGetComment()) {
211  descr = info.GetComment();
212  }
213 
214  if (info.CanGetAnnot()) {
215  ITERATE (list< CRef<objects::CAnnotdesc> >, it, info.GetAnnot()) {
216  if ((**it).IsComment()) {
217  if (!descr.empty())
218  descr += "\n";
219  descr += (*it)->GetComment();
220  }
221  }
222  }
223 
224  dlg.SetDescr(ToWxString(descr));
225 
226  if(readonly) {
227  dlg.ShowModal();
228  return true;
229  } else {
230  if(dlg.ShowModal() == wxID_OK) {
231  info.SetTitle(ToStdString(dlg.GetFolderName()));
232  descr = ToStdString(dlg.GetDescr());
233 
234  info.SetComment("");
235  info.SetAnnot().clear();
236 
237  list<string> comment;
238  NStr::Split(descr, "\n\r", comment, NStr::fSplit_Tokenize);
239 
240  ITERATE (list<string>, it, comment) {
241  if (!it->empty()) {
242  if (it == comment.begin())
243  info.SetComment(*it);
244  else {
245  CRef<objects::CAnnotdesc> annot(new objects::CAnnotdesc());
246  annot->SetComment(*it);
247  info.SetAnnot().push_back(annot);
248  }
249  }
250  }
251  return true;
252  }
253  return false;
254  }
255 }
256 
257 static const char* kDlgRegPath = "Dialogs.PT.EditFolder";
258 
259 void CProjectFolder::DoNewFolder(wxTreeCtrl& treeCtrl)
260 {
261  CProject* project = GetProject(treeCtrl, *this);
262  if (!project) return;
263 
264  CGBDocument* doc = project->GetData();
265  _ASSERT(doc);
266  if (!doc) return;
267 
268  objects::CProjectFolder& parent_folder = *GetData();
269 
270  CFolderNameValidator<objects::CProjectFolder> validator(&parent_folder, "");
271 
272  CRef<objects::CProjectFolder> new_folder(new objects::CProjectFolder());
273  new_folder->SetInfo().SetTitle("New Folder");
274  new_folder->SetInfo().SetComment("");
275  new_folder->SetInfo().SetOpen(true);
276 
277  if (s_EditFolder(new_folder->SetInfo(), "New Project Folder", kDlgRegPath, false, validator)) {
278  new_folder->SetInfo().SetCreate_date().SetToTime(CTime(CTime::eCurrent));
279  parent_folder.AddChildFolder(*new_folder);
280 
281  const objects::CFolderInfo& info = new_folder->GetInfo();
282  wxString name = ToWxString(info.GetTitle());
283  CProjectFolder* newFolder = new CProjectFolder(new_folder);
284  size_t pos = 0;
285  for (CChildIterator it(treeCtrl, *this); it; ++it) {
286  if ((*it).GetType() != eProjectFolder)
287  break;
288  ++pos;
289  }
290  InsertChildItem(treeCtrl, *newFolder, pos);
291  newFolder->Initialize(treeCtrl, *doc);
292 
293  parent_folder.SetInfo().SetOpen(true);
294  treeCtrl.Expand(m_TreeItemId);
295 
296  doc->SetDirty (true);
297  project->UpdateLabel(treeCtrl);
298  }
299 }
300 
301 bool CProjectFolder::DoProperties(wxTreeCtrl& treeCtrl)
302 {
303  CProject* project = GetProject(treeCtrl, *this);
304  if (!project) return false;
305 
306  CGBDocument* doc = project->GetData();
307  _ASSERT(doc);
308  if (!doc) return false;
309 
310  objects::CProjectFolder& folder = *GetData();
311 
312  objects::CProjectFolder* parent_folder = 0;
313  CProjectFolder* parent = dynamic_cast<CProjectFolder*>(GetParent(treeCtrl));
314  if (parent)
315  parent_folder = parent->GetData();
316 
317  CFolderNameValidator<objects::CProjectFolder> validator(parent_folder, folder.GetInfo().GetTitle());
318  bool readonly = (parent_folder == NULL);
319  if (s_EditFolder(folder.SetInfo(), "Edit Folder", kDlgRegPath, readonly, validator) && !readonly) {
320  treeCtrl.SetItemText(m_TreeItemId, ToWxString(folder.GetInfo().GetTitle()));
321  doc->SetDirty (true);
322  project->UpdateLabel(treeCtrl);
323  return true;
324  }
325  return false;
326 }
327 
328 void CProjectFolder::BeginLabelEdit(wxTreeCtrl& treeCtrl, wxTreeEvent& event)
329 {
330  const CItem* parent_item = GetParent(treeCtrl);
331  if (parent_item == 0 || parent_item->GetType() == eProject)
332  event.Veto();
333 }
334 
335 bool CProjectFolder::EndLabelEdit(wxTreeCtrl& treeCtrl, wxTreeEvent& event)
336 {
337  if (event.IsEditCancelled())
338  return false;
339 
340  event.Veto();
341 
342  CProject* project = GetProject(treeCtrl, *this);
343  if (!project) return false;
344 
345  CGBDocument* doc = project->GetData();
346  _ASSERT(doc);
347  if (!doc) return false;
348 
349  objects::CProjectFolder& pr_folder = *GetData();
350 
351  string new_name = ToStdString(event.GetLabel());
352  string oldName = pr_folder.GetInfo().GetTitle();
353  if (oldName == new_name)
354  return false;
355 
356  objects::CProjectFolder* parent_folder = 0;
357  CProjectFolder* parent = dynamic_cast<CProjectFolder*>(GetParent(treeCtrl));
358  if (parent)
359  parent_folder = parent->GetData();
360  if (!parent_folder)
361  return false;
362 
363  CFolderNameValidator<objects::CProjectFolder> validator(parent_folder, oldName);
364  string err;
365  if (!validator.IsValid(new_name, err)) {
366  NcbiErrorBox(err);
367  }
368  else {
369  pr_folder.SetInfo().SetTitle(new_name);
370  treeCtrl.SetItemText(m_TreeItemId, ToWxString(new_name));
371 
372  doc->SetDirty (true);
373  project->UpdateLabel(treeCtrl);
374  return true;
375  }
376  return false;
377 }
378 
379 bool CProjectFolder::CanDoRemove(wxTreeCtrl& treeCtrl) const
380 {
381  const CItem* parent = GetParent(treeCtrl);
382  return parent != 0 && parent->GetType() == eProjectFolder;
383 }
384 
385 static bool s_DeleteFolder(CGBDocument& doc, objects::CProjectFolder& folder)
386 {
387  vector<objects::CProjectItem*> projItems;
388  for (CTypeIterator<objects::CProjectItem> it(folder); it; ++it) {
389  projItems.push_back(&*it);
390  }
391  if (!projItems.empty())
392  doc.RemoveProjectItems(projItems);
393  doc.SetData().RemoveProjectFolder(folder.GetId());
394  return true;
395 }
396 
397 bool CProjectFolder::DoRemove(wxTreeCtrl& treeCtrl)
398 {
399  CProject* project = GetProject(treeCtrl, *this);
400  if (!project) return false;
401 
402  CItem* parent = GetParent(treeCtrl);
403  if (!parent) return false;
404 
405  CGBDocument* doc = project->GetData();
406  _ASSERT(doc);
407  if (!doc) return false;
408 
409  if (s_DeleteFolder(*doc, *GetData())) {
410  wxTreeItemId toDelete = m_TreeItemId;
411  doc->SetDirty (true);
412  project->UpdateLabel(treeCtrl);
413  treeCtrl.Delete(toDelete);
414  return true;
415  }
416  return false;
417 }
418 
419 bool CProjectFolder::CanCopyToClipboard(wxTreeCtrl& treeCtrl) const
420 {
421  const CItem* parent = GetParent(treeCtrl);
422  return parent != 0 && parent->GetType() == eProjectFolder;
423 }
424 
425 bool CProjectFolder::CanCutToClipboard(wxTreeCtrl& treeCtrl) const
426 {
427  return CanCopyToClipboard(treeCtrl);
428 }
429 
430 bool CProjectFolder::CanPaste(wxTreeCtrl& treeCtrl) const
431 {
432  CProject* project = GetProject(treeCtrl, *this);
433  if (!project) return false;
434  return true;
435 }
436 
437 static CRef<objects::CProjectItem> s_ProjectItemClone(const objects::CProjectItem& item)
438 {
439  CRef<objects::CProjectItem> new_item(new objects::CProjectItem());
440  new_item->SetLabel(item.GetLabel());
441  new_item->SetDescr().assign(item.GetDescr().begin(), item.GetDescr().end());
442 
443  CSerialObject* obj = const_cast<CSerialObject*>(item.GetObject());
444  new_item->SetObject(*obj);
445 
446  if (!item.IsEnabled())
447  new_item->SetDisabled(true);
448 
449  return new_item;
450 }
451 
452 static void s_ProjectFolderClone(const objects::CProjectFolder& folder, CGBDocument& doc, objects::CProjectFolder& dstFolder)
453 {
454  CRef<objects::CProjectFolder> new_folder(new objects::CProjectFolder());
455  objects::CFolderInfo& info = new_folder->SetInfo();
456  info.SetTitle(folder.GetInfo().GetTitle());
457  info.SetComment(folder.GetInfo().GetComment());
458  info.SetCreate_date().SetToTime(CTime(CTime::eCurrent));
459 
460  dstFolder.AddChildFolder(*new_folder);
461 
462  vector<objects::CProjectItem*> items;
463  ITERATE(objects::CProjectFolder::TItems, it, folder.GetItems()) {
465  doc.AddItem(*i, *new_folder);
466  if (i->IsEnabled())
467  items.push_back(i);
468  }
469  doc.AttachProjectItems(items);
470 
471  ITERATE(objects::CProjectFolder::TFolders, it, folder.GetFolders()) {
472  s_ProjectFolderClone(**it, doc, *new_folder);
473  }
474 }
475 
476 static bool s_PasteProjectFolder(CGBDocument& src, objects::CProjectFolder& srcFolder,
477  CGBDocument& dst, objects::CProjectFolder& dstFolder, bool cut)
478 {
479  if (src.GetId() == dst.GetId()) {
480  if (srcFolder.GetId() == dstFolder.GetId()) {
481  string err = "Cannot paste folder \"" + srcFolder.GetInfo().GetTitle() + "\" on itself.";
482  NcbiErrorBox(err);
483  return false;
484  }
485  if (srcFolder.FindChildFolderById(dstFolder.GetId())) {
486  string err = "Cannot paste folder \"" + srcFolder.GetInfo().GetTitle();
487  err += "\". Destination folder is a child of the source folder.";
488  NcbiErrorBox(err);
489  return false;
490  }
491  }
492 
493  if (src.GetId() == dst.GetId() && cut) {
494  CRef<objects::CProjectFolder> f = src.SetData().RemoveProjectFolder(srcFolder.GetId());
495  if (!f) return false;
496  dstFolder.AddChildFolder(*f);
497  } else {
498  s_ProjectFolderClone(srcFolder, dst, dstFolder);
499  if (cut) {
500  s_DeleteFolder(src, srcFolder);
501  }
502  }
503  return true;
504 }
505 
506 bool CProjectFolder::Paste(wxTreeCtrl& treeCtrl, PT::TItems& items, bool move)
507 {
508  if (items.empty()) return false;
509 
510  CProject* project = GetProject(treeCtrl, *this);
511  if (!project) return false;
512 
513  CGBDocument* doc = project->GetData();
514  _ASSERT(doc);
515  if (!doc) return false;
516 
517  objects::CProjectFolder& folder = *GetData();
518 
519  bool modified = false;
520  set<CProject*> modProjects;
521 
523  TDocItems toDelete;
524 
525  NON_CONST_ITERATE(PT::TItems, it, items) {
526  CItem& item = **it;
527  CProject* srcProject = GetProject(treeCtrl, item);
528  if (!srcProject) continue;
529 
530  CGBDocument* srcDoc = srcProject->GetData();
531  _ASSERT(srcDoc);
532  if (!srcDoc) continue;
533 
534  switch(item.GetType()) {
535  case eProjectFolder:
536  {{
537  CProjectFolder& srcFolder = static_cast<CProjectFolder&>(item);
538  if (s_PasteProjectFolder(*srcDoc, *srcFolder.GetData(), *doc, folder, move)) {
539  if (move) {
540  srcDoc->SetDirty(true);
541  modProjects.insert(srcProject);
542  treeCtrl.Delete(srcFolder.GetTreeItemId());
543  }
544  modified = true;
545  }
546  }}
547  break;
548  case eProjectItem:
549  {{
550  CProjectItem& srcItem = static_cast<CProjectItem&>(item);
551  objects::CProjectItem* projItem = srcItem.GetData();
552 
553  if (srcDoc == doc && move) {
554  int itemId = projItem->GetId();
555  objects::CProjectFolder* srcFolder = srcDoc->SetData().FindProjectItemFolder(itemId);
556  if (srcFolder && &folder != srcFolder) {
557  folder.AddChildItem(*projItem);
558  srcFolder->RemoveChildItem(itemId);
559  treeCtrl.Delete(srcItem.GetTreeItemId());
560  modified = true;
561  }
562  } else {
563  CRef<objects::CProjectItem> new_item = s_ProjectItemClone(*projItem);
564  doc->AddItem(*new_item, folder);
565  if (new_item->IsEnabled())
566  doc->AttachProjectItem(new_item);
567 
568  if (move) {
569  toDelete[srcDoc].push_back(projItem);
570  modProjects.insert(srcProject);
571  }
572  modified = true;
573  }
574  }}
575  break;
576  }
577  }
578 
579  ITERATE(TDocItems, it, toDelete) {
580  it->first->RemoveProjectItems(it->second);
581  it->first->SetDirty(true);
582  }
583 
584  if (modified) {
585  treeCtrl.DeleteChildren(m_TreeItemId);
586  Initialize(treeCtrl, *doc);
587 
588  folder.SetInfo().SetOpen(true);
589  treeCtrl.Expand(m_TreeItemId);
590 
591  doc->SetDirty (true);
592  modProjects.insert(project);
593  }
594 
595  ITERATE(set<CProject*>, it, modProjects)
596  if (*it) (*it)->UpdateLabel(treeCtrl);
597 
598  CItem* item = project->GetParent(treeCtrl);
599  if (item && item->GetType() == eWorkspace) {
600  CWorkspace& ws = dynamic_cast<CWorkspace&>(*item);
601  ws.UpdateHiddenItems(treeCtrl);
602  }
603 
604  return modified;
605 }
606 
607 void CProjectFolder::UpdateDisabledItems(wxTreeCtrl& treeCtrl)
608 {
609  CProject* project = GetProject(treeCtrl, *this);
610  if (!project) return;
611 
612  CGBDocument* doc = project->GetData();
613  _ASSERT(doc);
614  if (!doc) return;
615 
616  for (CChildIterator it(treeCtrl, *this); it; ++it) {
617  if ((*it).GetType() == eProjectFolder) {
618  static_cast<CProjectFolder&>(*it).UpdateDisabledItems(treeCtrl);
619  }
620  }
621  objects::CProjectFolder& folder = *GetData();
622 
623  if (s_CountDisabledItems(folder) == 0)
624  return;
625 
626  if (sm_HideDisabledItems) {
627  vector<wxTreeItemId> toDelete;
628  for (CChildIterator it(treeCtrl, *this); it; ++it) {
629  if ((*it).GetType() == eProjectItem) {
630  CProjectItem& item = static_cast<CProjectItem&>(*it);
631  if (!item.GetData()->IsEnabled())
632  toDelete.push_back((*it).GetTreeItemId());
633  }
634  }
635  ITERATE(vector<wxTreeItemId>, it, toDelete)
636  treeCtrl.Delete(*it);
637  } else {
638  if (!folder.CanGetItems())
639  return;
640 
641  objects::CProjectFolder::TItems& items = folder.SetItems();
642  objects::CProjectFolder::TItems::iterator it2 = items.begin();
643 
644  for (CChildIterator it(treeCtrl, *this); it && it2 != items.end(); ++it) {
645  if ((*it).GetType() == eProjectItem) {
646  CProjectItem& item = static_cast<CProjectItem&>(*it);
647  item.SetData(*it2);
648  item.Initialize(treeCtrl, *doc);
649  ++it2;
650  }
651  }
652 
653  for (; it2 != items.end(); ++it2) {
654  objects::CProjectItem& prjItem = **it2;
655  CProjectItem* new_item = new CProjectItem(CRef<objects::CProjectItem>(&prjItem));
656  AppendChildItem(treeCtrl, *new_item);
657  new_item->Initialize(treeCtrl, *doc);
658  }
659  }
660 }
661 
662 void CProjectFolder::UpdateProjectItems(wxTreeCtrl& treeCtrl, CGBDocument& doc)
663 {
664  CProject* project = GetProject(treeCtrl, *this);
665  if (!project) return;
666 
667  objects::CProjectFolder& folder = *GetData();
668 
669  for (CChildIterator it(treeCtrl, *this); it; ++it) {
670  if ((*it).GetType() == eProjectFolder) {
671  static_cast<CProjectFolder&>(*it).UpdateProjectItems(treeCtrl, doc);
672  }
673  }
674 
675  if (!folder.CanGetItems())
676  return;
677 
678  objects::CProjectFolder::TItems& items = folder.SetItems();
679  objects::CProjectFolder::TItems::iterator it2 = items.begin();
680  if (sm_HideDisabledItems) {
681  while (it2 != items.end() && !(*it2)->IsEnabled())
682  ++it2;
683  }
684 
685  CChildIterator it(treeCtrl, *this);
686  for (; it && it2 != items.end(); ++it) {
687  if ((*it).GetType() == eProjectItem) {
688  CProjectItem& item = static_cast<CProjectItem&>(*it);
689  item.SetData(*it2);
690  item.Initialize(treeCtrl, doc);
691  ++it2;
692  if (sm_HideDisabledItems) {
693  while (it2 != items.end() && !(*it2)->IsEnabled())
694  ++it2;
695  }
696  }
697  }
698 
699  vector<wxTreeItemId> toDelete;
700 
701  for (; it; ++it) {
702  if ((*it).GetType() == eProjectItem)
703  toDelete.push_back((*it).GetTreeItemId());
704  }
705 
706  ITERATE(vector<wxTreeItemId>, it, toDelete)
707  treeCtrl.Delete(*it);
708 
709  for (; it2 != items.end();) {
710  objects::CProjectItem& prjItem = **it2;
711  CProjectItem* new_item = new CProjectItem(CRef<objects::CProjectItem>(&prjItem));
712  AppendChildItem(treeCtrl, *new_item);
713  new_item->Initialize(treeCtrl, doc);
714 
715  ++it2;
716  if (sm_HideDisabledItems) {
717  while (it2 != items.end() && !(*it2)->IsEnabled())
718  ++it2;
719  }
720  }
721 }
722 
User-defined methods of the data storage class.
User-defined methods of the data storage class.
virtual void SetRegistryPath(const string &path)
Definition: dialog.cpp:59
void SetDescr(wxString value)
wxString GetFolderName() const
wxString GetDescr() const
void SetReadOnly(bool value)
void SetNameValidator(IFNameValidator *validator)
void SetFolderName(wxString value)
virtual bool IsValid(const string &name, string &err)
CGBDocument.
Definition: document.hpp:113
bool RemoveProjectItems(const vector< objects::CProjectItem * > &items)
Definition: document.cpp:744
void AttachProjectItems(const vector< objects::CProjectItem * > &items)
Definition: document.cpp:788
void AttachProjectItem(objects::CProjectItem *item)
Definition: document.cpp:772
Base class for all serializable objects.
Definition: serialbase.hpp:150
CTime –.
Definition: ncbitime.hpp:296
Template class for iteration on objects of class C.
Definition: iterator.hpp:673
Interface for testing cancellation request in a long lasting operation.
Definition: icanceled.hpp:51
virtual int GetType() const =0
void InsertChildItem(wxTreeCtrl &treeCtrl, CItem &ch_item, size_t pos)
Definition: pt_item.cpp:88
void AppendChildItem(wxTreeCtrl &treeCtrl, CItem &ch_item)
Definition: pt_item.cpp:82
wxTreeItemId GetTreeItemId() const
Definition: pt_item.hpp:62
wxTreeItemId m_TreeItemId
Definition: pt_item.hpp:90
CItem * GetParent(wxTreeCtrl &treeCtrl) const
Definition: pt_item.cpp:74
static CPTIcons & GetInstance()
int GetImageIndex(EIcon icon) const
virtual void DoNewFolder(wxTreeCtrl &treeCtrl)
virtual void BeginLabelEdit(wxTreeCtrl &treeCtrl, wxTreeEvent &event)
virtual bool CanDoRemove(wxTreeCtrl &treeCtrl) const
virtual bool DoProperties(wxTreeCtrl &treeCtrl)
void Initialize(wxTreeCtrl &treeCtrl, CGBDocument &doc)
void UpdateProjectItems(wxTreeCtrl &treeCtrl, CGBDocument &doc)
virtual bool CanPaste(wxTreeCtrl &treeCtrl) const
void ExpandCompacted(wxTreeCtrl &treeCtrl, wxTreeItemId &compacted_node, CGBDocument &doc, IStatusBarService *sb_srv, ICanceled *cancel)
void UpdateDisabledItems(wxTreeCtrl &treeCtrl)
CProjectFolder(const TParent::TDataType &data)
size_t CountDisabledItems(wxTreeCtrl &treeCtrl)
virtual void OnItemExpandedCollapsed(wxTreeCtrl &treeCtrl)
virtual bool CanCopyToClipboard(wxTreeCtrl &treeCtrl) const
virtual bool CanCutToClipboard(wxTreeCtrl &treeCtrl) const
void SetCompacted(bool compacted=true)
virtual bool DoRemove(wxTreeCtrl &treeCtrl)
virtual bool EndLabelEdit(wxTreeCtrl &treeCtrl, wxTreeEvent &event)
virtual bool Paste(wxTreeCtrl &treeCtrl, PT::TItems &items, bool move)
void Initialize(wxTreeCtrl &treeCtrl, CGBDocument &doc)
void UpdateLabel(wxTreeCtrl &treeCtrl)
Definition: pt_project.cpp:89
void UpdateHiddenItems(wxTreeCtrl &treeCtrl)
void SetData(const TData &data)
Definition: pt_item.hpp:137
const TData & GetData() const
Definition: pt_item.hpp:135
Definition: map.hpp:338
Definition: set.hpp:45
iterator_bool insert(const value_type &val)
Definition: set.hpp:149
static const char * str(char *buf, int n)
Definition: stats.c:84
char data[12]
Definition: iconv.c:80
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
Definition: ncbimisc.hpp:815
#define NON_CONST_ITERATE(Type, Var, Cont)
Non constant version of ITERATE macro.
Definition: ncbimisc.hpp:822
#define NULL
Definition: ncbistd.hpp:225
virtual void SetStatusMessage(const string &msg)=0
void NcbiErrorBox(const string &message, const string &title="Error")
specialized Message Box function for reporting critical errors
CRef< C > Ref(C *object)
Helper functions to get CRef<> and CConstRef<> objects.
Definition: ncbiobj.hpp:2015
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
virtual bool IsCanceled(void) const =0
static list< string > & Split(const CTempString str, const CTempString delim, list< string > &arr, TSplitFlags flags=0, vector< SIZE_TYPE > *token_pos=NULL)
Split a string using specified delimiters.
Definition: ncbistr.cpp:3461
@ fSplit_Tokenize
All delimiters are merged and trimmed, to get non-empty tokens only.
Definition: ncbistr.hpp:2508
@ eCurrent
Use current time. See also CCurrentTime.
Definition: ncbitime.hpp:300
int i
static MDB_envinfo info
Definition: mdb_load.c:37
#define wxT(x)
Definition: muParser.cpp:41
CProject * GetProject(wxTreeCtrl &treeCtrl, const CItem &item)
Definition: pt_utils.cpp:77
bool sm_HideDisabledItems
Definition: pt_utils.cpp:57
@ eProject
Definition: pt_item.hpp:118
@ eWorkspace
Definition: pt_item.hpp:117
@ eProjectItem
Definition: pt_item.hpp:120
@ eProjectFolder
Definition: pt_item.hpp:119
vector< CItem * > TItems
Definition: pt_item.hpp:113
double f(double x_, const double &y_)
Definition: njn_root.hpp:188
static unsigned cnt[256]
static bool s_PasteProjectFolder(CGBDocument &src, objects::CProjectFolder &srcFolder, CGBDocument &dst, objects::CProjectFolder &dstFolder, bool cut)
static size_t s_CountDisabledItems(objects::CProjectFolder &folder)
static bool s_DeleteFolder(CGBDocument &doc, objects::CProjectFolder &folder)
static void s_ProjectFolderClone(const objects::CProjectFolder &folder, CGBDocument &doc, objects::CProjectFolder &dstFolder)
static bool s_EditFolder(objects::CFolderInfo &info, const string &title, string reg_path, bool readonly, IFNameValidator &validator)
static CRef< objects::CProjectItem > s_ProjectItemClone(const objects::CProjectItem &item)
static const char * kDlgRegPath
static static static wxID_ANY
#define _ASSERT
wxString ToWxString(const string &s)
Definition: wx_utils.hpp:173
string ToStdString(const wxString &s)
Definition: wx_utils.hpp:161
Modified on Sat May 25 14:20:34 2024 by modify_doxy.py rev. 669887