return static_cast<wxView *>(m_documentViews.GetFirst()->GetData());
}
+void wxDocument::Modify(bool mod)
+{
+ if (mod != m_documentModified)
+ {
+ m_documentModified = mod;
+
+ // Allow views to append asterix to the title
+ wxView* view = GetFirstView();
+ if (view) view->OnChangeFilename();
+ }
+}
+
wxDocManager *wxDocument::GetDocumentManager() const
{
return m_documentTemplate ? m_documentTemplate->GetDocumentManager() : NULL;
if (fileName.empty())
return false; // cancelled by user
- wxString ext;
- wxFileName::SplitPath(fileName, NULL, NULL, &ext);
-
- if (ext.empty())
- {
- fileName += wxT(".");
- fileName += docTemplate->GetDefaultExtension();
- }
-
// Files that were not saved correctly are not added to the FileHistory.
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))
- {
- GetDocumentManager()->AddFileToHistory(fileName);
- }
- //else: the user will probably not be able to open the file again, so we
- // could warn about the wrong file-extension here
+ // 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))
+ {
+ GetDocumentManager()->AddFileToHistory(fileName);
+ }
+ //else: the user will probably not be able to open the file again, so we
+ // could warn about the wrong file-extension here
- return true;
+ return true;
}
bool wxDocument::OnSaveDocument(const wxString& file)
wxView::~wxView()
{
- GetDocumentManager()->ActivateView(this, false);
+ if (m_viewDocument && GetDocumentManager())
+ GetDocumentManager()->ActivateView(this, false);
// reset our frame view first, before removing it from the document as
// SetView(NULL) is a simple call while RemoveView() may result in user
wxDocument *doc = GetDocument();
if (!doc) return;
- win->SetLabel(doc->GetUserReadableName());
+ wxString label = doc->GetUserReadableName();
+ if (doc->IsModified())
+ {
+ label += "*";
+ }
+ win->SetLabel(label);
}
void wxView::SetDocument(wxDocument *doc)
wxDocManager::wxDocManager(long WXUNUSED(flags), bool initialize)
{
- wxASSERT_MSG( !sm_docManager, "multiple wxDocManagers not allowed" );
-
sm_docManager = this;
m_defaultDocumentNameCounter = 1;
wxString wxDocManager::GetLastDirectory() const
{
- // use the system-dependent default location for the document files if
- // we're being opened for the first time
+ // if we haven't determined the last used directory yet, do it now
if ( m_lastDirectory.empty() )
{
+ // we're going to modify m_lastDirectory in this const method, so do it
+ // via non-const self pointer instead of const this one
wxDocManager * const self = const_cast<wxDocManager *>(this);
- self->m_lastDirectory = wxStandardPaths::Get().GetAppDocumentsDir();
+
+ // first try to reuse the directory of the most recently opened file:
+ // this ensures that if the user opens a file, closes the program and
+ // runs it again the "Open file" dialog will open in the directory of
+ // the last file he used
+ if ( m_fileHistory && m_fileHistory->GetCount() )
+ {
+ const wxString lastOpened = m_fileHistory->GetHistoryFile(0);
+ const wxFileName fn(lastOpened);
+ if ( fn.DirExists() )
+ {
+ self->m_lastDirectory = fn.GetPath();
+ }
+ //else: should we try the next one?
+ }
+ //else: no history yet
+
+ // if we don't have any files in the history (yet?), use the
+ // system-dependent default location for the document files
+ if ( m_lastDirectory.empty() )
+ {
+ self->m_lastDirectory = wxStandardPaths::Get().GetAppDocumentsDir();
+ }
}
return m_lastDirectory;
void wxDocManager::OnPreview(wxCommandEvent& WXUNUSED(event))
{
#if wxUSE_PRINTING_ARCHITECTURE
+ wxBusyCursor busy;
wxView *view = GetActiveView();
if (!view)
return;
bool wxTransferFileToStream(const wxString& filename, wxSTD ostream& stream)
{
- wxFFile file(filename, _T("rb"));
+#if wxUSE_FFILE
+ wxFFile file(filename, wxT("rb"));
+#elif wxUSE_FILE
+ wxFile file(filename, wxFile::read);
+#endif
if ( !file.IsOpened() )
return false;
bool wxTransferStreamToFile(wxSTD istream& stream, const wxString& filename)
{
- wxFFile file(filename, _T("wb"));
+#if wxUSE_FFILE
+ wxFFile file(filename, wxT("wb"));
+#elif wxUSE_FILE
+ wxFile file(filename, wxFile::write);
+#endif
if ( !file.IsOpened() )
return false;
bool wxTransferFileToStream(const wxString& filename, wxOutputStream& stream)
{
- wxFFile file(filename, _T("rb"));
+#if wxUSE_FFILE
+ wxFFile file(filename, wxT("rb"));
+#elif wxUSE_FILE
+ wxFile file(filename, wxFile::read);
+#endif
if ( !file.IsOpened() )
return false;
bool wxTransferStreamToFile(wxInputStream& stream, const wxString& filename)
{
- wxFFile file(filename, _T("wb"));
+#if wxUSE_FFILE
+ wxFFile file(filename, wxT("wb"));
+#elif wxUSE_FILE
+ wxFile file(filename, wxFile::write);
+#endif
if ( !file.IsOpened() )
return false;