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

Go to the SVN repository for this file.

1 /* $Id: cmd_change_projectitem.cpp 43100 2019-05-14 19:24:34Z 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: Andrea Asztalos, based on a file by Roman Katargin
27  *
28  * File Description:
29  *
30  */
31 
32 #include <ncbi_pch.hpp>
33 #include <objects/general/Date.hpp>
34 
39 
42 
44 {
45  if (!m_OldItem || !m_Doc || !m_NewItem || !m_Workbench)
46  return;
47 
49  if (!srv) return;
50 
51  vector<CIRef<IProjectView>> views;
52  srv->FindViews(views, *m_OldItem->GetObject());
53  set<string> view_names;
54  for (auto& it : views) {
55  string viewType = it->GetLabel(IProjectView::eType);
56  if (!viewType.empty()) {
57  view_names.insert(viewType);
58  }
59  }
60 
61  bool removed = m_Doc->RemoveProjectItem(m_OldItem);
62  if (!removed) return;
63 
64  CProjectFolder& data_folder = m_Doc->SetData();
65  m_Doc->AddItem(*m_NewItem, data_folder);
67 
68  m_Doc->SetModifiedDate(CTime(CTime::eCurrent));
69  m_Doc->SetDirty(true);
71 
72  const CSerialObject* so = m_NewItem->GetObject();
73  if (so && !view_names.empty()) {
75  SConstScopedObject object(so, m_Doc->GetScope());
76  for (auto& it : view_names) {
77  COpenViewTask* task = new COpenViewTask(m_Workbench, it, object, 0, false);
78  taskService->AddTask(*task);
79  }
80  }
81 
83 }
84 
86 {
87  Execute();
88 }
89 
91 {
92  return "Change ProjectItem\n";
93 }
94 
CAppTaskService - Application Task Service.
CRef< objects::CProjectItem > m_NewItem
CRef< objects::CProjectItem > m_OldItem
virtual void Unexecute()
Undo (opposite to Execute())
virtual void Execute()
Do the editing action.
void ProjectItemsChanged()
Definition: document.cpp:239
bool RemoveProjectItem(objects::CProjectItem *item)
Definition: document.cpp:736
void AttachProjectItem(objects::CProjectItem *item)
Definition: document.cpp:772
CProjectService - a service providing API for operations with Workspaces and Projects.
Base class for all serializable objects.
Definition: serialbase.hpp:150
CTime –.
Definition: ncbitime.hpp:296
iterator_bool insert(const value_type &val)
Definition: set.hpp:149
bool empty() const
Definition: set.hpp:133
USING_SCOPE(objects)
void swap(NCBI_NS_NCBI::pair_base_member< T1, T2 > &pair1, NCBI_NS_NCBI::pair_base_member< T1, T2 > &pair2)
Definition: ncbimisc.hpp:1508
CIRef< T > GetServiceByType()
retrieves a typed reference to a service, the name of C++ type is used as the name of the service.
Definition: service.hpp:91
void AddTask(IAppTask &task)
Add a task to the queue.
TObjectType & GetObject(void)
Get object.
Definition: ncbiobj.hpp:1011
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
@ eCurrent
Use current time. See also CCurrentTime.
Definition: ncbitime.hpp:300
Modified on Fri Dec 01 04:48:16 2023 by modify_doxy.py rev. 669887