From de56f24082e4b66dada7bfe4033e1ef7328052ca Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Wed, 29 Oct 2008 16:23:25 +0000 Subject: [PATCH] added wxDocument::AlreadySaved() and use it in OnUpdateFileSave() to ensure that the "Save" menu item is enabled for new documents, even although they're not modified yet (otherwise the standard Ctrl-S key doesn't work in this case which is pretty annoying) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@56581 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/docview.h | 5 +++++ interface/wx/docview.h | 16 ++++++++++++++++ src/common/docview.cpp | 6 +++--- 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/include/wx/docview.h b/include/wx/docview.h index cbac917..a0fe1c4 100644 --- a/include/wx/docview.h +++ b/include/wx/docview.h @@ -78,6 +78,11 @@ public: bool GetDocumentSaved() const { return m_savedYet; } void SetDocumentSaved(bool saved = true) { m_savedYet = saved; } + // return true if the document hasn't been modified since the last time it + // was saved (implying that it returns false if it was never saved, even if + // the document is not modified) + bool AlreadySaved() const { return !IsModified() && GetDocumentSaved(); } + virtual bool Close(); virtual bool Save(); virtual bool SaveAs(); diff --git a/interface/wx/docview.h b/interface/wx/docview.h index 55effdd..33806cf 100644 --- a/interface/wx/docview.h +++ b/interface/wx/docview.h @@ -1009,6 +1009,22 @@ public: virtual bool AddView(wxView* view); /** + Returns true if the document hasn't been modified since the last time + it had been saved. + + Notice that this function returns @false if the document had been never + saved at all, so it may be also used to test whether it makes sense to + save the document: if it returns @true, there is nothing to save but if + @false is returned, it can be saved, even if it might be not modified + (this can be used to create an empty document file by the user). + + @see IsModified(), GetDocumentSaved() + + @since 2.9.0 + */ + bool AlreadySaved() const; + + /** Closes the document, by calling OnSaveModified() and then (if this returned @true) OnCloseDocument(). This does not normally delete the document object, use DeleteAllViews() to do this implicitly. diff --git a/src/common/docview.cpp b/src/common/docview.cpp index db67b46..dbc0e56 100644 --- a/src/common/docview.cpp +++ b/src/common/docview.cpp @@ -259,7 +259,7 @@ bool wxDocument::OnNewDocument() bool wxDocument::Save() { - if (!IsModified() && m_savedYet) + if ( AlreadySaved() ) return true; if ( m_documentFile.empty() || !m_savedYet ) @@ -1094,8 +1094,8 @@ void wxDocManager::OnUpdateFileNew(wxUpdateUIEvent& event) void wxDocManager::OnUpdateFileSave(wxUpdateUIEvent& event) { - wxDocument *doc = GetCurrentDocument(); - event.Enable( doc && doc->IsModified() ); + wxDocument * const doc = GetCurrentDocument(); + event.Enable( doc && !doc->AlreadySaved() ); } void wxDocManager::OnUpdateUndo(wxUpdateUIEvent& event) -- 2.7.4