don't keep a dirty flag in each entry/group, this is totally wasteful as a single flag in wxFileConfig itself is enough; do reset the dirty flag after Flush()ing
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@29631 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -126,8 +126,7 @@ public:
|
|||||||
|
|
||||||
#if wxUSE_STREAMS
|
#if wxUSE_STREAMS
|
||||||
// ctor that takes an input stream.
|
// ctor that takes an input stream.
|
||||||
wxFileConfig(wxInputStream &inStream,
|
wxFileConfig(wxInputStream &inStream, wxMBConv& conv = wxConvUTF8);
|
||||||
wxMBConv& conv = wxConvUTF8);
|
|
||||||
#endif // wxUSE_STREAMS
|
#endif // wxUSE_STREAMS
|
||||||
|
|
||||||
// dtor will save unsaved data
|
// dtor will save unsaved data
|
||||||
@@ -198,6 +197,12 @@ private:
|
|||||||
// the same as SetPath("/")
|
// the same as SetPath("/")
|
||||||
void SetRootPath();
|
void SetRootPath();
|
||||||
|
|
||||||
|
// set/test the dirty flag
|
||||||
|
void SetDirty() { m_isDirty = true; }
|
||||||
|
void ResetDirty() { m_isDirty = false; }
|
||||||
|
bool IsDirty() const { return m_isDirty; }
|
||||||
|
|
||||||
|
|
||||||
// member variables
|
// member variables
|
||||||
// ----------------
|
// ----------------
|
||||||
wxFileConfigLineList *m_linesHead, // head of the linked list
|
wxFileConfigLineList *m_linesHead, // head of the linked list
|
||||||
@@ -216,6 +221,8 @@ private:
|
|||||||
int m_umask; // the umask to use for file creation
|
int m_umask; // the umask to use for file creation
|
||||||
#endif // __UNIX__
|
#endif // __UNIX__
|
||||||
|
|
||||||
|
bool m_isDirty; // if true, we have unsaved changes
|
||||||
|
|
||||||
DECLARE_NO_COPY_CLASS(wxFileConfig)
|
DECLARE_NO_COPY_CLASS(wxFileConfig)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -154,8 +154,7 @@ private:
|
|||||||
|
|
||||||
wxString m_strName, // entry name
|
wxString m_strName, // entry name
|
||||||
m_strValue; // value
|
m_strValue; // value
|
||||||
bool m_bDirty:1, // changed since last read?
|
bool m_bImmutable:1, // can be overriden locally?
|
||||||
m_bImmutable:1, // can be overriden locally?
|
|
||||||
m_bHasValue:1; // set after first call to SetValue()
|
m_bHasValue:1; // set after first call to SetValue()
|
||||||
|
|
||||||
int m_nLine; // used if m_pLine == NULL only
|
int m_nLine; // used if m_pLine == NULL only
|
||||||
@@ -172,7 +171,6 @@ public:
|
|||||||
const wxString& Name() const { return m_strName; }
|
const wxString& Name() const { return m_strName; }
|
||||||
const wxString& Value() const { return m_strValue; }
|
const wxString& Value() const { return m_strValue; }
|
||||||
wxFileConfigGroup *Group() const { return m_pParent; }
|
wxFileConfigGroup *Group() const { return m_pParent; }
|
||||||
bool IsDirty() const { return m_bDirty; }
|
|
||||||
bool IsImmutable() const { return m_bImmutable; }
|
bool IsImmutable() const { return m_bImmutable; }
|
||||||
bool IsLocal() const { return m_pLine != 0; }
|
bool IsLocal() const { return m_pLine != 0; }
|
||||||
int Line() const { return m_nLine; }
|
int Line() const { return m_nLine; }
|
||||||
@@ -181,7 +179,6 @@ public:
|
|||||||
|
|
||||||
// modify entry attributes
|
// modify entry attributes
|
||||||
void SetValue(const wxString& strValue, bool bUser = true);
|
void SetValue(const wxString& strValue, bool bUser = true);
|
||||||
void SetDirty();
|
|
||||||
void SetLine(wxFileConfigLineList *pLine);
|
void SetLine(wxFileConfigLineList *pLine);
|
||||||
|
|
||||||
DECLARE_NO_COPY_CLASS(wxFileConfigEntry)
|
DECLARE_NO_COPY_CLASS(wxFileConfigEntry)
|
||||||
@@ -199,7 +196,6 @@ private:
|
|||||||
ArrayEntries m_aEntries; // entries in this group
|
ArrayEntries m_aEntries; // entries in this group
|
||||||
ArrayGroups m_aSubgroups; // subgroups
|
ArrayGroups m_aSubgroups; // subgroups
|
||||||
wxString m_strName; // group's name
|
wxString m_strName; // group's name
|
||||||
bool m_bDirty; // if false => all subgroups are not dirty
|
|
||||||
wxFileConfigLineList *m_pLine; // pointer to our line in the linked list
|
wxFileConfigLineList *m_pLine; // pointer to our line in the linked list
|
||||||
wxFileConfigEntry *m_pLastEntry; // last entry/subgroup of this group in the
|
wxFileConfigEntry *m_pLastEntry; // last entry/subgroup of this group in the
|
||||||
wxFileConfigGroup *m_pLastGroup; // local file (we insert new ones after it)
|
wxFileConfigGroup *m_pLastGroup; // local file (we insert new ones after it)
|
||||||
@@ -218,7 +214,6 @@ public:
|
|||||||
const wxString& Name() const { return m_strName; }
|
const wxString& Name() const { return m_strName; }
|
||||||
wxFileConfigGroup *Parent() const { return m_pParent; }
|
wxFileConfigGroup *Parent() const { return m_pParent; }
|
||||||
wxFileConfig *Config() const { return m_pConfig; }
|
wxFileConfig *Config() const { return m_pConfig; }
|
||||||
bool IsDirty() const { return m_bDirty; }
|
|
||||||
|
|
||||||
const ArrayEntries& Entries() const { return m_aEntries; }
|
const ArrayEntries& Entries() const { return m_aEntries; }
|
||||||
const ArrayGroups& Groups() const { return m_aSubgroups; }
|
const ArrayGroups& Groups() const { return m_aSubgroups; }
|
||||||
@@ -236,8 +231,6 @@ public:
|
|||||||
wxFileConfigGroup *AddSubgroup(const wxString& strName);
|
wxFileConfigGroup *AddSubgroup(const wxString& strName);
|
||||||
wxFileConfigEntry *AddEntry (const wxString& strName, int nLine = wxNOT_FOUND);
|
wxFileConfigEntry *AddEntry (const wxString& strName, int nLine = wxNOT_FOUND);
|
||||||
|
|
||||||
// will also recursively set parent's dirty flag
|
|
||||||
void SetDirty();
|
|
||||||
void SetLine(wxFileConfigLineList *pLine);
|
void SetLine(wxFileConfigLineList *pLine);
|
||||||
|
|
||||||
// rename: no checks are done to ensure that the name is unique!
|
// rename: no checks are done to ensure that the name is unique!
|
||||||
@@ -417,6 +410,8 @@ void wxFileConfig::Init()
|
|||||||
wxLogWarning(_("can't open user configuration file '%s'."), m_strLocalFile.c_str() );
|
wxLogWarning(_("can't open user configuration file '%s'."), m_strLocalFile.c_str() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m_isDirty = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// constructor supports creation of wxFileConfig objects of any type
|
// constructor supports creation of wxFileConfig objects of any type
|
||||||
@@ -913,7 +908,7 @@ bool wxFileConfig::DoWriteString(const wxString& key, const wxString& szValue)
|
|||||||
_T(" Creating group %s"),
|
_T(" Creating group %s"),
|
||||||
m_pCurrentGroup->Name().c_str() );
|
m_pCurrentGroup->Name().c_str() );
|
||||||
|
|
||||||
m_pCurrentGroup->SetDirty();
|
SetDirty();
|
||||||
|
|
||||||
// this will add a line for this group if it didn't have it before
|
// this will add a line for this group if it didn't have it before
|
||||||
|
|
||||||
@@ -921,9 +916,7 @@ bool wxFileConfig::DoWriteString(const wxString& key, const wxString& szValue)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// writing an entry
|
// writing an entry check that the name is reasonable
|
||||||
// check that the name is reasonable
|
|
||||||
|
|
||||||
if ( strName[0u] == wxCONFIG_IMMUTABLE_PREFIX )
|
if ( strName[0u] == wxCONFIG_IMMUTABLE_PREFIX )
|
||||||
{
|
{
|
||||||
wxLogError( _("Config entry name cannot start with '%c'."),
|
wxLogError( _("Config entry name cannot start with '%c'."),
|
||||||
@@ -945,6 +938,8 @@ bool wxFileConfig::DoWriteString(const wxString& key, const wxString& szValue)
|
|||||||
_T(" Setting value %s"),
|
_T(" Setting value %s"),
|
||||||
szValue.c_str() );
|
szValue.c_str() );
|
||||||
pEntry->SetValue(szValue);
|
pEntry->SetValue(szValue);
|
||||||
|
|
||||||
|
SetDirty();
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@@ -957,7 +952,7 @@ bool wxFileConfig::DoWriteLong(const wxString& key, long lValue)
|
|||||||
|
|
||||||
bool wxFileConfig::Flush(bool /* bCurrentOnly */)
|
bool wxFileConfig::Flush(bool /* bCurrentOnly */)
|
||||||
{
|
{
|
||||||
if ( LineListIsEmpty() || !m_pRootGroup->IsDirty() || !m_strLocalFile )
|
if ( !IsDirty() || !m_strLocalFile )
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
// set the umask if needed
|
// set the umask if needed
|
||||||
@@ -990,6 +985,8 @@ bool wxFileConfig::Flush(bool /* bCurrentOnly */)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ResetDirty();
|
||||||
|
|
||||||
#if defined(__WXMAC__)
|
#if defined(__WXMAC__)
|
||||||
wxFileName(m_strLocalFile).MacSetTypeAndCreator('TEXT', 'ttxt');
|
wxFileName(m_strLocalFile).MacSetTypeAndCreator('TEXT', 'ttxt');
|
||||||
#endif // __WXMAC__
|
#endif // __WXMAC__
|
||||||
@@ -1018,6 +1015,8 @@ bool wxFileConfig::RenameEntry(const wxString& oldName,
|
|||||||
if ( !m_pCurrentGroup->DeleteEntry(oldName) )
|
if ( !m_pCurrentGroup->DeleteEntry(oldName) )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
SetDirty();
|
||||||
|
|
||||||
wxFileConfigEntry *newEntry = m_pCurrentGroup->AddEntry(newName);
|
wxFileConfigEntry *newEntry = m_pCurrentGroup->AddEntry(newName);
|
||||||
newEntry->SetValue(value);
|
newEntry->SetValue(value);
|
||||||
|
|
||||||
@@ -1038,6 +1037,8 @@ bool wxFileConfig::RenameGroup(const wxString& oldName,
|
|||||||
|
|
||||||
group->Rename(newName);
|
group->Rename(newName);
|
||||||
|
|
||||||
|
SetDirty();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1056,7 +1057,8 @@ bool wxFileConfig::DeleteEntry(const wxString& key, bool bGroupIfEmptyAlso)
|
|||||||
if ( m_pCurrentGroup != m_pRootGroup ) {
|
if ( m_pCurrentGroup != m_pRootGroup ) {
|
||||||
wxFileConfigGroup *pGroup = m_pCurrentGroup;
|
wxFileConfigGroup *pGroup = m_pCurrentGroup;
|
||||||
SetPath(wxT("..")); // changes m_pCurrentGroup!
|
SetPath(wxT("..")); // changes m_pCurrentGroup!
|
||||||
m_pCurrentGroup->DeleteSubgroupByName(pGroup->Name());
|
if ( m_pCurrentGroup->DeleteSubgroupByName(pGroup->Name()) )
|
||||||
|
SetDirty();
|
||||||
}
|
}
|
||||||
//else: never delete the root group
|
//else: never delete the root group
|
||||||
}
|
}
|
||||||
@@ -1068,7 +1070,12 @@ bool wxFileConfig::DeleteGroup(const wxString& key)
|
|||||||
{
|
{
|
||||||
wxConfigPathChanger path(this, key);
|
wxConfigPathChanger path(this, key);
|
||||||
|
|
||||||
return m_pCurrentGroup->DeleteSubgroupByName(path.Name());
|
if ( !m_pCurrentGroup->DeleteSubgroupByName(path.Name()) )
|
||||||
|
return false;
|
||||||
|
|
||||||
|
SetDirty();
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wxFileConfig::DeleteAll()
|
bool wxFileConfig::DeleteAll()
|
||||||
@@ -1239,7 +1246,6 @@ wxFileConfigGroup::wxFileConfigGroup(wxFileConfigGroup *pParent,
|
|||||||
{
|
{
|
||||||
m_pConfig = pConfig;
|
m_pConfig = pConfig;
|
||||||
m_pParent = pParent;
|
m_pParent = pParent;
|
||||||
m_bDirty = false;
|
|
||||||
m_pLine = NULL;
|
m_pLine = NULL;
|
||||||
|
|
||||||
m_pLastEntry = NULL;
|
m_pLastEntry = NULL;
|
||||||
@@ -1417,8 +1423,6 @@ void wxFileConfigGroup::Rename(const wxString& newName)
|
|||||||
wxCHECK_RET( line, _T("a non root group must have a corresponding line!") );
|
wxCHECK_RET( line, _T("a non root group must have a corresponding line!") );
|
||||||
|
|
||||||
line->SetText(strFullName);
|
line->SetText(strFullName);
|
||||||
|
|
||||||
SetDirty();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
wxString wxFileConfigGroup::GetFullName() const
|
wxString wxFileConfigGroup::GetFullName() const
|
||||||
@@ -1671,8 +1675,6 @@ bool wxFileConfigGroup::DeleteSubgroup(wxFileConfigGroup *pGroup)
|
|||||||
pGroup->Name().c_str() );
|
pGroup->Name().c_str() );
|
||||||
}
|
}
|
||||||
|
|
||||||
SetDirty();
|
|
||||||
|
|
||||||
m_aSubgroups.Remove(pGroup);
|
m_aSubgroups.Remove(pGroup);
|
||||||
delete pGroup;
|
delete pGroup;
|
||||||
|
|
||||||
@@ -1720,25 +1722,12 @@ bool wxFileConfigGroup::DeleteEntry(const wxChar *szName)
|
|||||||
m_pConfig->LineListRemove(pLine);
|
m_pConfig->LineListRemove(pLine);
|
||||||
}
|
}
|
||||||
|
|
||||||
// we must be written back for the changes to be saved
|
|
||||||
SetDirty();
|
|
||||||
|
|
||||||
m_aEntries.Remove(pEntry);
|
m_aEntries.Remove(pEntry);
|
||||||
delete pEntry;
|
delete pEntry;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
//
|
|
||||||
// ----------------------------------------------------------------------------
|
|
||||||
void wxFileConfigGroup::SetDirty()
|
|
||||||
{
|
|
||||||
m_bDirty = true;
|
|
||||||
if ( Parent() != NULL ) // propagate upwards
|
|
||||||
Parent()->SetDirty();
|
|
||||||
}
|
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
// wxFileConfig::wxFileConfigEntry
|
// wxFileConfig::wxFileConfigEntry
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
@@ -1757,7 +1746,6 @@ wxFileConfigEntry::wxFileConfigEntry(wxFileConfigGroup *pParent,
|
|||||||
m_nLine = nLine;
|
m_nLine = nLine;
|
||||||
m_pLine = NULL;
|
m_pLine = NULL;
|
||||||
|
|
||||||
m_bDirty =
|
|
||||||
m_bHasValue = false;
|
m_bHasValue = false;
|
||||||
|
|
||||||
m_bImmutable = strName[0] == wxCONFIG_IMMUTABLE_PREFIX;
|
m_bImmutable = strName[0] == wxCONFIG_IMMUTABLE_PREFIX;
|
||||||
@@ -1791,10 +1779,8 @@ void wxFileConfigEntry::SetValue(const wxString& strValue, bool bUser)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// do nothing if it's the same value: but don't test for it
|
// do nothing if it's the same value: but don't test for it if m_bHasValue
|
||||||
// if m_bHasValue hadn't been set yet or we'd never write
|
// hadn't been set yet or we'd never write empty values to the file
|
||||||
// empty values to the file
|
|
||||||
|
|
||||||
if ( m_bHasValue && strValue == m_strValue )
|
if ( m_bHasValue && strValue == m_strValue )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -1829,17 +1815,9 @@ void wxFileConfigEntry::SetValue(const wxString& strValue, bool bUser)
|
|||||||
|
|
||||||
Group()->SetLastEntry(this);
|
Group()->SetLastEntry(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
SetDirty();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxFileConfigEntry::SetDirty()
|
|
||||||
{
|
|
||||||
m_bDirty = true;
|
|
||||||
Group()->SetDirty();
|
|
||||||
}
|
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
// global functions
|
// global functions
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
|
Reference in New Issue
Block a user