#if wxUSE_STREAMS
// ctor that takes an input stream.
- wxFileConfig(wxInputStream &inStream,
- wxMBConv& conv = wxConvUTF8);
+ wxFileConfig(wxInputStream &inStream, wxMBConv& conv = wxConvUTF8);
#endif // wxUSE_STREAMS
// dtor will save unsaved data
// the same as SetPath("/")
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
// ----------------
- wxFileConfigLineList *m_linesHead, // head of the linked list
- *m_linesTail; // tail
+ wxFileConfigLineList *m_linesHead, // head of the linked list
+ *m_linesTail; // tail
- wxString m_strLocalFile, // local file name passed to ctor
- m_strGlobalFile; // global
- wxString m_strPath; // current path (not '/' terminated)
+ wxString m_strLocalFile, // local file name passed to ctor
+ m_strGlobalFile; // global
+ wxString m_strPath; // current path (not '/' terminated)
wxFileConfigGroup *m_pRootGroup, // the top (unnamed) group
*m_pCurrentGroup; // the current group
wxMBConv &m_conv;
#ifdef __UNIX__
- int m_umask; // the umask to use for file creation
+ int m_umask; // the umask to use for file creation
#endif // __UNIX__
- DECLARE_NO_COPY_CLASS(wxFileConfig)
+ bool m_isDirty; // if true, we have unsaved changes
+
+ DECLARE_NO_COPY_CLASS(wxFileConfig)
};
#endif
wxString m_strName, // entry name
m_strValue; // value
- bool m_bDirty:1, // changed since last read?
- m_bImmutable:1, // can be overriden locally?
+ bool m_bImmutable:1, // can be overriden locally?
m_bHasValue:1; // set after first call to SetValue()
int m_nLine; // used if m_pLine == NULL only
const wxString& Name() const { return m_strName; }
const wxString& Value() const { return m_strValue; }
wxFileConfigGroup *Group() const { return m_pParent; }
- bool IsDirty() const { return m_bDirty; }
bool IsImmutable() const { return m_bImmutable; }
bool IsLocal() const { return m_pLine != 0; }
int Line() const { return m_nLine; }
// modify entry attributes
void SetValue(const wxString& strValue, bool bUser = true);
- void SetDirty();
void SetLine(wxFileConfigLineList *pLine);
DECLARE_NO_COPY_CLASS(wxFileConfigEntry)
ArrayEntries m_aEntries; // entries in this group
ArrayGroups m_aSubgroups; // subgroups
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
wxFileConfigEntry *m_pLastEntry; // last entry/subgroup of this group in the
wxFileConfigGroup *m_pLastGroup; // local file (we insert new ones after it)
const wxString& Name() const { return m_strName; }
wxFileConfigGroup *Parent() const { return m_pParent; }
wxFileConfig *Config() const { return m_pConfig; }
- bool IsDirty() const { return m_bDirty; }
const ArrayEntries& Entries() const { return m_aEntries; }
const ArrayGroups& Groups() const { return m_aSubgroups; }
wxFileConfigGroup *AddSubgroup(const wxString& strName);
wxFileConfigEntry *AddEntry (const wxString& strName, int nLine = wxNOT_FOUND);
- // will also recursively set parent's dirty flag
- void SetDirty();
void SetLine(wxFileConfigLineList *pLine);
// rename: no checks are done to ensure that the name is unique!
wxLogWarning(_("can't open user configuration file '%s'."), m_strLocalFile.c_str() );
}
}
+
+ m_isDirty = false;
}
// constructor supports creation of wxFileConfig objects of any type
_T(" Creating group %s"),
m_pCurrentGroup->Name().c_str() );
- m_pCurrentGroup->SetDirty();
+ SetDirty();
// this will add a line for this group if it didn't have it before
}
else
{
- // writing an entry
- // check that the name is reasonable
-
+ // writing an entry check that the name is reasonable
if ( strName[0u] == wxCONFIG_IMMUTABLE_PREFIX )
{
wxLogError( _("Config entry name cannot start with '%c'."),
_T(" Setting value %s"),
szValue.c_str() );
pEntry->SetValue(szValue);
+
+ SetDirty();
}
return true;
bool wxFileConfig::Flush(bool /* bCurrentOnly */)
{
- if ( LineListIsEmpty() || !m_pRootGroup->IsDirty() || !m_strLocalFile )
+ if ( !IsDirty() || !m_strLocalFile )
return true;
// set the umask if needed
return false;
}
+ ResetDirty();
+
#if defined(__WXMAC__)
wxFileName(m_strLocalFile).MacSetTypeAndCreator('TEXT', 'ttxt');
#endif // __WXMAC__
if ( !m_pCurrentGroup->DeleteEntry(oldName) )
return false;
+ SetDirty();
+
wxFileConfigEntry *newEntry = m_pCurrentGroup->AddEntry(newName);
newEntry->SetValue(value);
group->Rename(newName);
+ SetDirty();
+
return true;
}
if ( m_pCurrentGroup != m_pRootGroup ) {
wxFileConfigGroup *pGroup = 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
}
{
wxConfigPathChanger path(this, key);
- return m_pCurrentGroup->DeleteSubgroupByName(path.Name());
+ if ( !m_pCurrentGroup->DeleteSubgroupByName(path.Name()) )
+ return false;
+
+ SetDirty();
+
+ return true;
}
bool wxFileConfig::DeleteAll()
{
m_pConfig = pConfig;
m_pParent = pParent;
- m_bDirty = false;
m_pLine = NULL;
m_pLastEntry = NULL;
wxCHECK_RET( line, _T("a non root group must have a corresponding line!") );
line->SetText(strFullName);
-
- SetDirty();
}
wxString wxFileConfigGroup::GetFullName() const
pGroup->Name().c_str() );
}
- SetDirty();
-
m_aSubgroups.Remove(pGroup);
delete pGroup;
m_pConfig->LineListRemove(pLine);
}
- // we must be written back for the changes to be saved
- SetDirty();
-
m_aEntries.Remove(pEntry);
delete pEntry;
return true;
}
-// ----------------------------------------------------------------------------
-//
-// ----------------------------------------------------------------------------
-void wxFileConfigGroup::SetDirty()
-{
- m_bDirty = true;
- if ( Parent() != NULL ) // propagate upwards
- Parent()->SetDirty();
-}
-
// ============================================================================
// wxFileConfig::wxFileConfigEntry
// ============================================================================
m_nLine = nLine;
m_pLine = NULL;
- m_bDirty =
m_bHasValue = false;
m_bImmutable = strName[0] == wxCONFIG_IMMUTABLE_PREFIX;
return;
}
- // do nothing if it's the same value: but don't test for it
- // if m_bHasValue hadn't been set yet or we'd never write
- // empty values to the file
-
+ // do nothing if it's the same value: but don't test for it if m_bHasValue
+ // hadn't been set yet or we'd never write empty values to the file
if ( m_bHasValue && strValue == m_strValue )
return;
if ( bUser )
{
- wxString strValFiltered;
+ wxString strValFiltered;
if ( Group()->Config()->GetStyle() & wxCONFIG_USE_NO_ESCAPE_CHARACTERS )
{
Group()->SetLastEntry(this);
}
-
- SetDirty();
}
}
-void wxFileConfigEntry::SetDirty()
-{
- m_bDirty = true;
- Group()->SetDirty();
-}
-
// ============================================================================
// global functions
// ============================================================================