git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@34794
c3d73ce0-8a6f-49c7-b76d-
6d57e0e08775
// the same as SetPath("/")
void SetRootPath();
// the same as SetPath("/")
void SetRootPath();
+ // real SetPath() implementation, returns true if path could be set or false
+ // if path doesn't exist and createMissingComponents == false
+ bool DoSetPath(const wxString& strPath, bool createMissingComponents);
+
// set/test the dirty flag
void SetDirty() { m_isDirty = true; }
void ResetDirty() { m_isDirty = false; }
// set/test the dirty flag
void SetDirty() { m_isDirty = true; }
void ResetDirty() { m_isDirty = false; }
m_pCurrentGroup = m_pRootGroup;
}
m_pCurrentGroup = m_pRootGroup;
}
-void wxFileConfig::SetPath(const wxString& strPath)
+bool
+wxFileConfig::DoSetPath(const wxString& strPath, bool createMissingComponents)
{
wxArrayString aParts;
if ( strPath.empty() ) {
SetRootPath();
{
wxArrayString aParts;
if ( strPath.empty() ) {
SetRootPath();
}
if ( strPath[0] == wxCONFIG_PATH_SEPARATOR ) {
}
if ( strPath[0] == wxCONFIG_PATH_SEPARATOR ) {
for ( n = 0; n < aParts.Count(); n++ ) {
wxFileConfigGroup *pNextGroup = m_pCurrentGroup->FindSubgroup(aParts[n]);
if ( pNextGroup == NULL )
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]);
pNextGroup = m_pCurrentGroup->AddSubgroup(aParts[n]);
m_pCurrentGroup = pNextGroup;
}
m_pCurrentGroup = pNextGroup;
}
for ( n = 0; n < aParts.Count(); n++ ) {
m_strPath << wxCONFIG_PATH_SEPARATOR << aParts[n];
}
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 */);
}
// ----------------------------------------------------------------------------
}
// ----------------------------------------------------------------------------
bool wxFileConfig::HasGroup(const wxString& strName) 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();
+
+ wxFileConfig *self = wx_const_cast(wxFileConfig *, this);
+ const bool
+ rc = self->DoSetPath(strName, false /* don't create missing components */);
+
+ self->SetPath(pathOld);
- wxFileConfigGroup *pGroup = m_pCurrentGroup->FindSubgroup(path.Name());
- return pGroup != NULL;
}
bool wxFileConfig::HasEntry(const wxString& strName) const
}
bool wxFileConfig::HasEntry(const wxString& strName) const