X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/828c8f98d5346c58b8fa75b043fba7a2a007b337..bced985eb03eb774a1e5337ed8b1fa7d662d11a3:/samples/docview/doc.cpp diff --git a/samples/docview/doc.cpp b/samples/docview/doc.cpp index f43bbb1c13..4892856fe0 100644 --- a/samples/docview/doc.cpp +++ b/samples/docview/doc.cpp @@ -176,6 +176,24 @@ DocumentIstream& DoodleSegment::LoadObject(DocumentIstream& istream) IMPLEMENT_CLASS(wxTextDocument, wxDocument) +bool wxTextDocument::OnCreate(const wxString& path, long flags) +{ + if ( !wxDocument::OnCreate(path, flags) ) + return false; + + // subscribe to changes in the text control to update the document state + // when it's modified + GetTextCtrl()->Connect + ( + wxEVT_COMMAND_TEXT_UPDATED, + wxCommandEventHandler(wxTextDocument::OnTextChange), + NULL, + this + ); + + return true; +} + // Since text windows have their own method for saving to/loading from files, // we override DoSave/OpenDocument instead of Save/LoadObject bool wxTextDocument::DoSaveDocument(const wxString& filename) @@ -185,7 +203,13 @@ bool wxTextDocument::DoSaveDocument(const wxString& filename) bool wxTextDocument::DoOpenDocument(const wxString& filename) { - return GetTextCtrl()->LoadFile(filename); + if ( !GetTextCtrl()->LoadFile(filename) ) + return false; + + // we're not modified by the user yet + Modify(false); + + return true; } bool wxTextDocument::IsModified() const @@ -205,6 +229,13 @@ void wxTextDocument::Modify(bool modified) } } +void wxTextDocument::OnTextChange(wxCommandEvent& event) +{ + Modify(true); + + event.Skip(); +} + // ---------------------------------------------------------------------------- // TextEditDocument implementation // ----------------------------------------------------------------------------