#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"
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,
(
wxString::Format
(
- _("Do you want to save changes to document %s?"),
+ _("Do you want to save changes to %s?"),
GetUserReadableName()
),
wxTheApp->GetAppDisplayName(),
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<wxDocManager *>(this);
+ self->m_lastDirectory = wxStandardPaths::Get().GetAppDocumentsDir();
+ }
+
+ return m_lastDirectory;
+}
+
wxFileHistory *wxDocManager::OnCreateFileHistory()
{
return new wxFileHistory;
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)
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)
wxWindow* parent = wxFindSuitableParent();
wxString pathTmp = wxFileSelectorEx(_("Open File"),
- m_lastDirectory,
+ GetLastDirectory(),
wxEmptyString,
&FilterIndex,
descrBuf,
path = wxEmptyString;
return NULL;
}
- m_lastDirectory = wxPathOnly(pathTmp);
+
+ SetLastDirectory(wxPathOnly(pathTmp));
path = pathTmp;