wxFileConfig bugs corrected (now the new entries belong to the right groups)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@107 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -229,8 +229,8 @@ protected:
|
|||||||
wxString m_strName; // group's name
|
wxString m_strName; // group's name
|
||||||
bool m_bDirty; // if FALSE => all subgroups are not dirty
|
bool m_bDirty; // if FALSE => all subgroups are not dirty
|
||||||
LineList *m_pLine; // pointer to our line in the linked list
|
LineList *m_pLine; // pointer to our line in the linked list
|
||||||
int m_nLastEntry, // last here means "last added"
|
ConfigEntry *m_pLastEntry; // last entry of this group in the local file
|
||||||
m_nLastGroup; //
|
ConfigGroup *m_pLastGroup; // last subgroup
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// ctor
|
// ctor
|
||||||
@@ -264,6 +264,11 @@ protected:
|
|||||||
// will also recursively set parent's dirty flag
|
// will also recursively set parent's dirty flag
|
||||||
void SetDirty();
|
void SetDirty();
|
||||||
void SetLine(LineList *pLine);
|
void SetLine(LineList *pLine);
|
||||||
|
|
||||||
|
// the new entries in this subgroup will be inserted after the last subgroup
|
||||||
|
// or, if there is none, after the last entry
|
||||||
|
void SetLastEntry(ConfigEntry *pLastEntry) { m_pLastEntry = pLastEntry; }
|
||||||
|
void SetLastGroup(ConfigGroup *pLastGroup) { m_pLastGroup = pLastGroup; }
|
||||||
|
|
||||||
wxString GetFullName() const;
|
wxString GetFullName() const;
|
||||||
|
|
||||||
|
@@ -542,15 +542,23 @@ wxFileConfig::LineList *wxFileConfig::LineListAppend(const wxString& str)
|
|||||||
return m_linesTail;
|
return m_linesTail;
|
||||||
}
|
}
|
||||||
|
|
||||||
// insert a new line after the given one
|
// insert a new line after the given one or in the very beginning if !pLine
|
||||||
wxFileConfig::LineList *wxFileConfig::LineListInsert(const wxString& str,
|
wxFileConfig::LineList *wxFileConfig::LineListInsert(const wxString& str,
|
||||||
LineList *pLine)
|
LineList *pLine)
|
||||||
{
|
{
|
||||||
if ( pLine == NULL )
|
if ( pLine == m_linesTail )
|
||||||
return LineListAppend(str);
|
return LineListAppend(str);
|
||||||
|
|
||||||
LineList *pNewLine = new LineList(str, pLine->Next());
|
LineList *pNewLine;
|
||||||
pLine->SetNext(pNewLine);
|
|
||||||
|
if ( pLine == NULL ) {
|
||||||
|
pNewLine = new LineList(str, m_linesHead);
|
||||||
|
m_linesHead = pNewLine;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
pNewLine = new LineList(str, pLine->Next());
|
||||||
|
pLine->SetNext(pNewLine);
|
||||||
|
}
|
||||||
|
|
||||||
return pNewLine;
|
return pNewLine;
|
||||||
}
|
}
|
||||||
@@ -578,9 +586,8 @@ wxFileConfig::ConfigGroup::ConfigGroup(wxFileConfig::ConfigGroup *pParent,
|
|||||||
m_pParent = pParent;
|
m_pParent = pParent;
|
||||||
m_pLine = NULL;
|
m_pLine = NULL;
|
||||||
m_bDirty = FALSE;
|
m_bDirty = FALSE;
|
||||||
|
m_pLastEntry = NULL;
|
||||||
m_nLastEntry =
|
m_pLastGroup = NULL;
|
||||||
m_nLastGroup = NOT_FOUND;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// dtor deletes all children
|
// dtor deletes all children
|
||||||
@@ -618,11 +625,11 @@ wxFileConfig::LineList *wxFileConfig::ConfigGroup::GetGroupLine()
|
|||||||
strFullName << "[" << GetFullName().c_str() + 1 << "]"; // +1: no '/'
|
strFullName << "[" << GetFullName().c_str() + 1 << "]"; // +1: no '/'
|
||||||
m_pLine = m_pConfig->LineListInsert(strFullName,
|
m_pLine = m_pConfig->LineListInsert(strFullName,
|
||||||
Parent()->GetLastGroupLine());
|
Parent()->GetLastGroupLine());
|
||||||
|
Parent()->SetLastGroup(this);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// we're the root group, yet we were not in the local file => there were
|
// we return NULL, so that LineListInsert() will insert us in the
|
||||||
// only comments and blank lines in config file or nothing at all
|
// very beginning
|
||||||
// we return NULL, so that LineListInsert() will do Append()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -635,14 +642,12 @@ wxFileConfig::LineList *wxFileConfig::ConfigGroup::GetLastGroupLine()
|
|||||||
{
|
{
|
||||||
// if we have any subgroups, our last line is the last line of the last
|
// if we have any subgroups, our last line is the last line of the last
|
||||||
// subgroup
|
// subgroup
|
||||||
if ( m_nLastGroup != NOT_FOUND ) {
|
if ( m_pLastGroup != NULL )
|
||||||
return m_aSubgroups[m_nLastGroup]->GetLastGroupLine();
|
return m_pLastGroup->GetLastGroupLine();
|
||||||
}
|
|
||||||
|
|
||||||
// if we have any entries, our last line is the last entry
|
// if we have any entries, our last line is the last entry
|
||||||
if ( m_nLastEntry != NOT_FOUND ) {
|
if ( m_pLastEntry != NULL )
|
||||||
return m_aEntries[m_nLastEntry]->GetLine();
|
return m_pLastEntry->GetLine();
|
||||||
}
|
|
||||||
|
|
||||||
// nothing at all: last line is the first one
|
// nothing at all: last line is the first one
|
||||||
return GetGroupLine();
|
return GetGroupLine();
|
||||||
@@ -652,10 +657,15 @@ wxFileConfig::LineList *wxFileConfig::ConfigGroup::GetLastGroupLine()
|
|||||||
// (after which we can add a new entry)
|
// (after which we can add a new entry)
|
||||||
wxFileConfig::LineList *wxFileConfig::ConfigGroup::GetLastEntryLine()
|
wxFileConfig::LineList *wxFileConfig::ConfigGroup::GetLastEntryLine()
|
||||||
{
|
{
|
||||||
if ( m_nLastEntry != NOT_FOUND )
|
if ( m_pLastEntry != NULL ) {
|
||||||
return m_aEntries[m_nLastEntry]->GetLine();
|
wxFileConfig::LineList *pLine = m_pLastEntry->GetLine();
|
||||||
else
|
|
||||||
return GetGroupLine();
|
wxASSERT( pLine != NULL ); // last entry must have !NULL associated line
|
||||||
|
return pLine;
|
||||||
|
}
|
||||||
|
|
||||||
|
// no entrues: insert after the group header
|
||||||
|
return GetGroupLine();
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
@@ -807,6 +817,7 @@ void wxFileConfig::ConfigEntry::SetLine(LineList *pLine)
|
|||||||
}
|
}
|
||||||
|
|
||||||
m_pLine = pLine;
|
m_pLine = pLine;
|
||||||
|
Group()->SetLastEntry(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
// second parameter is FALSE if we read the value from file and prevents the
|
// second parameter is FALSE if we read the value from file and prevents the
|
||||||
@@ -838,7 +849,9 @@ void wxFileConfig::ConfigEntry::SetValue(const wxString& strValue, bool bUser)
|
|||||||
// add a new line to the file
|
// add a new line to the file
|
||||||
wxASSERT( m_nLine == NOT_FOUND ); // consistency check
|
wxASSERT( m_nLine == NOT_FOUND ); // consistency check
|
||||||
|
|
||||||
Group()->Config()->LineListInsert(strLine, Group()->GetLastEntryLine());
|
m_pLine = Group()->Config()->LineListInsert(strLine,
|
||||||
|
Group()->GetLastEntryLine());
|
||||||
|
Group()->SetLastEntry(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
SetDirty();
|
SetDirty();
|
||||||
|
Reference in New Issue
Block a user