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
#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("<?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;
@ -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("<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
@ -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("</setting>");
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()
}
*/
}

View File

@ -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;
}
}