X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/9e730a78765d0e70ca5b77512569c94585070fe2..1978421a6d8b81c1f8a961da4b8ddf544fec7b1b:/src/stc/stc.cpp.in diff --git a/src/stc/stc.cpp.in b/src/stc/stc.cpp.in index 6643474798..60360d977e 100644 --- a/src/stc/stc.cpp.in +++ b/src/stc/stc.cpp.in @@ -24,6 +24,7 @@ #include #include #include +#include //---------------------------------------------------------------------- @@ -307,6 +308,51 @@ void wxStyledTextCtrl::ScrollToColumn(int column) { } +bool wxStyledTextCtrl::SaveFile(const wxString& filename) +{ + wxFile file(filename, wxFile::write); + + if (!file.IsOpened()) + return FALSE; + + bool success = file.Write(GetText()); + + if (success) + SetSavePoint(); + + return success; +} + +bool wxStyledTextCtrl::LoadFile(const wxString& filename) +{ + bool success = false; + wxFile file(filename, wxFile::read); + + if (file.IsOpened()) + { + wxString contents; + off_t len = file.Length(); + + 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; +} + //---------------------------------------------------------------------- // Event handlers