From: Vadim Zeitlin Date: Thu, 18 Jun 1998 13:07:58 +0000 (+0000) Subject: wxFileConfig bugs corrected (now the new entries belong to the right groups) X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/b841e0e379f585a35feef93569f1bc27a2b00fb6 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 --- diff --git a/include/wx/fileconf.h b/include/wx/fileconf.h index 97c03c8ffa..cbbb0e0de0 100644 --- a/include/wx/fileconf.h +++ b/include/wx/fileconf.h @@ -229,8 +229,8 @@ protected: wxString m_strName; // group's name bool m_bDirty; // if FALSE => all subgroups are not dirty LineList *m_pLine; // pointer to our line in the linked list - int m_nLastEntry, // last here means "last added" - m_nLastGroup; // + ConfigEntry *m_pLastEntry; // last entry of this group in the local file + ConfigGroup *m_pLastGroup; // last subgroup public: // ctor @@ -264,6 +264,11 @@ protected: // will also recursively set parent's dirty flag void SetDirty(); 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; diff --git a/src/common/fileconf.cpp b/src/common/fileconf.cpp index 9a0f899135..b75de3b7c3 100644 --- a/src/common/fileconf.cpp +++ b/src/common/fileconf.cpp @@ -542,15 +542,23 @@ wxFileConfig::LineList *wxFileConfig::LineListAppend(const wxString& str) 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, LineList *pLine) { - if ( pLine == NULL ) + if ( pLine == m_linesTail ) return LineListAppend(str); - LineList *pNewLine = new LineList(str, pLine->Next()); - pLine->SetNext(pNewLine); + LineList *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; } @@ -578,9 +586,8 @@ wxFileConfig::ConfigGroup::ConfigGroup(wxFileConfig::ConfigGroup *pParent, m_pParent = pParent; m_pLine = NULL; m_bDirty = FALSE; - - m_nLastEntry = - m_nLastGroup = NOT_FOUND; + m_pLastEntry = NULL; + m_pLastGroup = NULL; } // dtor deletes all children @@ -618,11 +625,11 @@ wxFileConfig::LineList *wxFileConfig::ConfigGroup::GetGroupLine() strFullName << "[" << GetFullName().c_str() + 1 << "]"; // +1: no '/' m_pLine = m_pConfig->LineListInsert(strFullName, Parent()->GetLastGroupLine()); + Parent()->SetLastGroup(this); } else { - // we're the root group, yet we were not in the local file => there were - // only comments and blank lines in config file or nothing at all - // we return NULL, so that LineListInsert() will do Append() + // we return NULL, so that LineListInsert() will insert us in the + // very beginning } } @@ -635,14 +642,12 @@ wxFileConfig::LineList *wxFileConfig::ConfigGroup::GetLastGroupLine() { // if we have any subgroups, our last line is the last line of the last // subgroup - if ( m_nLastGroup != NOT_FOUND ) { - return m_aSubgroups[m_nLastGroup]->GetLastGroupLine(); - } + if ( m_pLastGroup != NULL ) + return m_pLastGroup->GetLastGroupLine(); // if we have any entries, our last line is the last entry - if ( m_nLastEntry != NOT_FOUND ) { - return m_aEntries[m_nLastEntry]->GetLine(); - } + if ( m_pLastEntry != NULL ) + return m_pLastEntry->GetLine(); // nothing at all: last line is the first one return GetGroupLine(); @@ -652,10 +657,15 @@ wxFileConfig::LineList *wxFileConfig::ConfigGroup::GetLastGroupLine() // (after which we can add a new entry) wxFileConfig::LineList *wxFileConfig::ConfigGroup::GetLastEntryLine() { - if ( m_nLastEntry != NOT_FOUND ) - return m_aEntries[m_nLastEntry]->GetLine(); - else - return GetGroupLine(); + if ( m_pLastEntry != NULL ) { + wxFileConfig::LineList *pLine = m_pLastEntry->GetLine(); + + 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; + Group()->SetLastEntry(this); } // 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 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();