diff --git a/contrib/include/wx/stc/stc.h b/contrib/include/wx/stc/stc.h index 41e36f3e8b..193376418f 100644 --- a/contrib/include/wx/stc/stc.h +++ b/contrib/include/wx/stc/stc.h @@ -2161,6 +2161,12 @@ public: bool GetLastKeydownProcessed() { return m_lastKeyDownConsumed; } void SetLastKeydownProcessed(bool val) { m_lastKeyDownConsumed = val; } + // Write the contents of the editor to filename + bool SaveFile(const wxString& filename); + + // Load the contents of filename into the editor + bool LoadFile(const wxString& filename); + //---------------------------------------------------------------------- diff --git a/contrib/src/stc/stc.cpp b/contrib/src/stc/stc.cpp index c4a9d0c4e1..d4fbcec50c 100644 --- a/contrib/src/stc/stc.cpp +++ b/contrib/src/stc/stc.cpp @@ -24,6 +24,7 @@ #include #include #include +#include //---------------------------------------------------------------------- @@ -474,7 +475,7 @@ void wxStyledTextCtrl::MarkerDefineBitmap(int markerNumber, const wxBitmap& bmp) buff[len] = 0; SendMsg(2049, markerNumber, (long)buff); delete [] buff; - + } // Set a margin to be either numeric or symbolic. @@ -857,7 +858,7 @@ void wxStyledTextCtrl::RegisterImage(int type, const wxBitmap& bmp) { buff[len] = 0; SendMsg(2405, type, (long)buff); delete [] buff; - + } // Clear all the registered images. @@ -2075,6 +2076,45 @@ 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) +{ + wxFile file(filename, wxFile::read); + + 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); + EmptyUndoBuffer(); + SetSavePoint(); + } + + return success; +} + //---------------------------------------------------------------------- // Event handlers diff --git a/contrib/src/stc/stc.cpp.in b/contrib/src/stc/stc.cpp.in index 6643474798..8952840b6c 100644 --- a/contrib/src/stc/stc.cpp.in +++ b/contrib/src/stc/stc.cpp.in @@ -24,6 +24,7 @@ #include #include #include +#include //---------------------------------------------------------------------- @@ -307,6 +308,45 @@ 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) +{ + wxFile file(filename, wxFile::read); + + 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); + EmptyUndoBuffer(); + SetSavePoint(); + } + + return success; +} + //---------------------------------------------------------------------- // Event handlers diff --git a/contrib/src/stc/stc.h.in b/contrib/src/stc/stc.h.in index baeaf0d437..70addc7abb 100644 --- a/contrib/src/stc/stc.h.in +++ b/contrib/src/stc/stc.h.in @@ -193,6 +193,12 @@ public: bool GetLastKeydownProcessed() { return m_lastKeyDownConsumed; } void SetLastKeydownProcessed(bool val) { m_lastKeyDownConsumed = val; } + // Write the contents of the editor to filename + bool SaveFile(const wxString& filename); + + // Load the contents of filename into the editor + bool LoadFile(const wxString& filename); + //---------------------------------------------------------------------- diff --git a/include/wx/stc/stc.h b/include/wx/stc/stc.h index 41e36f3e8b..193376418f 100644 --- a/include/wx/stc/stc.h +++ b/include/wx/stc/stc.h @@ -2161,6 +2161,12 @@ public: bool GetLastKeydownProcessed() { return m_lastKeyDownConsumed; } void SetLastKeydownProcessed(bool val) { m_lastKeyDownConsumed = val; } + // Write the contents of the editor to filename + bool SaveFile(const wxString& filename); + + // Load the contents of filename into the editor + bool LoadFile(const wxString& filename); + //---------------------------------------------------------------------- diff --git a/src/stc/stc.cpp b/src/stc/stc.cpp index c4a9d0c4e1..d4fbcec50c 100644 --- a/src/stc/stc.cpp +++ b/src/stc/stc.cpp @@ -24,6 +24,7 @@ #include #include #include +#include //---------------------------------------------------------------------- @@ -474,7 +475,7 @@ void wxStyledTextCtrl::MarkerDefineBitmap(int markerNumber, const wxBitmap& bmp) buff[len] = 0; SendMsg(2049, markerNumber, (long)buff); delete [] buff; - + } // Set a margin to be either numeric or symbolic. @@ -857,7 +858,7 @@ void wxStyledTextCtrl::RegisterImage(int type, const wxBitmap& bmp) { buff[len] = 0; SendMsg(2405, type, (long)buff); delete [] buff; - + } // Clear all the registered images. @@ -2075,6 +2076,45 @@ 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) +{ + wxFile file(filename, wxFile::read); + + 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); + EmptyUndoBuffer(); + SetSavePoint(); + } + + return success; +} + //---------------------------------------------------------------------- // Event handlers diff --git a/src/stc/stc.cpp.in b/src/stc/stc.cpp.in index 6643474798..8952840b6c 100644 --- a/src/stc/stc.cpp.in +++ b/src/stc/stc.cpp.in @@ -24,6 +24,7 @@ #include #include #include +#include //---------------------------------------------------------------------- @@ -307,6 +308,45 @@ 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) +{ + wxFile file(filename, wxFile::read); + + 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); + EmptyUndoBuffer(); + SetSavePoint(); + } + + return success; +} + //---------------------------------------------------------------------- // Event handlers diff --git a/src/stc/stc.h.in b/src/stc/stc.h.in index baeaf0d437..70addc7abb 100644 --- a/src/stc/stc.h.in +++ b/src/stc/stc.h.in @@ -193,6 +193,12 @@ public: bool GetLastKeydownProcessed() { return m_lastKeyDownConsumed; } void SetLastKeydownProcessed(bool val) { m_lastKeyDownConsumed = val; } + // Write the contents of the editor to filename + bool SaveFile(const wxString& filename); + + // Load the contents of filename into the editor + bool LoadFile(const wxString& filename); + //----------------------------------------------------------------------