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:
Vadim Zeitlin
1998-06-18 13:07:58 +00:00
parent 82052affa7
commit b841e0e379
2 changed files with 41 additions and 23 deletions

View File

@@ -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
@@ -265,6 +265,11 @@ protected:
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;
// get the last line belonging to an entry/subgroup of this group // get the last line belonging to an entry/subgroup of this group

View File

@@ -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;
if ( pLine == NULL ) {
pNewLine = new LineList(str, m_linesHead);
m_linesHead = pNewLine;
}
else {
pNewLine = new LineList(str, pLine->Next());
pLine->SetNext(pNewLine); 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,9 +657,14 @@ 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
wxASSERT( pLine != NULL ); // last entry must have !NULL associated line
return pLine;
}
// no entrues: insert after the group header
return GetGroupLine(); 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();