X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/d9ab621ea2513f623f3f7c1699648f189e37be3f..dfc6f510c5f5efdc1f072996ddf1ae0416a4a4ad:/utils/configtool/src/configtooldoc.cpp diff --git a/utils/configtool/src/configtooldoc.cpp b/utils/configtool/src/configtooldoc.cpp index 122bd5926a..7754ba4ced 100644 --- a/utils/configtool/src/configtooldoc.cpp +++ b/utils/configtool/src/configtooldoc.cpp @@ -29,6 +29,7 @@ #endif #include "wx/textfile.h" +#include "wx/txtstrm.h" #include "wx/wfstream.h" #include "wx/config.h" #include "configtooldoc.h" @@ -175,7 +176,7 @@ bool ctConfigToolDoc::OnSaveDocument(const wxString& filename) // 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"); @@ -193,7 +194,7 @@ bool ctConfigToolDoc::OnSaveDocument(const wxString& filename) { wxRemoveFile(backupFilename); } - + // Copy the old file to the .bak if (leaveBackup) @@ -212,13 +213,13 @@ bool ctConfigToolDoc::OnSaveDocument(const wxString& filename) 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(); @@ -262,32 +263,36 @@ bool ctConfigToolDoc::OnOpenDocument(const wxString& filename) /// 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("\n"); stream << wxT(""); - DoSave(m_topItem, stream, 1); + DoSave(m_topItem, osFile, 1); stream << wxT("\n\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; @@ -313,12 +318,12 @@ bool ctConfigToolDoc::DoSave(ctConfigItem* item, wxOutputStream& stream, int ind indent ++; - OutputIndentation(stream, indent*2); + OutputIndentation(osFile, indent*2); if (item->IsActive()) stream << wxT("1"); else stream << wxT("0"); - OutputIndentation(stream, indent*2); + OutputIndentation(osFile, indent*2); if (item->IsEnabled()) stream << wxT("1"); else @@ -329,9 +334,9 @@ bool ctConfigToolDoc::DoSave(ctConfigItem* item, wxOutputStream& stream, int ind 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\""); @@ -345,7 +350,7 @@ bool ctConfigToolDoc::DoSave(ctConfigItem* item, wxOutputStream& stream, int ind stream << wxT(" choices=\"") << choices << wxT("\""); } } - + stream << wxT(">"); stream << ctEscapeHTMLCharacters(prop->GetVariant().GetString()) ; @@ -359,14 +364,14 @@ bool ctConfigToolDoc::DoSave(ctConfigItem* item, wxOutputStream& stream, int ind 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(""); return true; @@ -400,10 +405,10 @@ bool ctConfigToolDoc::DoOpen(const wxString& filename) 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) @@ -548,8 +553,11 @@ bool ctConfigToolDoc::DoOpen(wxSimpleHtmlTag* tag, ctConfigItem* parent) /// 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() ) @@ -569,6 +577,9 @@ void ctConfigToolDoc::RefreshDependencies() /// 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")); @@ -596,7 +607,7 @@ void ctConfigToolDoc::RefreshDependencies(ctConfigItem* item) // 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()); @@ -766,7 +777,7 @@ void ctConfigToolDoc::GenerateConfigureCommand(ctConfigItem* item, wxString& str { str << wxT(" ") << configureCommand; } - } + } } } @@ -908,7 +919,7 @@ bool ctConfigCommand::DoAndUndo(bool doCmd) // This will delete the old clipboard contents, if any. doc->SetClipboardItem(newItem); - + m_parent = m_activeState->GetParent(); m_insertBefore = m_activeState->FindNextSibling(); @@ -1076,7 +1087,7 @@ ctConfiguration::~ctConfiguration() wxGetApp().GetMainFrame()->GetDocument()->SetTopItem(NULL); } */ - + Clear(); } @@ -1244,5 +1255,3 @@ void ctConfiguration::DetachFromTree() } */ } - -