X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/00e3ea1c6f5e52509f52e427a8aaae3ffb534f88..713e92905e4c463be1cd8b2b626aec8ffa166420:/src/common/docview.cpp?ds=sidebyside diff --git a/src/common/docview.cpp b/src/common/docview.cpp index b9eac57233..851d5a4c31 100644 --- a/src/common/docview.cpp +++ b/src/common/docview.cpp @@ -56,6 +56,7 @@ #include "wx/cmdproc.h" #include "wx/tokenzr.h" #include "wx/filename.h" +#include "wx/stdpaths.h" #include "wx/vector.h" #include "wx/ptr_scpd.h" @@ -307,8 +308,12 @@ bool wxDocument::SaveAs() wxString filter = docTemplate->GetFileFilter() ; #endif wxString defaultDir = docTemplate->GetDirectory(); - if (defaultDir.IsEmpty()) + if ( defaultDir.empty() ) + { defaultDir = wxPathOnly(GetFilename()); + if ( defaultDir.empty() ) + defaultDir = GetDocumentManager()->GetLastDirectory(); + } wxString fileName = wxFileSelector(_("Save As"), defaultDir, @@ -938,6 +943,19 @@ bool wxDocManager::Initialize() return true; } +wxString wxDocManager::GetLastDirectory() const +{ + // use the system-dependent default location for the document files if + // we're being opened for the first time + if ( m_lastDirectory.empty() ) + { + wxDocManager * const self = const_cast(this); + self->m_lastDirectory = wxStandardPaths::Get().GetAppDocumentsDir(); + } + + return m_lastDirectory; +} + wxFileHistory *wxDocManager::OnCreateFileHistory() { return new wxFileHistory; @@ -1070,7 +1088,9 @@ void wxDocManager::OnRedo(wxCommandEvent& event) void wxDocManager::OnUpdateFileOpen(wxUpdateUIEvent& event) { - event.Enable( true ); + // CreateDocument() (which is called from OnFileOpen) may succeed + // only when there is at least a template: + event.Enable( GetTemplates().GetCount()>0 ); } void wxDocManager::OnUpdateDisableIfNoDoc(wxUpdateUIEvent& event) @@ -1080,7 +1100,9 @@ void wxDocManager::OnUpdateDisableIfNoDoc(wxUpdateUIEvent& event) void wxDocManager::OnUpdateFileNew(wxUpdateUIEvent& event) { - event.Enable( true ); + // CreateDocument() (which is called from OnFileNew) may succeed + // only when there is at least a template: + event.Enable( GetTemplates().GetCount()>0 ); } void wxDocManager::OnUpdateFileSave(wxUpdateUIEvent& event) @@ -1486,7 +1508,7 @@ wxDocTemplate *wxDocManager::SelectDocumentPath(wxDocTemplate **templates, wxWindow* parent = wxFindSuitableParent(); wxString pathTmp = wxFileSelectorEx(_("Open File"), - m_lastDirectory, + GetLastDirectory(), wxEmptyString, &FilterIndex, descrBuf, @@ -1510,7 +1532,8 @@ wxDocTemplate *wxDocManager::SelectDocumentPath(wxDocTemplate **templates, path = wxEmptyString; return NULL; } - m_lastDirectory = wxPathOnly(pathTmp); + + SetLastDirectory(wxPathOnly(pathTmp)); path = pathTmp;