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

Go to the SVN repository for this file.

1 /* $Id: quick_launch_list.cpp 39666 2017-10-25 16:01:13Z 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 
34 
36 #include <wx/menu.h>
37 
38 #include <set>
39 
41 
42 static const string kQLPath = "Workbench.Tools.QuickLaunch";
43 
45 : m_ToolList(10)
46 {
47 }
48 
50 {
52  if (!s_Instance) {
53  s_Instance.Reset(new CQuickLaunchList());
54  s_Instance->x_Load();
55  }
56  return *s_Instance;
57 }
58 
59 string CQuickLaunchList::GetItemPath(const string& item) const
60 {
61  return kQLPath + ".Entries." + item;
62 }
63 
64 void CQuickLaunchList::UpdateMenu(wxMenu& menu, int cmdStart, int cmdEnd, size_t pos)
65 {
66  if (IsEmpty())
67  return;
68 
69  wxMenu* subMenu = new wxMenu();
70  const list<string>& items = m_ToolList.GetItems();
71  int cmd = cmdStart;
72  ITERATE(list<string>, it, items) {
73  subMenu->Append(cmd, ToWxString(*it));
74  if (cmd == cmdEnd)
75  break;
76  ++cmd;
77  }
78 
79  if (pos == (size_t)-1)
80  pos = menu.GetMenuItemCount();
81 
82  wxMenuItem* item = wxMenuItem::New(&menu, wxID_ANY,
83  wxT("Quick Launch"), wxEmptyString, wxITEM_NORMAL, subMenu);
84  menu.Insert(pos, item);
85 }
86 
88 {
90 }
91 
93 {
95 
96  list<string> items = m_ToolList.GetItems();
97  gui_reg.Set(kQLPath + ".List", items);
98 
99  set<string> itemsSet;
100  std::copy(items.begin(), items.end(), inserter(itemsSet, itemsSet.begin()));
101 
102  CRegistryReadView view = gui_reg.GetReadView(kQLPath + ".Entries");
104  view.GetTopKeys(entries);
106  const CRegistryReadView::SKeyInfo& key = *it;
107  if (itemsSet.find(key.key) == itemsSet.end())
108  gui_reg.DeleteField(kQLPath + ".Entries." + key.key);
109  }
110 }
111 
113 {
114  return m_ToolList.GetItems().empty();
115 }
116 
117 const list<string>& CQuickLaunchList::GetItems() const
118 {
119  return m_ToolList.GetItems();
120 }
121 
122 void CQuickLaunchList::AddItem(const string& item)
123 {
124  m_ToolList.AddItem(item);
125  x_Save();
126 }
127 
128 void CQuickLaunchList::RemoveItem(const string& item)
129 {
130  m_ToolList.RemoveItem(item);
131  x_Save();
132 }
133 
void GetStringList(const string &key, list< string > &val) const
Definition: registry.cpp:168
static CGuiRegistry & GetInstance()
access the application-wide singleton
Definition: registry.cpp:400
void Set(const string &key, int val)
set specific values
Definition: registry.cpp:178
CRegistryReadView GetReadView(const string &section) const
get a read-only view at a particular level.
Definition: registry.cpp:428
bool DeleteField(const string &key)
delete the specified field (and any of its subfields).
Definition: registry.cpp:333
const TItems & GetItems() const
Definition: mru_list.hpp:96
void SetItems(const TItems &items)
Definition: mru_list.hpp:110
void AddItem(T item)
Definition: mru_list.hpp:60
void RemoveItem(T item)
Definition: mru_list.hpp:74
CQuickLaunchList.
CMRUList< string > m_ToolList
const list< string > & GetItems() const
static CQuickLaunchList & GetInstance()
void AddItem(const string &item)
void RemoveItem(const string &item)
string GetItemPath(const string &item) const
void UpdateMenu(wxMenu &menu, int cmdStart, int cmdEnd, size_t pos=(size_t) -1)
CRef –.
Definition: ncbiobj.hpp:618
class CRegistryReadView provides a nested hierarchical view at a particular key.
Definition: reg_view.hpp:58
list< SKeyInfo > TKeys
retrieve information about all keys in the registry
Definition: reg_view.hpp:68
void GetTopKeys(TKeys &keys) const
Retrieve information about the top level keys in this view.
Definition: reg_view.cpp:278
const_iterator begin() const
Definition: set.hpp:135
const_iterator find(const key_type &key) const
Definition: set.hpp:137
const_iterator end() const
Definition: set.hpp:136
static CS_COMMAND * cmd
Definition: ct_dynamic.c:26
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
Definition: ncbimisc.hpp:815
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
static CSafeStatic< CMetaRegistry > s_Instance
Definition: metareg.cpp:59
#define wxT(x)
Definition: muParser.cpp:41
const struct ncbi::grid::netcache::search::fields::KEY key
void copy(Njn::Matrix< S > *matrix_, const Njn::Matrix< T > &matrix0_)
Definition: njn_matrix.hpp:613
static const string kQLPath
static static static wxID_ANY
static wxAcceleratorEntry entries[3]
wxString ToWxString(const string &s)
Definition: wx_utils.hpp:173
Modified on Fri Sep 20 14:57:44 2024 by modify_doxy.py rev. 669887