Fixed 'saving read-only files fails silently' bug. Updated about box for 1.1.0.2.

This commit is contained in:
Gerald Schmidt 2007-09-13 06:40:58 +00:00
parent aba51977cd
commit e4ece4ad0f
1 changed files with 40 additions and 64 deletions

View File

@ -3326,11 +3326,6 @@ void MyFrame::save()
if ( ( doc = getActiveDocument() ) == NULL ) if ( ( doc = getActiveDocument() ) == NULL )
return; return;
/*
if (!doc->GetModify())
return;
*/
wxString fileName; wxString fileName;
if ( ( fileName = doc->getFullFileName() ) == _T ( "" ) ) if ( ( fileName = doc->getFullFileName() ) == _T ( "" ) )
{ {
@ -4204,69 +4199,10 @@ void MyFrame::OnEncoding ( wxCommandEvent& event )
return; return;
} }
/*
if (wl->getLastError().empty())
{
doc->SetTextRaw(xur->getBuffer().c_str());
}
else
{
std::string err = wl->getLastError();
wxString wideErr;
wideErr = _("Cannot set encoding: ");
wideErr += wxString(err.c_str(), wxConvUTF8, err.size());
messagePane(wideErr, CONST_STOP);
}
*/
doc->SetTextRaw ( xur->getBuffer().c_str() ); doc->SetTextRaw ( xur->getBuffer().c_str() );
doc->SetFocus(); doc->SetFocus();
} }
/*
std::string MyFrame::getEncodedBuffer(
const std::string& bufferUtf8,
const std::string& encodingUtf8)
{
WrapTempFileName tempFileName(_T(""));
std::auto_ptr<WrapLibxml> wl(new WrapLibxml(libxmlNetAccess));
int res;
// change to saveEncodingFromFile?
res = wl->saveEncoding(bufferUtf8, tempFileName.name(), encodingUtf8);
if (res == -1)
{
std::string error = wl->getLastError();
wxString wideError = wxString(error.c_str(), wxConvUTF8, error.size());
wideError.Prepend(_("Cannot set encoding: "));
messagePane(wideError, CONST_STOP);
return "";
}
std::string newBuffer;
bool success = ReadFile::run(tempFileName.name(), newBuffer);
if (!success)
{
messagePane(_("Cannot set encoding (cannot open temporary file)"),
CONST_STOP);
return "";
}
std::auto_ptr<XmlUtf8Reader> xur(new XmlUtf8Reader(
false,
expandInternalEntities,
newBuffer.size()));
if (!xur->parse(newBuffer))
{
messagePane(_("Cannot set encoding (cannot parse temporary file)"),
CONST_STOP);
return "";
}
return xur->getBuffer().c_str();
}
*/
void MyFrame::OnHome ( wxCommandEvent& event ) void MyFrame::OnHome ( wxCommandEvent& event )
{ {
navigate ( _T ( "http://xml-copy-editor.sourceforge.net" ) ); navigate ( _T ( "http://xml-copy-editor.sourceforge.net" ) );
@ -4603,12 +4539,27 @@ bool MyFrame::saveFile ( XmlDoc *doc, wxString& fileName, bool checkLastModified
success = saveRawUtf8 ( fileNameLocal, utf8Buffer, true, isXml ); success = saveRawUtf8 ( fileNameLocal, utf8Buffer, true, isXml );
if ( success ) if ( success )
bytes = utf8Buffer.size(); bytes = utf8Buffer.size();
else
{
wxString message;
message.Printf ( _ ( "Cannot save %s" ), fileName.c_str() );
messagePane ( message, CONST_STOP );
return false;
}
} }
else if ( !isXml && encoding.empty() ) else if ( !isXml && encoding.empty() )
{ {
success = saveRawUtf8 ( fileNameLocal, utf8Buffer, true, isXml ); success = saveRawUtf8 ( fileNameLocal, utf8Buffer, true, isXml );
if ( success ) if ( success )
bytes = utf8Buffer.size(); bytes = utf8Buffer.size();
else
{
wxString message;
message.Printf ( _ ( "Cannot save %s" ), fileName.c_str() );
messagePane ( message, CONST_STOP );
return false;
}
} }
else if ( encoding == "UTF-8" ) else if ( encoding == "UTF-8" )
{ {
@ -4625,6 +4576,13 @@ bool MyFrame::saveFile ( XmlDoc *doc, wxString& fileName, bool checkLastModified
success = saveRawUtf8 ( fileNameLocal, utf8Buffer, true, isXml ); success = saveRawUtf8 ( fileNameLocal, utf8Buffer, true, isXml );
if ( success ) if ( success )
bytes = utf8Buffer.size(); bytes = utf8Buffer.size();
else
{
wxString message;
message.Printf ( _ ( "Cannot save %s" ), fileName.c_str() );
messagePane ( message, CONST_STOP );
return false;
}
} }
else else
{ {
@ -4650,7 +4608,12 @@ bool MyFrame::saveFile ( XmlDoc *doc, wxString& fileName, bool checkLastModified
messagePane ( message, CONST_WARNING ); messagePane ( message, CONST_WARNING );
} }
else else
{
wxString message;
message.Printf ( _ ( "Cannot save %s" ), fileName.c_str() );
messagePane ( message, CONST_STOP );
return false; return false;
}
} }
else else
{ {
@ -4719,6 +4682,9 @@ bool MyFrame::saveFile ( XmlDoc *doc, wxString& fileName, bool checkLastModified
} }
else else
{ {
wxString message;
message.Printf ( _ ( "Cannot save %s" ), fileName.c_str() );
messagePane ( message, CONST_STOP );
return false; return false;
} }
} }
@ -4730,6 +4696,9 @@ bool MyFrame::saveFile ( XmlDoc *doc, wxString& fileName, bool checkLastModified
if ( !ofs ) if ( !ofs )
{ {
delete[] finalBuffer; delete[] finalBuffer;
wxString message;
message.Printf ( _ ( "Cannot save %s" ), fileName.c_str() );
messagePane ( message, CONST_STOP );
return false; return false;
} }
@ -4768,6 +4737,13 @@ bool MyFrame::saveFile ( XmlDoc *doc, wxString& fileName, bool checkLastModified
wideEncoding.c_str(), wideError.c_str() ); wideEncoding.c_str(), wideError.c_str() );
messagePane ( msg, CONST_INFO ); messagePane ( msg, CONST_INFO );
} }
else
{
wxString message;
message.Printf ( _ ( "Cannot save %s" ), fileName.c_str() );
messagePane ( message, CONST_STOP );
return false;
}
} }
else else
bytes = result; bytes = result;