+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;
wxDocManager *wxDocument::GetDocumentManager() const
{
return m_documentTemplate ? m_documentTemplate->GetDocumentManager() : NULL;
// Files that were not saved correctly are not added to the FileHistory.
if (!OnSaveDocument(fileName))
return false;
// 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
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
+ if ( wxMessageBox
+ (
+ _("Discard changes and reload the last saved version?"),
+ wxTheApp->GetAppDisplayName(),
+ wxYES_NO | wxCANCEL | wxICON_QUESTION,
+ GetDocumentWindow()
+ ) != wxYES )
+ return false;
+
+ if ( !DoOpenDocument(GetFilename()) )
+ return false;
+
+ Modify(false);
+ UpdateAllViews();
+
+ return true;
// reset our frame view first, before removing it from the document as
// SetView(NULL) is a simple call while RemoveView() may result in user
// reset our frame view first, before removing it from the document as
// SetView(NULL) is a simple call while RemoveView() may result in user
EVT_UPDATE_UI(wxID_OPEN, wxDocManager::OnUpdateFileOpen)
EVT_UPDATE_UI(wxID_CLOSE, wxDocManager::OnUpdateDisableIfNoDoc)
EVT_UPDATE_UI(wxID_CLOSE_ALL, wxDocManager::OnUpdateDisableIfNoDoc)
EVT_UPDATE_UI(wxID_OPEN, wxDocManager::OnUpdateFileOpen)
EVT_UPDATE_UI(wxID_CLOSE, wxDocManager::OnUpdateDisableIfNoDoc)
EVT_UPDATE_UI(wxID_CLOSE_ALL, wxDocManager::OnUpdateDisableIfNoDoc)
EVT_UPDATE_UI(wxID_NEW, wxDocManager::OnUpdateFileNew)
EVT_UPDATE_UI(wxID_SAVE, wxDocManager::OnUpdateFileSave)
EVT_UPDATE_UI(wxID_SAVEAS, wxDocManager::OnUpdateDisableIfNoDoc)
EVT_UPDATE_UI(wxID_NEW, wxDocManager::OnUpdateFileNew)
EVT_UPDATE_UI(wxID_SAVE, wxDocManager::OnUpdateFileSave)
EVT_UPDATE_UI(wxID_SAVEAS, wxDocManager::OnUpdateDisableIfNoDoc)
// 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
// 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 we don't have any files in the history (yet?), use the
// system-dependent default location for the document files
// if we don't have any files in the history (yet?), use the
// system-dependent default location for the document files
+#if wxUSE_PRINTING_ARCHITECTURE
+wxPreviewFrame* wxDocManager::CreatePreviewFrame(wxPrintPreviewBase* preview,
+ wxWindow *parent,
+ const wxString& title)
+{
+ return new wxPreviewFrame(preview, parent, title);
+}
+#endif // wxUSE_PRINTING_ARCHITECTURE
+
- wxPreviewFrame *
- frame = new wxPreviewFrame(preview, wxTheApp->GetTopWindow(),
- _("Print Preview"));
+ wxPreviewFrame* frame = CreatePreviewFrame(preview,
+ wxTheApp->GetTopWindow(),
+ _("Print Preview"));
+ wxCHECK_RET( frame, "should create a print preview frame" );
+
void wxDocManager::OnUpdateFileNew(wxUpdateUIEvent& event)
{
// CreateDocument() (which is called from OnFileNew) may succeed
void wxDocManager::OnUpdateFileNew(wxUpdateUIEvent& event)
{
// CreateDocument() (which is called from OnFileNew) may succeed
- if ( event.CanVeto() && !m_childView->Close(false) )
+ // notice that we must call wxView::Close() and OnClose() called from
+ // it in any case, even if we know that we are going to close anyhow
+ if ( !m_childView->Close(false) && event.CanVeto() )