Code::Blocks  SVN r11506
cbcolourmanager.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of the Code::Blocks IDE and licensed under the GNU Lesser General Public License, version 3
3  * http://www.gnu.org/licenses/lgpl-3.0.html
4  *
5  * $Revision: 9263 $
6  * $Id: cbcolourmanager.cpp 9263 2013-08-17 09:20:28Z mortenmacfly $
7  * $HeadURL: https://svn.code.sf.net/p/codeblocks/code/trunk/src/sdk/cbcolourmanager.cpp $
8  */
9 
10 #include "sdk_precomp.h"
11 
12 #ifndef CB_PRECOMP
13  #include "configmanager.h"
14 #endif // CB_PRECOMP
15 
16 #include "cbcolourmanager.h"
17 
18 template<> ColourManager* Mgr<ColourManager>::instance = nullptr;
19 template<> bool Mgr<ColourManager>::isShutdown = false;
20 
22 {
23  ConfigManager *config = Manager::Get()->GetConfigManager(wxT("colours"));
24  const wxArrayString &colours = config->EnumerateKeys(wxT("list"));
25  for (size_t ii = 0; ii < colours.GetCount(); ++ii)
26  {
27  const wxString &id = colours[ii].Lower();
28  const wxColour &colour = config->ReadColour(wxT("list/") + id);
29 
30  ColourDefMap::iterator it = m_colours.find(id);
31  if (it != m_colours.end())
32  it->second.value = colour;
33  else
34  {
35  ColourDef def;
36  def.value = def.defaultValue = colour;
37  m_colours[id] = def;
38  }
39  }
40 }
41 
43 {
44  ConfigManager *config = Manager::Get()->GetConfigManager(wxT("colours"));
45  for (ColourDefMap::const_iterator it = m_colours.begin(); it != m_colours.end(); ++it)
46  {
47  if (it->second.value != it->second.defaultValue)
48  config->Write(wxT("list/") + it->first, it->second.value);
49  else
50  config->UnSet(wxT("list/") + it->first);
51  }
52 }
53 
54 void ColourManager::RegisterColour(const wxString &category, const wxString &name,
55  const wxString &id, const wxColour &defaultColour)
56 {
57  wxString lowerID = id.Lower();
58  ColourDefMap::iterator it = m_colours.find(lowerID);
59  if (it != m_colours.end())
60  {
61  it->second.name = name;
62  it->second.category = category;
63  it->second.defaultValue = defaultColour;
64  }
65  else
66  {
67  ColourDef def;
68  def.name = name;
69  def.category = category;
70  def.value = def.defaultValue = defaultColour;
71  m_colours[lowerID] = def;
72  }
73 }
74 
76 {
77  ColourDefMap::const_iterator it = m_colours.find(id);
78  return it != m_colours.end() ? it->second.value : *wxBLACK;
79 }
80 
81 void ColourManager::SetColour(const wxString &id, const wxColour &colour)
82 {
83  ColourDefMap::iterator it = m_colours.find(id);
84  if (it != m_colours.end())
85  it->second.value = colour;
86 }
87 
89 {
90  return m_colours;
91 }
wxColour * wxBLACK
ConfigManager * GetConfigManager(const wxString &name_space) const
Definition: manager.cpp:474
static Manager * Get()
Use Manager::Get() to get a pointer to its instance Manager::Get() is guaranteed to never return an i...
Definition: manager.cpp:182
wxString Lower() const
void RegisterColour(const wxString &category, const wxString &name, const wxString &id, const wxColour &defaultColour)
wxColour ReadColour(const wxString &name, const wxColour &defaultVal= *wxBLACK)
#define wxT(string)
void UnSet(const wxString &name)
void Write(const wxString &name, const wxString &value, bool ignoreEmpty=false)
wxColour GetColour(const wxString &id) const
ColourDefMap m_colours
Definition: manager.h:183
const ColourDefMap & GetColourDefinitions() const
std::map< wxString, ColourDef > ColourDefMap
size_t GetCount() const
void SetColour(const wxString &id, const wxColour &colour)
wxArrayString EnumerateKeys(const wxString &path)