TOOL_SETTINGS acquires wxConfigBase each time it is used.
This commit is contained in:
parent
5cd464f244
commit
9ecc593aac
|
@ -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<PCB_EDIT_FRAME>();
|
||||
|
||||
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<PCB_EDIT_FRAME>() )
|
||||
return frame->GetSettings();
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
@ -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 <class T>
|
||||
template<class T>
|
||||
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 <class T>
|
||||
template<class T>
|
||||
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;
|
||||
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue