X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/7351db919a9dab89c951406bee859b5f3bb53f7a..7533ba252ba505f159f504a34877793fb32d8bca:/src/common/fileconf.cpp diff --git a/src/common/fileconf.cpp b/src/common/fileconf.cpp index e26936b7a5..c84e60de07 100644 --- a/src/common/fileconf.cpp +++ b/src/common/fileconf.cpp @@ -746,13 +746,14 @@ void wxFileConfig::SetRootPath() m_pCurrentGroup = m_pRootGroup; } -void wxFileConfig::SetPath(const wxString& strPath) +bool +wxFileConfig::DoSetPath(const wxString& strPath, bool createMissingComponents) { wxArrayString aParts; if ( strPath.empty() ) { SetRootPath(); - return; + return true; } if ( strPath[0] == wxCONFIG_PATH_SEPARATOR ) { @@ -772,7 +773,13 @@ void wxFileConfig::SetPath(const wxString& strPath) for ( n = 0; n < aParts.Count(); n++ ) { wxFileConfigGroup *pNextGroup = m_pCurrentGroup->FindSubgroup(aParts[n]); if ( pNextGroup == NULL ) + { + if ( !createMissingComponents ) + return false; + pNextGroup = m_pCurrentGroup->AddSubgroup(aParts[n]); + } + m_pCurrentGroup = pNextGroup; } @@ -781,6 +788,13 @@ void wxFileConfig::SetPath(const wxString& strPath) for ( n = 0; n < aParts.Count(); n++ ) { m_strPath << wxCONFIG_PATH_SEPARATOR << aParts[n]; } + + return true; +} + +void wxFileConfig::SetPath(const wxString& strPath) +{ + DoSetPath(strPath, true /* create missing path components */); } // ---------------------------------------------------------------------------- @@ -857,10 +871,20 @@ size_t wxFileConfig::GetNumberOfGroups(bool bRecursive) const bool wxFileConfig::HasGroup(const wxString& strName) const { - wxConfigPathChanger path(this, strName); + // special case: DoSetPath("") does work as it's equivalent to DoSetPath("/") + // but there is no group with empty name so treat this separately + if ( strName.empty() ) + return false; + + const wxString pathOld = GetPath(); - wxFileConfigGroup *pGroup = m_pCurrentGroup->FindSubgroup(path.Name()); - return pGroup != NULL; + wxFileConfig *self = wx_const_cast(wxFileConfig *, this); + const bool + rc = self->DoSetPath(strName, false /* don't create missing components */); + + self->SetPath(pathOld); + + return rc; } bool wxFileConfig::HasEntry(const wxString& strName) const @@ -1098,12 +1122,13 @@ bool wxFileConfig::DeleteEntry(const wxString& key, bool bGroupIfEmptyAlso) if ( !m_pCurrentGroup->DeleteEntry(path.Name()) ) return false; + SetDirty(); + if ( bGroupIfEmptyAlso && m_pCurrentGroup->IsEmpty() ) { if ( m_pCurrentGroup != m_pRootGroup ) { wxFileConfigGroup *pGroup = m_pCurrentGroup; SetPath(wxT("..")); // changes m_pCurrentGroup! - if ( m_pCurrentGroup->DeleteSubgroupByName(pGroup->Name()) ) - SetDirty(); + m_pCurrentGroup->DeleteSubgroupByName(pGroup->Name()); } //else: never delete the root group } @@ -1326,8 +1351,11 @@ wxFileConfigGroup::~wxFileConfigGroup() void wxFileConfigGroup::SetLine(wxFileConfigLineList *pLine) { - // shouldn't be called twice unless we are resetting the line - wxASSERT( m_pLine == 0 || pLine == 0 ); + // for a normal (i.e. not root) group this method shouldn't be called twice + // unless we are resetting the line + wxASSERT_MSG( !m_pParent || !m_pLine || !pLine, + _T("changing line for a non-root group?") ); + m_pLine = pLine; }