diff --git a/common/tool/tool_base.cpp b/common/tool/tool_base.cpp index 8615c93d36..f9191d52d4 100644 --- a/common/tool/tool_base.cpp +++ b/common/tool/tool_base.cpp @@ -58,20 +58,9 @@ void TOOL_BASE::attachManager( TOOL_MANAGER* aManager ) } -TOOL_SETTINGS::TOOL_SETTINGS( TOOL_BASE* aTool ) +TOOL_SETTINGS::TOOL_SETTINGS( TOOL_BASE* aTool ) : + m_tool( aTool ) { - m_tool = aTool; - - if( !aTool ) - { - m_config = NULL; - return; - } - - // fixme: make independent of pcbnew (post-stable) - PCB_EDIT_FRAME* frame = aTool->getEditFrame(); - - m_config = frame->GetSettings(); } @@ -93,3 +82,16 @@ wxString TOOL_SETTINGS::getKeyName( const wxString& aEntryName ) const key += aEntryName; return key; } + + +wxConfigBase* TOOL_SETTINGS::getConfigBase() const +{ + if( !m_tool ) + return NULL; + + // fixme: make independent of pcbnew (post-stable) + if( PCB_EDIT_FRAME* frame = m_tool->getEditFrame() ) + return frame->GetSettings(); + + return NULL; +} diff --git a/include/tool/tool_settings.h b/include/tool/tool_settings.h index 393afb0a79..64d26126c3 100644 --- a/include/tool/tool_settings.h +++ b/include/tool/tool_settings.h @@ -38,34 +38,41 @@ class TOOL_BASE; class TOOL_SETTINGS { public: - TOOL_SETTINGS ( TOOL_BASE* aTool = NULL ); - ~TOOL_SETTINGS (); + TOOL_SETTINGS( TOOL_BASE* aTool = NULL ); + ~TOOL_SETTINGS(); - template + template T Get( const wxString& aName, T aDefaultValue ) const { - if( !m_config ) + wxConfigBase* config = getConfigBase(); + + if( !config ) return aDefaultValue; T tmp = aDefaultValue; - m_config->Read( getKeyName( aName ), &tmp ); + config->Read( getKeyName( aName ), &tmp ); return tmp; } - template + template void Set( const wxString& aName, const T &aValue ) { - if( !m_config ) + wxConfigBase* config = getConfigBase(); + + if( !config ) return; - m_config->Write( getKeyName( aName ), aValue ); + config->Write( getKeyName( aName ), aValue ); } private: wxString getKeyName( const wxString& aEntryName ) const; - wxConfigBase* m_config; + ///> Returns pointer to currently used wxConfigBase. It might be NULL, if there is no + ///> TOOL_BASE assigned. + wxConfigBase* getConfigBase() const; + TOOL_BASE* m_tool; };