#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 tmp = wxFileSelector(_("Save As"),
+ wxString fileName = wxFileSelector(_("Save As"),
defaultDir,
wxFileNameFromPath(GetFilename()),
docTemplate->GetDefaultExtension(),
wxFD_SAVE | wxFD_OVERWRITE_PROMPT,
GetDocumentWindow());
- if (tmp.empty())
+ if (fileName.empty())
return false;
- wxString fileName(tmp);
- wxString path, name, ext;
- wxFileName::SplitPath(fileName, & path, & name, & ext);
+ wxString ext;
+ wxFileName::SplitPath(fileName, NULL, NULL, &ext);
if (ext.empty())
{
fileName += docTemplate->GetDefaultExtension();
}
- SetFilename(fileName);
- SetTitle(wxFileNameFromPath(fileName));
-
- // Notify the views that the filename has changed
- wxList::compatibility_iterator node = m_documentViews.GetFirst();
- while (node)
- {
- wxView *view = (wxView *)node->GetData();
- view->OnChangeFilename();
- node = node->GetNext();
- }
-
// Files that were not saved correctly are not added to the FileHistory.
- if (!OnSaveDocument(m_documentFile))
+ if (!OnSaveDocument(fileName))
return false;
+ SetTitle(wxFileNameFromPath(fileName));
+ SetFilename(fileName, true); // will call OnChangeFileName automatically
+
// A file that doesn't use the default extension of its document template cannot be opened
// via the FileHistory, so we do not add it.
if (docTemplate->FileMatchesTemplate(fileName))
(
wxString::Format
(
- _("Do you want to save changes to document %s?"),
+ _("Do you want to save changes to %s?"),
GetUserReadableName()
),
wxTheApp->GetAppDisplayName(),
- wxYES_NO | wxCANCEL | wxICON_QUESTION,
- GetDocumentWindow()
+ wxYES_NO | wxCANCEL | wxICON_QUESTION | wxCENTRE,
+ wxFindSuitableParent()
) )
{
case wxNO:
void wxDocument::SetFilename(const wxString& filename, bool notifyViews)
{
m_documentFile = filename;
+ OnChangeFilename(notifyViews);
+}
+
+void wxDocument::OnChangeFilename(bool notifyViews)
+{
if ( notifyViews )
{
// Notify the views that the filename has changed
if ( !store )
#else
wxFileInputStream store(file);
- if (store.GetLastError() != wxSTREAM_NO_ERROR)
+ if (store.GetLastError() != wxSTREAM_NO_ERROR || !store.IsOk())
#endif
{
wxLogError(_("File \"%s\" could not be opened for reading."), file);
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,
else
msgTitle = wxString(_("File error"));
- (void)wxMessageBox(_("Sorry, could not open this file."), msgTitle, wxOK | wxICON_EXCLAMATION,
+ (void)wxMessageBox(_("Sorry, could not open this file."), msgTitle, wxOK | wxICON_EXCLAMATION | wxCENTRE,
parent);
path = wxEmptyString;
return NULL;
}
- m_lastDirectory = wxPathOnly(pathTmp);
+
+ SetLastDirectory(wxPathOnly(pathTmp));
path = pathTmp;
// can only happen if the application changes the allowed templates in runtime.
(void)wxMessageBox(_("Sorry, the format for this file is unknown."),
_("Open File"),
- wxOK | wxICON_EXCLAMATION, wxFindSuitableParent());
+ wxOK | wxICON_EXCLAMATION | wxCENTRE, wxFindSuitableParent());
}
}
else