Check for and allow zero length files
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@21517 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
parent
7142ac377a
commit
041973c55e
@ -2093,23 +2093,29 @@ bool wxStyledTextCtrl::SaveFile(const wxString& filename)
|
|||||||
|
|
||||||
bool wxStyledTextCtrl::LoadFile(const wxString& filename)
|
bool wxStyledTextCtrl::LoadFile(const wxString& filename)
|
||||||
{
|
{
|
||||||
|
bool success = false;
|
||||||
wxFile file(filename, wxFile::read);
|
wxFile file(filename, wxFile::read);
|
||||||
|
|
||||||
if (!file.IsOpened())
|
if (file.IsOpened())
|
||||||
return FALSE;
|
|
||||||
|
|
||||||
wxString contents;
|
|
||||||
off_t len = file.Length();
|
|
||||||
|
|
||||||
wxChar *buf = contents.GetWriteBuf(len);
|
|
||||||
bool success = (file.Read(buf, len) == len);
|
|
||||||
contents.UngetWriteBuf();
|
|
||||||
|
|
||||||
if (success)
|
|
||||||
{
|
{
|
||||||
SetText(contents);
|
wxString contents;
|
||||||
EmptyUndoBuffer();
|
off_t len = file.Length();
|
||||||
SetSavePoint();
|
|
||||||
|
if (len > 0)
|
||||||
|
{
|
||||||
|
wxChar *buf = contents.GetWriteBuf(len);
|
||||||
|
success = (file.Read(buf, len) == len);
|
||||||
|
contents.UngetWriteBuf();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
success = true; // empty file is ok
|
||||||
|
|
||||||
|
if (success)
|
||||||
|
{
|
||||||
|
SetText(contents);
|
||||||
|
EmptyUndoBuffer();
|
||||||
|
SetSavePoint();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return success;
|
return success;
|
||||||
|
@ -325,23 +325,29 @@ bool wxStyledTextCtrl::SaveFile(const wxString& filename)
|
|||||||
|
|
||||||
bool wxStyledTextCtrl::LoadFile(const wxString& filename)
|
bool wxStyledTextCtrl::LoadFile(const wxString& filename)
|
||||||
{
|
{
|
||||||
|
bool success = false;
|
||||||
wxFile file(filename, wxFile::read);
|
wxFile file(filename, wxFile::read);
|
||||||
|
|
||||||
if (!file.IsOpened())
|
if (file.IsOpened())
|
||||||
return FALSE;
|
|
||||||
|
|
||||||
wxString contents;
|
|
||||||
off_t len = file.Length();
|
|
||||||
|
|
||||||
wxChar *buf = contents.GetWriteBuf(len);
|
|
||||||
bool success = (file.Read(buf, len) == len);
|
|
||||||
contents.UngetWriteBuf();
|
|
||||||
|
|
||||||
if (success)
|
|
||||||
{
|
{
|
||||||
SetText(contents);
|
wxString contents;
|
||||||
EmptyUndoBuffer();
|
off_t len = file.Length();
|
||||||
SetSavePoint();
|
|
||||||
|
if (len > 0)
|
||||||
|
{
|
||||||
|
wxChar *buf = contents.GetWriteBuf(len);
|
||||||
|
success = (file.Read(buf, len) == len);
|
||||||
|
contents.UngetWriteBuf();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
success = true; // empty file is ok
|
||||||
|
|
||||||
|
if (success)
|
||||||
|
{
|
||||||
|
SetText(contents);
|
||||||
|
EmptyUndoBuffer();
|
||||||
|
SetSavePoint();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return success;
|
return success;
|
||||||
|
@ -2093,23 +2093,29 @@ bool wxStyledTextCtrl::SaveFile(const wxString& filename)
|
|||||||
|
|
||||||
bool wxStyledTextCtrl::LoadFile(const wxString& filename)
|
bool wxStyledTextCtrl::LoadFile(const wxString& filename)
|
||||||
{
|
{
|
||||||
|
bool success = false;
|
||||||
wxFile file(filename, wxFile::read);
|
wxFile file(filename, wxFile::read);
|
||||||
|
|
||||||
if (!file.IsOpened())
|
if (file.IsOpened())
|
||||||
return FALSE;
|
|
||||||
|
|
||||||
wxString contents;
|
|
||||||
off_t len = file.Length();
|
|
||||||
|
|
||||||
wxChar *buf = contents.GetWriteBuf(len);
|
|
||||||
bool success = (file.Read(buf, len) == len);
|
|
||||||
contents.UngetWriteBuf();
|
|
||||||
|
|
||||||
if (success)
|
|
||||||
{
|
{
|
||||||
SetText(contents);
|
wxString contents;
|
||||||
EmptyUndoBuffer();
|
off_t len = file.Length();
|
||||||
SetSavePoint();
|
|
||||||
|
if (len > 0)
|
||||||
|
{
|
||||||
|
wxChar *buf = contents.GetWriteBuf(len);
|
||||||
|
success = (file.Read(buf, len) == len);
|
||||||
|
contents.UngetWriteBuf();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
success = true; // empty file is ok
|
||||||
|
|
||||||
|
if (success)
|
||||||
|
{
|
||||||
|
SetText(contents);
|
||||||
|
EmptyUndoBuffer();
|
||||||
|
SetSavePoint();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return success;
|
return success;
|
||||||
|
@ -325,23 +325,29 @@ bool wxStyledTextCtrl::SaveFile(const wxString& filename)
|
|||||||
|
|
||||||
bool wxStyledTextCtrl::LoadFile(const wxString& filename)
|
bool wxStyledTextCtrl::LoadFile(const wxString& filename)
|
||||||
{
|
{
|
||||||
|
bool success = false;
|
||||||
wxFile file(filename, wxFile::read);
|
wxFile file(filename, wxFile::read);
|
||||||
|
|
||||||
if (!file.IsOpened())
|
if (file.IsOpened())
|
||||||
return FALSE;
|
|
||||||
|
|
||||||
wxString contents;
|
|
||||||
off_t len = file.Length();
|
|
||||||
|
|
||||||
wxChar *buf = contents.GetWriteBuf(len);
|
|
||||||
bool success = (file.Read(buf, len) == len);
|
|
||||||
contents.UngetWriteBuf();
|
|
||||||
|
|
||||||
if (success)
|
|
||||||
{
|
{
|
||||||
SetText(contents);
|
wxString contents;
|
||||||
EmptyUndoBuffer();
|
off_t len = file.Length();
|
||||||
SetSavePoint();
|
|
||||||
|
if (len > 0)
|
||||||
|
{
|
||||||
|
wxChar *buf = contents.GetWriteBuf(len);
|
||||||
|
success = (file.Read(buf, len) == len);
|
||||||
|
contents.UngetWriteBuf();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
success = true; // empty file is ok
|
||||||
|
|
||||||
|
if (success)
|
||||||
|
{
|
||||||
|
SetText(contents);
|
||||||
|
EmptyUndoBuffer();
|
||||||
|
SetSavePoint();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return success;
|
return success;
|
||||||
|
Loading…
Reference in New Issue
Block a user