#endif
#include "wx/textfile.h"
+#include "wx/txtstrm.h"
#include "wx/wfstream.h"
#include "wx/config.h"
#include "configtooldoc.h"
// This is the backup filename
wxString backupFilename(filename);
backupFilename += wxT(".bak");
-
+
// This is the temporary copy of the backup
wxString tempFilename(filename);
tempFilename += wxT(".tmp");
{
wxRemoveFile(backupFilename);
}
-
+
// Copy the old file to the .bak
if (leaveBackup)
if (wxFileExists(filename))
wxRemoveFile(filename);
}
-
+
// Finally, copy the temporary file to the proper filename
if (!wxRenameFile(tempFilename, filename))
{
wxCopyFile(tempFilename, filename);
wxRemoveFile(tempFilename);
- }
+ }
Modify(false);
((ctConfigToolView*)GetFirstView())->OnChangeFilename();
/// Save the settings file
bool ctConfigToolDoc::DoSave(const wxString& filename)
{
- wxFileOutputStream stream(filename);
- if (!stream.Ok())
+ wxFileOutputStream osFile(filename);
+ if (!osFile.Ok())
return false;
+ wxTextOutputStream stream(osFile);
+
stream << wxT("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");
stream << wxT("<settings xmlns=\"http://www.wxwidgets.org/wxs\" version=\"2.5.0.1\">");
- DoSave(m_topItem, stream, 1);
+ DoSave(m_topItem, osFile, 1);
stream << wxT("\n</settings>\n");
return true;
}
-inline static void OutputIndentation(wxOutputStream& stream, int indent)
+inline static void OutputIndentation(wxOutputStream& osFile, int indent)
{
+ wxTextOutputStream stream(osFile);
wxString str = wxT("\n");
for (int i = 0; i < indent; i++)
- str << wxT(' ') << wxT(' ');
+ str << wxT(" ");
stream << str ;
}
/// Recursive helper function for file saving
-bool ctConfigToolDoc::DoSave(ctConfigItem* item, wxOutputStream& stream, int indent)
+bool ctConfigToolDoc::DoSave(ctConfigItem* item, wxOutputStream& osFile, int indent)
{
- OutputIndentation(stream, indent*2);
+ OutputIndentation(osFile, indent*2);
+ wxTextOutputStream stream(osFile);
wxString name(item->GetName());
wxString s;
indent ++;
- OutputIndentation(stream, indent*2);
+ OutputIndentation(osFile, indent*2);
if (item->IsActive())
stream << wxT("<active>1</active>");
else
stream << wxT("<active>0</active>");
- OutputIndentation(stream, indent*2);
+ OutputIndentation(osFile, indent*2);
if (item->IsEnabled())
stream << wxT("<enabled>1</enabled>");
else
while (node)
{
ctProperty* prop = (ctProperty*) node->GetData();
- OutputIndentation(stream, indent*2);
+ OutputIndentation(osFile, indent*2);
stream << wxT("<") << prop->GetName() ;
-
+
if (prop->IsCustom())
{
stream << wxT(" custom=\"true\"");
stream << wxT(" choices=\"") << choices << wxT("\"");
}
}
-
+
stream << wxT(">");
stream << ctEscapeHTMLCharacters(prop->GetVariant().GetString()) ;
while (node)
{
ctConfigItem* child = (ctConfigItem*) node->GetData();
- DoSave(child, stream, indent);
+ DoSave(child, osFile, indent);
node = node->GetNext();
}
indent --;
- OutputIndentation(stream, indent*2);
+ OutputIndentation(osFile, indent*2);
stream << wxT("</setting>");
return true;
static bool GetHtmlBoolValue(const wxString& value)
{
- if (value == wxT("true") || value == wxT("TRUE") || value == wxT("1"))
+ if (value.IsSameAs(wxT("true"),false) || value == wxT("1"))
return true;
- else
- return false;
+ else
+ return false;
}
static int GetHtmlIntegerValue(const wxString& value)
/// Clear dependencies
void ctConfigToolDoc::ClearDependencies(ctConfigItem* item)
{
- if (!item)
+ if (!item) {
item = GetTopItem();
+ if (!item)
+ return;
+ }
item->GetDependents().Clear();
for ( wxObjectList::compatibility_iterator node = item->GetChildren().GetFirst(); node; node = node->GetNext() )
/// Refresh dependencies
void ctConfigToolDoc::RefreshDependencies(ctConfigItem* item)
{
+ if (item==NULL)
+ return;
+
wxArrayString requiresArr;
wxString requires = item->GetPropertyString(wxT("requires"));
wxString precludes = item->GetPropertyString(wxT("precludes"));
// parent is a check or radio group.
ctConfigItem* parent = item->GetParent();
if (parent &&
- (parent->GetType() == ctTypeCheckGroup ||
+ (parent->GetType() == ctTypeCheckGroup ||
parent->GetType() == ctTypeRadioGroup))
requiresArr.Add(parent->GetName());
{
str << wxT(" ") << configureCommand;
}
- }
+ }
}
}
// This will delete the old clipboard contents, if any.
doc->SetClipboardItem(newItem);
-
+
m_parent = m_activeState->GetParent();
m_insertBefore = m_activeState->FindNextSibling();
wxGetApp().GetMainFrame()->GetDocument()->SetTopItem(NULL);
}
*/
-
+
Clear();
}
}
*/
}
-
-