X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/9a83f860948059b0273b5cc6d9e43fadad3ebfca..b4c1fe36b9854cdb404906ba3a181a67f9247e0e:/src/common/docview.cpp diff --git a/src/common/docview.cpp b/src/common/docview.cpp index 8936703547..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; @@ -991,9 +998,9 @@ wxString wxDocManager::GetLastDirectory() const // 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 - wxString lastOpened = GetHistoryFile(0); - if ( !lastOpened.empty() ) + if ( m_fileHistory && m_fileHistory->GetCount() ) { + const wxString lastOpened = m_fileHistory->GetHistoryFile(0); const wxFileName fn(lastOpened); if ( fn.DirExists() ) { @@ -1001,6 +1008,7 @@ wxString wxDocManager::GetLastDirectory() const } //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 @@ -1094,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; @@ -2235,7 +2244,11 @@ void wxFileHistory::AddFilesToMenu(wxMenu* menu) bool wxTransferFileToStream(const wxString& filename, wxSTD ostream& stream) { +#if wxUSE_FFILE wxFFile file(filename, wxT("rb")); +#elif wxUSE_FILE + wxFile file(filename, wxFile::read); +#endif if ( !file.IsOpened() ) return false; @@ -2259,7 +2272,11 @@ bool wxTransferFileToStream(const wxString& filename, wxSTD ostream& stream) bool wxTransferStreamToFile(wxSTD istream& stream, const wxString& filename) { +#if wxUSE_FFILE wxFFile file(filename, wxT("wb")); +#elif wxUSE_FILE + wxFile file(filename, wxFile::write); +#endif if ( !file.IsOpened() ) return false; @@ -2282,7 +2299,11 @@ bool wxTransferStreamToFile(wxSTD istream& stream, const wxString& filename) bool wxTransferFileToStream(const wxString& filename, wxOutputStream& stream) { +#if wxUSE_FFILE wxFFile file(filename, wxT("rb")); +#elif wxUSE_FILE + wxFile file(filename, wxFile::read); +#endif if ( !file.IsOpened() ) return false; @@ -2306,7 +2327,11 @@ bool wxTransferFileToStream(const wxString& filename, wxOutputStream& stream) bool wxTransferStreamToFile(wxInputStream& stream, const wxString& filename) { +#if wxUSE_FFILE wxFFile file(filename, wxT("wb")); +#elif wxUSE_FILE + wxFile file(filename, wxFile::write); +#endif if ( !file.IsOpened() ) return false;