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

Go to the SVN repository for this file.

1 /* $Id: wnd_layout_registry.cpp 39926 2017-11-27 16:55:21Z katargir $
2  * ===========================================================================
3  *
4  * PUBLIC DOMAIN NOTICE
5  * National Center for Biotechnology Information
6  *
7  * This software/database is a "United States Government Work" under the
8  * terms of the United States Copyright Act. It was written as part of
9  * the author's official duties as a United States Government employee and
10  * thus cannot be copyrighted. This software/database is freely available
11  * to the public for use. The National Library of Medicine and the U.S.
12  * Government have not placed any restriction on its use or reproduction.
13  *
14  * Although all reasonable efforts have been taken to ensure the accuracy
15  * and reliability of the software and data, the NLM and the U.S.
16  * Government do not and cannot warrant the performance or results that
17  * may be obtained by using this software or data. The NLM and the U.S.
18  * Government disclaim all warranties, express or implied, including
19  * warranties of performance, merchantability or fitness for any particular
20  * purpose.
21  *
22  * Please cite the author in any work or product based on this material.
23  *
24  * ===========================================================================
25  *
26  * Authors: Roman Katargin
27  *
28  */
29 
30 #include <ncbi_pch.hpp>
31 
32 #include <corelib/ncbistd.hpp>
33 
37 
40 
41 static const wxChar* kLayoutPath = wxT("<home>/window_layout2.asn");
42 static const char* kWindowLayouts2 = "WindowLayouts2";
43 static const char* kWindowPos = "WindowPos.";
44 
46 {
47 }
48 
50 {
51  static CWndLayoutReg inst;
52  return inst;
53 }
54 
55 CRegistryReadView CWndLayoutReg::GetReadView(const string& section) const
56 {
57  if (!m_Registry)
58  return CRegistryReadView();
59 
60  return m_Registry->GetReadView(kWindowPos + GetVideoId() + "." + section);
61 }
62 
64 {
65  if (!m_Registry)
66  return CRegistryWriteView();
67 
68  return m_Registry->GetWriteView(kWindowPos + GetVideoId() + "." + section);
69 }
70 
72 {
73  wxString path = CSysPath::ResolvePathExisting(wxT("<std>/etc/def_window_layout.asn"));
74  if (!path.empty()) {
75  try {
76  CNcbiIfstream istr(path.fn_str());
77  m_Default.Reset(new CRegistryFile(istr));
78  } NCBI_CATCH("Reading " + string(path.ToUTF8()));
79  }
80 
82  if (!path.empty()) {
83  try {
84  CNcbiIfstream istr(path.fn_str());
85  m_Registry.Reset(new CRegistryFile(istr));
86  } NCBI_CATCH("Reading " + string(path.ToUTF8()));
87  }
88 
89  if (!m_Registry)
91 }
92 
94 {
95  if (!m_Registry)
96  return;
97 
98  wxString path = CSysPath::ResolvePath(kLayoutPath);
99  try {
100  CNcbiOfstream ostr(path.fn_str());
101  m_Registry->Write(ostr);
102  } NCBI_CATCH("Writing " + string(path.ToUTF8()));
103 }
104 
106 {
107  if (m_Default) {
109  CConstRef<CUser_field> field = view.GetField("Default");
110 
111  if (field && field->CanGetData() && field->GetData().IsObject()) {
112  CConstRef<CUser_object> layout(&field->GetData().GetObject());
113  return layout;
114  }
115  }
116 
117  return CConstRef<CUser_object>();
118 }
119 
121 {
122  if (m_Registry) {
125 
126  if (field && field->CanGetData() && field->GetData().IsObject()) {
127  CConstRef<CUser_object> layout(&field->GetData().GetObject());
128  return layout;
129  }
130 
131  LOG_POST(Error << "Failed to load window layout: " << GetVideoId());
132  }
133 
134  return GetDefaultLayout();
135 }
136 
137 void CWndLayoutReg::SetLayout(objects::CUser_object* layout)
138 {
139  if (!m_Registry)
140  return;
141 
143  if (layout) {
144  CRef<CUser_field> field = view.SetField(GetVideoId());
145  field->SetData().SetObject(*layout);
146  }
147  else {
148  view.DeleteField(GetVideoId());
149  }
150 }
151 
153 {
154  if (!m_Registry)
155  return;
158 }
159 
CRegistryReadView GetReadView(const string &section) const
Definition: reg_file.cpp:65
void Write(CNcbiOstream &istr) const
Definition: reg_file.cpp:457
CRegistryWriteView GetWriteView(const string &section)
Definition: reg_file.cpp:70
class CRegistryReadView provides a nested hierarchical view at a particular key.
Definition: reg_view.hpp:58
CConstRef< objects::CUser_field > GetField(const string &key) const
provide raw field access
Definition: reg_view.cpp:104
CRef< objects::CUser_field > SetField(const string &key)
provide raw field access
Definition: reg_view.cpp:502
bool DeleteField(const string &key)
delete the specified field (and any of its subfields) from this view and from its registry.
Definition: reg_view.cpp:523
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
CConstRef< objects::CUser_object > GetDefaultLayout()
CRef< CRegistryFile > m_Registry
CConstRef< objects::CUser_object > GetLayout()
CRegistryWriteView GetWriteView(const string &section)
void SetLayout(objects::CUser_object *layout)
CRegistryReadView GetReadView(const string &section) const
CRef< CRegistryFile > m_Default
static CWndLayoutReg & GetInstance()
Include a standard set of the NCBI C++ Toolkit most basic headers.
#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
#define NCBI_CATCH(message)
Catch CExceptions as well This macro is deprecated - use *_X or *_XX variant instead of it.
Definition: ncbiexpt.hpp:580
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
IO_PREFIX::ofstream CNcbiOfstream
Portable alias for ofstream.
Definition: ncbistre.hpp:500
IO_PREFIX::ifstream CNcbiIfstream
Portable alias for ifstream.
Definition: ncbistre.hpp:439
const TData & GetData(void) const
Get the Data member data.
bool CanGetData(void) const
Check if it is safe to call GetData method.
const TObject & GetObject(void) const
Get the variant data.
void SetData(TData &value)
Assign a value to Data data member.
bool IsObject(void) const
Check if variant Object is selected.
#define wxT(x)
Definition: muParser.cpp:41
USING_SCOPE(objects)
static const wxChar * kLayoutPath
static const char * kWindowPos
static const char * kWindowLayouts2
string GetVideoId()
Returns id of video configuration to be used for saving settings.
Definition: wx_utils.cpp:224
Modified on Thu May 02 14:35:51 2024 by modify_doxy.py rev. 669887