X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/b6e96faf3eb7b8bda2b1d7fc8aac4e212607da31..cbab1556578ae39b1f00e0c4f6ca8016ac8124ac:/src/common/docview.cpp diff --git a/src/common/docview.cpp b/src/common/docview.cpp index 11d6bca96d..6e1ef4c162 100644 --- a/src/common/docview.cpp +++ b/src/common/docview.cpp @@ -233,6 +233,18 @@ wxView *wxDocument::GetFirstView() const return static_cast(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; @@ -327,15 +339,6 @@ bool wxDocument::SaveAs() 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; @@ -343,16 +346,16 @@ bool wxDocument::SaveAs() 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) @@ -648,7 +651,8 @@ wxView::wxView() 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 @@ -713,7 +717,12 @@ void wxView::OnChangeFilename() 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) @@ -899,8 +908,6 @@ wxDocManager* wxDocManager::sm_docManager = NULL; wxDocManager::wxDocManager(long WXUNUSED(flags), bool initialize) { - wxASSERT_MSG( !sm_docManager, "multiple wxDocManagers not allowed" ); - sm_docManager = this; m_defaultDocumentNameCounter = 1; @@ -980,12 +987,35 @@ bool wxDocManager::Initialize() 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(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; @@ -1072,6 +1102,7 @@ void wxDocManager::OnPrint(wxCommandEvent& WXUNUSED(event)) void wxDocManager::OnPreview(wxCommandEvent& WXUNUSED(event)) { #if wxUSE_PRINTING_ARCHITECTURE + wxBusyCursor busy; wxView *view = GetActiveView(); if (!view) return; @@ -2213,7 +2244,11 @@ void wxFileHistory::AddFilesToMenu(wxMenu* menu) 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; @@ -2237,7 +2272,11 @@ bool wxTransferFileToStream(const wxString& filename, wxSTD ostream& stream) 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; @@ -2260,7 +2299,11 @@ bool wxTransferStreamToFile(wxSTD istream& stream, const wxString& filename) 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; @@ -2284,7 +2327,11 @@ bool wxTransferFileToStream(const wxString& filename, wxOutputStream& stream) 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;