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
This commit is contained in:
Włodzimierz Skiba
2005-04-04 18:48:35 +00:00
parent 57133d5cdb
commit 8d3261f9d9
2 changed files with 37 additions and 31 deletions

View File

@@ -29,6 +29,7 @@
#endif #endif
#include "wx/textfile.h" #include "wx/textfile.h"
#include "wx/txtstrm.h"
#include "wx/wfstream.h" #include "wx/wfstream.h"
#include "wx/config.h" #include "wx/config.h"
#include "configtooldoc.h" #include "configtooldoc.h"
@@ -262,32 +263,36 @@ bool ctConfigToolDoc::OnOpenDocument(const wxString& filename)
/// Save the settings file /// Save the settings file
bool ctConfigToolDoc::DoSave(const wxString& filename) bool ctConfigToolDoc::DoSave(const wxString& filename)
{ {
wxFileOutputStream stream(filename); wxFileOutputStream osFile(filename);
if (!stream.Ok()) if (!osFile.Ok())
return false; return false;
wxTextOutputStream stream(osFile);
stream << wxT("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"); stream << wxT("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n");
stream << wxT("<settings xmlns=\"http://www.wxwidgets.org/wxs\" version=\"2.5.0.1\">"); 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"); stream << wxT("\n</settings>\n");
return true; 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"); wxString str = wxT("\n");
for (int i = 0; i < indent; i++) for (int i = 0; i < indent; i++)
str << wxT(' ') << wxT(' '); str << wxT(" ");
stream << str ; stream << str ;
} }
/// Recursive helper function for file saving /// 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 name(item->GetName());
wxString s; wxString s;
@@ -313,12 +318,12 @@ bool ctConfigToolDoc::DoSave(ctConfigItem* item, wxOutputStream& stream, int ind
indent ++; indent ++;
OutputIndentation(stream, indent*2); OutputIndentation(osFile, indent*2);
if (item->IsActive()) if (item->IsActive())
stream << wxT("<active>1</active>"); stream << wxT("<active>1</active>");
else else
stream << wxT("<active>0</active>"); stream << wxT("<active>0</active>");
OutputIndentation(stream, indent*2); OutputIndentation(osFile, indent*2);
if (item->IsEnabled()) if (item->IsEnabled())
stream << wxT("<enabled>1</enabled>"); stream << wxT("<enabled>1</enabled>");
else else
@@ -329,7 +334,7 @@ bool ctConfigToolDoc::DoSave(ctConfigItem* item, wxOutputStream& stream, int ind
while (node) while (node)
{ {
ctProperty* prop = (ctProperty*) node->GetData(); ctProperty* prop = (ctProperty*) node->GetData();
OutputIndentation(stream, indent*2); OutputIndentation(osFile, indent*2);
stream << wxT("<") << prop->GetName() ; stream << wxT("<") << prop->GetName() ;
if (prop->IsCustom()) if (prop->IsCustom())
@@ -359,14 +364,14 @@ bool ctConfigToolDoc::DoSave(ctConfigItem* item, wxOutputStream& stream, int ind
while (node) while (node)
{ {
ctConfigItem* child = (ctConfigItem*) node->GetData(); ctConfigItem* child = (ctConfigItem*) node->GetData();
DoSave(child, stream, indent); DoSave(child, osFile, indent);
node = node->GetNext(); node = node->GetNext();
} }
indent --; indent --;
OutputIndentation(stream, indent*2); OutputIndentation(osFile, indent*2);
stream << wxT("</setting>"); stream << wxT("</setting>");
return true; return true;
@@ -400,7 +405,7 @@ bool ctConfigToolDoc::DoOpen(const wxString& filename)
static bool GetHtmlBoolValue(const wxString& value) 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; return true;
else else
return false; return false;
@@ -1250,5 +1255,3 @@ void ctConfiguration::DetachFromTree()
} }
*/ */
} }

View File

@@ -21,6 +21,7 @@
#endif #endif
#include "wx/wfstream.h" #include "wx/wfstream.h"
#include "wx/txtstrm.h"
#include "configtoolview.h" #include "configtoolview.h"
#include "configtooldoc.h" #include "configtooldoc.h"
#include "configtree.h" #include "configtree.h"
@@ -923,13 +924,14 @@ void ctConfigToolView::OnSaveSetupFile(wxCommandEvent& WXUNUSED(event))
wxString fullPath = dialog.GetPath(); wxString fullPath = dialog.GetPath();
wxGetApp().GetSettings().m_lastSetupSaveDir = wxPathOnly(fullPath); wxGetApp().GetSettings().m_lastSetupSaveDir = wxPathOnly(fullPath);
wxFileOutputStream stream(fullPath); wxFileOutputStream osFile(fullPath);
if (!stream.Ok()) if (!osFile.Ok())
{ {
wxMessageBox(_("Sorry, could not save this file."), _("Save Setup File"), wxICON_EXCLAMATION|wxOK); wxMessageBox(_("Sorry, could not save this file."), _("Save Setup File"), wxICON_EXCLAMATION|wxOK);
return; return;
} }
wxTextOutputStream stream(osFile);
stream << setupStr; stream << setupStr;
} }
} }
@@ -955,13 +957,14 @@ void ctConfigToolView::OnSaveConfigureCommand(wxCommandEvent& WXUNUSED(event))
wxString fullPath = dialog.GetPath(); wxString fullPath = dialog.GetPath();
wxGetApp().GetSettings().m_lastSetupSaveDir = wxPathOnly(fullPath); wxGetApp().GetSettings().m_lastSetupSaveDir = wxPathOnly(fullPath);
wxFileOutputStream stream(fullPath); wxFileOutputStream osFile(fullPath);
if (!stream.Ok()) if (!osFile.Ok())
{ {
wxMessageBox(_("Sorry, could not save this file."), _("Save Configure Command File"), wxICON_EXCLAMATION|wxOK); wxMessageBox(_("Sorry, could not save this file."), _("Save Configure Command File"), wxICON_EXCLAMATION|wxOK);
return; return;
} }
wxTextOutputStream stream(osFile);
stream << configureStr; stream << configureStr;
} }
} }