From 41f3015283f5171b56432d337394e34b6eb03c67 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 14 Jul 2006 22:08:43 +0000 Subject: [PATCH] fix the bug with the current path being restored if it was under the group being deleted with DeleteGroup(); clarify what happens in this case in the docs git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@40095 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/latex/wx/config.tex | 5 ++++- src/common/config.cpp | 15 +++++++++++++++ src/common/fileconf.cpp | 2 ++ src/msw/regconf.cpp | 16 +++++++++++++--- 4 files changed, 34 insertions(+), 4 deletions(-) diff --git a/docs/latex/wx/config.tex b/docs/latex/wx/config.tex index b2969399f7..3700a8ec72 100644 --- a/docs/latex/wx/config.tex +++ b/docs/latex/wx/config.tex @@ -454,7 +454,10 @@ in it and the second parameter is true. \func{bool}{DeleteGroup}{\param{const wxString\& }{ key}} -Delete the group (with all subgroups) +Delete the group (with all subgroups). If the current path is under the group +being deleted it is changed to its deepest still existing component. E.g. if +the current path is \texttt{/A/B/C/D} and the group \texttt{C} is deleted the +path becomes \texttt{/A/B}. \membersection{wxConfigBase::Exists}\label{wxconfigbaseexists} diff --git a/src/common/config.cpp b/src/common/config.cpp index 9f49fa0783..4b509a7fc0 100644 --- a/src/common/config.cpp +++ b/src/common/config.cpp @@ -274,6 +274,21 @@ wxConfigPathChanger::wxConfigPathChanger(const wxConfigBase *pContainer, } } +void wxConfigPathChanger::UpdateIfDeleted() +{ + // we don't have to do anything at all if we didn't change the path + if ( !m_bChanged ) + return; + + // find the deepest still existing parent path of the original path + while ( !m_pContainer->HasGroup(m_strOldPath) ) + { + m_strOldPath = m_strOldPath.BeforeLast(wxCONFIG_PATH_SEPARATOR); + if ( m_strOldPath.empty() ) + m_strOldPath = wxCONFIG_PATH_SEPARATOR; + } +} + wxConfigPathChanger::~wxConfigPathChanger() { // only restore path if it was changed diff --git a/src/common/fileconf.cpp b/src/common/fileconf.cpp index fae2059278..8078b6f5d4 100644 --- a/src/common/fileconf.cpp +++ b/src/common/fileconf.cpp @@ -1145,6 +1145,8 @@ bool wxFileConfig::DeleteGroup(const wxString& key) if ( !m_pCurrentGroup->DeleteSubgroupByName(path.Name()) ) return false; + path.UpdateIfDeleted(); + SetDirty(); return true; diff --git a/src/msw/regconf.cpp b/src/msw/regconf.cpp index 4c9d9e5fb7..1777569b88 100644 --- a/src/msw/regconf.cpp +++ b/src/msw/regconf.cpp @@ -699,7 +699,18 @@ bool wxRegConfig::DeleteGroup(const wxString& key) { wxConfigPathChanger path(this, key); - return m_keyLocal.Exists() ? LocalKey().DeleteKey(path.Name()) : true; + if ( !m_keyLocal.Exists() ) + { + // nothing to do + return true; + } + + if ( !LocalKey().DeleteKey(path.Name()) ) + return false; + + path.UpdateIfDeleted(); + + return true; } bool wxRegConfig::DeleteAll() @@ -717,5 +728,4 @@ bool wxRegConfig::DeleteAll() return bOk; } -#endif - // wxUSE_CONFIG +#endif // wxUSE_CONFIG -- 2.45.2