fixed problem of deleting an entry added to an initially empty root group
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@19948 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
parent
3908fe9b00
commit
128e0251fe
@ -250,8 +250,9 @@ public:
|
|||||||
wxFileConfigLineList *GetLastGroupLine(); // after which the next group starts
|
wxFileConfigLineList *GetLastGroupLine(); // after which the next group starts
|
||||||
|
|
||||||
// called by entries/subgroups when they're created/deleted
|
// called by entries/subgroups when they're created/deleted
|
||||||
void SetLastEntry(wxFileConfigEntry *pEntry) { m_pLastEntry = pEntry; }
|
void SetLastEntry(wxFileConfigEntry *pEntry);
|
||||||
void SetLastGroup(wxFileConfigGroup *pGroup) { m_pLastGroup = pGroup; }
|
void SetLastGroup(wxFileConfigGroup *pGroup)
|
||||||
|
{ m_pLastGroup = pGroup; }
|
||||||
|
|
||||||
DECLARE_NO_COPY_CLASS(wxFileConfigGroup)
|
DECLARE_NO_COPY_CLASS(wxFileConfigGroup)
|
||||||
};
|
};
|
||||||
@ -1132,7 +1133,6 @@ wxFileConfigLineList *wxFileConfig::LineListAppend(const wxString& str)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// insert a new line after the given one or in the very beginning if !pLine
|
// insert a new line after the given one or in the very beginning if !pLine
|
||||||
|
|
||||||
wxFileConfigLineList *wxFileConfig::LineListInsert(const wxString& str,
|
wxFileConfigLineList *wxFileConfig::LineListInsert(const wxString& str,
|
||||||
wxFileConfigLineList *pLine)
|
wxFileConfigLineList *pLine)
|
||||||
{
|
{
|
||||||
@ -1311,7 +1311,7 @@ wxFileConfigLineList *wxFileConfigGroup::GetGroupLine()
|
|||||||
_T(" GetGroupLine() for Group '%s'"),
|
_T(" GetGroupLine() for Group '%s'"),
|
||||||
Name().c_str() );
|
Name().c_str() );
|
||||||
|
|
||||||
if ( m_pLine == 0 )
|
if ( !m_pLine )
|
||||||
{
|
{
|
||||||
wxLogTrace( _T("wxFileConfig"),
|
wxLogTrace( _T("wxFileConfig"),
|
||||||
_T(" Getting Line item pointer") );
|
_T(" Getting Line item pointer") );
|
||||||
@ -1319,8 +1319,7 @@ wxFileConfigLineList *wxFileConfigGroup::GetGroupLine()
|
|||||||
wxFileConfigGroup *pParent = Parent();
|
wxFileConfigGroup *pParent = Parent();
|
||||||
|
|
||||||
// this group wasn't present in local config file, add it now
|
// this group wasn't present in local config file, add it now
|
||||||
|
if ( pParent )
|
||||||
if ( pParent != 0 )
|
|
||||||
{
|
{
|
||||||
wxLogTrace( _T("wxFileConfig"),
|
wxLogTrace( _T("wxFileConfig"),
|
||||||
_T(" checking parent '%s'"),
|
_T(" checking parent '%s'"),
|
||||||
@ -1328,18 +1327,16 @@ wxFileConfigLineList *wxFileConfigGroup::GetGroupLine()
|
|||||||
|
|
||||||
wxString strFullName;
|
wxString strFullName;
|
||||||
|
|
||||||
strFullName << wxT("[") // +1: no '/'
|
// add 1 to the name because we don't want to start with '/'
|
||||||
|
strFullName << wxT("[")
|
||||||
<< FilterOutEntryName(GetFullName().c_str() + 1)
|
<< FilterOutEntryName(GetFullName().c_str() + 1)
|
||||||
<< wxT("]");
|
<< wxT("]");
|
||||||
m_pLine = m_pConfig->LineListInsert(strFullName,
|
m_pLine = m_pConfig->LineListInsert(strFullName,
|
||||||
pParent->GetLastGroupLine());
|
pParent->GetLastGroupLine());
|
||||||
pParent->SetLastGroup(this); // we're surely after all the others
|
pParent->SetLastGroup(this); // we're surely after all the others
|
||||||
}
|
}
|
||||||
else
|
//else: this is the root group and so we return NULL because we don't
|
||||||
{
|
// have any group line
|
||||||
// we return NULL, so that LineListInsert() will insert us in the
|
|
||||||
// very beginning
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return m_pLine;
|
return m_pLine;
|
||||||
@ -1350,19 +1347,18 @@ wxFileConfigLineList *wxFileConfigGroup::GetGroupLine()
|
|||||||
// last line is the group line (m_pLine) itself.
|
// last line is the group line (m_pLine) itself.
|
||||||
wxFileConfigLineList *wxFileConfigGroup::GetLastGroupLine()
|
wxFileConfigLineList *wxFileConfigGroup::GetLastGroupLine()
|
||||||
{
|
{
|
||||||
// if we have any subgroups, our last line is
|
// if we have any subgroups, our last line is the last line of the last
|
||||||
// the last line of the last subgroup
|
// subgroup
|
||||||
|
if ( m_pLastGroup )
|
||||||
if ( m_pLastGroup != 0 )
|
|
||||||
{
|
{
|
||||||
wxFileConfigLineList *pLine = m_pLastGroup->GetLastGroupLine();
|
wxFileConfigLineList *pLine = m_pLastGroup->GetLastGroupLine();
|
||||||
|
|
||||||
wxASSERT( pLine != 0 ); // last group must have !NULL associated line
|
wxASSERT_MSG( pLine, _T("last group must have !NULL associated line") );
|
||||||
|
|
||||||
return pLine;
|
return pLine;
|
||||||
}
|
}
|
||||||
|
|
||||||
// no subgroups, so the last line is the line of thelast entry (if any)
|
// no subgroups, so the last line is the line of thelast entry (if any)
|
||||||
|
|
||||||
return GetLastEntryLine();
|
return GetLastEntryLine();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1375,30 +1371,52 @@ wxFileConfigLineList *wxFileConfigGroup::GetLastEntryLine()
|
|||||||
_T(" GetLastEntryLine() for Group '%s'"),
|
_T(" GetLastEntryLine() for Group '%s'"),
|
||||||
Name().c_str() );
|
Name().c_str() );
|
||||||
|
|
||||||
if ( m_pLastEntry != 0 )
|
if ( m_pLastEntry )
|
||||||
{
|
{
|
||||||
wxFileConfigLineList *pLine = m_pLastEntry->GetLine();
|
wxFileConfigLineList *pLine = m_pLastEntry->GetLine();
|
||||||
|
|
||||||
wxASSERT( pLine != 0 ); // last entry must have !NULL associated line
|
wxASSERT_MSG( pLine, _T("last entry must have !NULL associated line") );
|
||||||
|
|
||||||
return pLine;
|
return pLine;
|
||||||
}
|
}
|
||||||
|
|
||||||
// no entries: insert after the group header
|
// no entries: insert after the group header, if any
|
||||||
|
|
||||||
return GetGroupLine();
|
return GetGroupLine();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void wxFileConfigGroup::SetLastEntry(wxFileConfigEntry *pEntry)
|
||||||
|
{
|
||||||
|
m_pLastEntry = pEntry;
|
||||||
|
|
||||||
|
if ( !m_pLine )
|
||||||
|
{
|
||||||
|
// the only situation in which a group without its own line can have
|
||||||
|
// an entry is when the first entry is added to the initially empty
|
||||||
|
// root pseudo-group
|
||||||
|
wxASSERT_MSG( !m_pParent, _T("unexpected for non root group") );
|
||||||
|
|
||||||
|
// let the group know that it does have a line in the file now
|
||||||
|
m_pLine = pEntry->GetLine();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// group name
|
// group name
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
void wxFileConfigGroup::Rename(const wxString& newName)
|
void wxFileConfigGroup::Rename(const wxString& newName)
|
||||||
{
|
{
|
||||||
|
wxCHECK_RET( m_pParent, _T("the root group can't be renamed") );
|
||||||
|
|
||||||
m_strName = newName;
|
m_strName = newName;
|
||||||
|
|
||||||
wxFileConfigLineList *line = GetGroupLine();
|
// +1: no leading '/'
|
||||||
wxString strFullName;
|
wxString strFullName;
|
||||||
strFullName << wxT("[") << (GetFullName().c_str() + 1) << wxT("]"); // +1: no '/'
|
strFullName << wxT("[") << (GetFullName().c_str() + 1) << wxT("]");
|
||||||
|
|
||||||
|
wxFileConfigLineList *line = GetGroupLine();
|
||||||
|
wxCHECK_RET( line, _T("a non root group must have a corresponding line!") );
|
||||||
|
|
||||||
line->SetText(strFullName);
|
line->SetText(strFullName);
|
||||||
|
|
||||||
SetDirty();
|
SetDirty();
|
||||||
@ -1799,17 +1817,19 @@ void wxFileConfigEntry::SetValue(const wxString& strValue, bool bUser)
|
|||||||
wxString strLine;
|
wxString strLine;
|
||||||
strLine << FilterOutEntryName(m_strName) << wxT('=') << strValFiltered;
|
strLine << FilterOutEntryName(m_strName) << wxT('=') << strValFiltered;
|
||||||
|
|
||||||
if ( m_pLine != 0 )
|
if ( m_pLine )
|
||||||
{
|
{
|
||||||
// entry was read from the local config file, just modify the line
|
// entry was read from the local config file, just modify the line
|
||||||
m_pLine->SetText(strLine);
|
m_pLine->SetText(strLine);
|
||||||
}
|
}
|
||||||
else {
|
else // this entry didn't exist in the local file
|
||||||
|
{
|
||||||
// add a new line to the file
|
// add a new line to the file
|
||||||
wxASSERT( m_nLine == wxNOT_FOUND ); // consistency check
|
wxASSERT( m_nLine == wxNOT_FOUND ); // consistency check
|
||||||
|
|
||||||
m_pLine = Group()->Config()->LineListInsert(strLine,
|
wxFileConfigLineList *line = Group()->GetLastEntryLine();
|
||||||
Group()->GetLastEntryLine());
|
m_pLine = Group()->Config()->LineListInsert(strLine, line);
|
||||||
|
|
||||||
Group()->SetLastEntry(this);
|
Group()->SetLastEntry(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user