You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

128 lines
3.5 KiB

8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2015 CERN
  5. * @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License
  9. * as published by the Free Software Foundation; either version 2
  10. * of the License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, you may find one here:
  19. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  20. * or you may search the http://www.gnu.org website for the version 2 license,
  21. * or you may write to the Free Software Foundation, Inc.,
  22. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  23. */
  24. #ifndef __SETTINGS_H
  25. #define __SETTINGS_H
  26. #include <wx/confbase.h>
  27. #include <config_params.h>
  28. /**
  29. * Class TOOL_SETTINGS
  30. *
  31. * Manages persistent settings for a tool (just a simple wrapper to wxConfigBase)
  32. */
  33. class SETTINGS
  34. {
  35. public:
  36. SETTINGS()
  37. {}
  38. virtual ~SETTINGS()
  39. {}
  40. /** Set a prefix that will be prepent to the keywords when adding a setting in list
  41. * @param aPrefix is the string to prepend to the keywords
  42. */
  43. void SetConfigPrefix( const wxString& aPrefix )
  44. {
  45. m_prefix = aPrefix;
  46. }
  47. /** @return the current prefix
  48. */
  49. const wxString& GetConfigPrefix()
  50. {
  51. return m_prefix;
  52. }
  53. virtual void Load( wxConfigBase *aConfig );
  54. virtual void Save( wxConfigBase *aConfig );
  55. #if 0
  56. template<class T>
  57. T Get( const wxString& aName, T aDefaultValue ) const
  58. {
  59. wxConfigBase* config = getConfigBase();
  60. if( !config )
  61. return aDefaultValue;
  62. T tmp = aDefaultValue;
  63. config->Read( getKeyName( aName ), &tmp );
  64. return tmp;
  65. }
  66. template<class T>
  67. void Set( const wxString& aName, const T &aValue )
  68. {
  69. wxConfigBase* config = getConfigBase();
  70. if( !config )
  71. return;
  72. config->Write( getKeyName( aName ), aValue );
  73. }
  74. #endif
  75. void Add( const wxString& name, int* aPtr, int aDefaultValue )
  76. {
  77. m_params.push_back( new PARAM_CFG_INT ( m_prefix+name, aPtr, aDefaultValue ) );
  78. }
  79. void Add( const wxString& name, bool* aPtr, bool aDefaultValue )
  80. {
  81. m_params.push_back( new PARAM_CFG_BOOL ( m_prefix+name, aPtr, aDefaultValue ) );
  82. }
  83. void Add( const wxString& name, KIGFX::COLOR4D* aPtr, KIGFX::COLOR4D aDefaultValue )
  84. {
  85. m_params.push_back( new PARAM_CFG_SETCOLOR ( m_prefix+name, aPtr, aDefaultValue ) );
  86. }
  87. void Add( const wxString& name, KIGFX::COLOR4D* aPtr, EDA_COLOR_T aDefaultValue )
  88. {
  89. m_params.push_back( new PARAM_CFG_SETCOLOR ( m_prefix+name, aPtr, aDefaultValue ) );
  90. }
  91. protected:
  92. virtual wxString getKeyName( const wxString& aEntryName ) const
  93. {
  94. return aEntryName;
  95. }
  96. private:
  97. wxString m_prefix;
  98. PARAM_CFG_ARRAY m_params;
  99. };
  100. #endif