From 8d3261f9d950b23bcbab74a48572b07c4cfa1c16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?W=C5=82odzimierz=20Skiba?= Date: Mon, 4 Apr 2005 18:48:35 +0000 Subject: [PATCH] Fix for saving in Unicode mode (Bug #1172299). git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@33329 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- utils/configtool/src/configtooldoc.cpp | 57 +++++++++++++------------ utils/configtool/src/configtoolview.cpp | 11 +++-- 2 files changed, 37 insertions(+), 31 deletions(-) diff --git a/utils/configtool/src/configtooldoc.cpp b/utils/configtool/src/configtooldoc.cpp index 2fad2cf31e..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) @@ -602,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()); @@ -772,7 +777,7 @@ void ctConfigToolDoc::GenerateConfigureCommand(ctConfigItem* item, wxString& str { str << wxT(" ") << configureCommand; } - } + } } } @@ -914,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(); @@ -1082,7 +1087,7 @@ ctConfiguration::~ctConfiguration() wxGetApp().GetMainFrame()->GetDocument()->SetTopItem(NULL); } */ - + Clear(); } @@ -1250,5 +1255,3 @@ void ctConfiguration::DetachFromTree() } */ } - - diff --git a/utils/configtool/src/configtoolview.cpp b/utils/configtool/src/configtoolview.cpp index ab770e3f59..59668482b3 100644 --- a/utils/configtool/src/configtoolview.cpp +++ b/utils/configtool/src/configtoolview.cpp @@ -21,6 +21,7 @@ #endif #include "wx/wfstream.h" +#include "wx/txtstrm.h" #include "configtoolview.h" #include "configtooldoc.h" #include "configtree.h" @@ -923,13 +924,14 @@ void ctConfigToolView::OnSaveSetupFile(wxCommandEvent& WXUNUSED(event)) wxString fullPath = dialog.GetPath(); wxGetApp().GetSettings().m_lastSetupSaveDir = wxPathOnly(fullPath); - wxFileOutputStream stream(fullPath); - if (!stream.Ok()) + wxFileOutputStream osFile(fullPath); + if (!osFile.Ok()) { wxMessageBox(_("Sorry, could not save this file."), _("Save Setup File"), wxICON_EXCLAMATION|wxOK); return; } + wxTextOutputStream stream(osFile); stream << setupStr; } } @@ -955,13 +957,14 @@ void ctConfigToolView::OnSaveConfigureCommand(wxCommandEvent& WXUNUSED(event)) wxString fullPath = dialog.GetPath(); wxGetApp().GetSettings().m_lastSetupSaveDir = wxPathOnly(fullPath); - wxFileOutputStream stream(fullPath); - if (!stream.Ok()) + wxFileOutputStream osFile(fullPath); + if (!osFile.Ok()) { wxMessageBox(_("Sorry, could not save this file."), _("Save Configure Command File"), wxICON_EXCLAMATION|wxOK); return; } + wxTextOutputStream stream(osFile); stream << configureStr; } }