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:
@@ -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"
|
||||||
@@ -175,7 +176,7 @@ bool ctConfigToolDoc::OnSaveDocument(const wxString& filename)
|
|||||||
// This is the backup filename
|
// This is the backup filename
|
||||||
wxString backupFilename(filename);
|
wxString backupFilename(filename);
|
||||||
backupFilename += wxT(".bak");
|
backupFilename += wxT(".bak");
|
||||||
|
|
||||||
// This is the temporary copy of the backup
|
// This is the temporary copy of the backup
|
||||||
wxString tempFilename(filename);
|
wxString tempFilename(filename);
|
||||||
tempFilename += wxT(".tmp");
|
tempFilename += wxT(".tmp");
|
||||||
@@ -193,7 +194,7 @@ bool ctConfigToolDoc::OnSaveDocument(const wxString& filename)
|
|||||||
{
|
{
|
||||||
wxRemoveFile(backupFilename);
|
wxRemoveFile(backupFilename);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Copy the old file to the .bak
|
// Copy the old file to the .bak
|
||||||
|
|
||||||
if (leaveBackup)
|
if (leaveBackup)
|
||||||
@@ -212,13 +213,13 @@ bool ctConfigToolDoc::OnSaveDocument(const wxString& filename)
|
|||||||
if (wxFileExists(filename))
|
if (wxFileExists(filename))
|
||||||
wxRemoveFile(filename);
|
wxRemoveFile(filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Finally, copy the temporary file to the proper filename
|
// Finally, copy the temporary file to the proper filename
|
||||||
if (!wxRenameFile(tempFilename, filename))
|
if (!wxRenameFile(tempFilename, filename))
|
||||||
{
|
{
|
||||||
wxCopyFile(tempFilename, filename);
|
wxCopyFile(tempFilename, filename);
|
||||||
wxRemoveFile(tempFilename);
|
wxRemoveFile(tempFilename);
|
||||||
}
|
}
|
||||||
|
|
||||||
Modify(false);
|
Modify(false);
|
||||||
((ctConfigToolView*)GetFirstView())->OnChangeFilename();
|
((ctConfigToolView*)GetFirstView())->OnChangeFilename();
|
||||||
@@ -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,9 +334,9 @@ 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())
|
||||||
{
|
{
|
||||||
stream << wxT(" custom=\"true\"");
|
stream << wxT(" custom=\"true\"");
|
||||||
@@ -345,7 +350,7 @@ bool ctConfigToolDoc::DoSave(ctConfigItem* item, wxOutputStream& stream, int ind
|
|||||||
stream << wxT(" choices=\"") << choices << wxT("\"");
|
stream << wxT(" choices=\"") << choices << wxT("\"");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
stream << wxT(">");
|
stream << wxT(">");
|
||||||
|
|
||||||
stream << ctEscapeHTMLCharacters(prop->GetVariant().GetString()) ;
|
stream << ctEscapeHTMLCharacters(prop->GetVariant().GetString()) ;
|
||||||
@@ -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,10 +405,10 @@ 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int GetHtmlIntegerValue(const wxString& value)
|
static int GetHtmlIntegerValue(const wxString& value)
|
||||||
@@ -602,7 +607,7 @@ void ctConfigToolDoc::RefreshDependencies(ctConfigItem* item)
|
|||||||
// parent is a check or radio group.
|
// parent is a check or radio group.
|
||||||
ctConfigItem* parent = item->GetParent();
|
ctConfigItem* parent = item->GetParent();
|
||||||
if (parent &&
|
if (parent &&
|
||||||
(parent->GetType() == ctTypeCheckGroup ||
|
(parent->GetType() == ctTypeCheckGroup ||
|
||||||
parent->GetType() == ctTypeRadioGroup))
|
parent->GetType() == ctTypeRadioGroup))
|
||||||
requiresArr.Add(parent->GetName());
|
requiresArr.Add(parent->GetName());
|
||||||
|
|
||||||
@@ -772,7 +777,7 @@ void ctConfigToolDoc::GenerateConfigureCommand(ctConfigItem* item, wxString& str
|
|||||||
{
|
{
|
||||||
str << wxT(" ") << configureCommand;
|
str << wxT(" ") << configureCommand;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -914,7 +919,7 @@ bool ctConfigCommand::DoAndUndo(bool doCmd)
|
|||||||
|
|
||||||
// This will delete the old clipboard contents, if any.
|
// This will delete the old clipboard contents, if any.
|
||||||
doc->SetClipboardItem(newItem);
|
doc->SetClipboardItem(newItem);
|
||||||
|
|
||||||
m_parent = m_activeState->GetParent();
|
m_parent = m_activeState->GetParent();
|
||||||
m_insertBefore = m_activeState->FindNextSibling();
|
m_insertBefore = m_activeState->FindNextSibling();
|
||||||
|
|
||||||
@@ -1082,7 +1087,7 @@ ctConfiguration::~ctConfiguration()
|
|||||||
wxGetApp().GetMainFrame()->GetDocument()->SetTopItem(NULL);
|
wxGetApp().GetMainFrame()->GetDocument()->SetTopItem(NULL);
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
Clear();
|
Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1250,5 +1255,3 @@ void ctConfiguration::DetachFromTree()
|
|||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user