X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/d06a66f52670ed5258b6a1dcf52ed5cd3a06ae1a..4e3ad7c095f0a047b48445d76316fc20f394f3e9:/src/common/docview.cpp diff --git a/src/common/docview.cpp b/src/common/docview.cpp index 95b9f93b46..78f6ea18ef 100644 --- a/src/common/docview.cpp +++ b/src/common/docview.cpp @@ -40,6 +40,7 @@ #include "wx/list.h" #include "wx/filedlg.h" #include "wx/intl.h" + #include "wx/log.h" #endif @@ -164,6 +165,8 @@ bool wxDocument::Close() bool wxDocument::OnCloseDocument() { + // Tell all views that we're about to close + NotifyClosing(); DeleteContents(); Modify(FALSE); return TRUE; @@ -341,7 +344,8 @@ bool wxDocument::OnOpenDocument(const wxString& file) return FALSE; } #if wxUSE_STD_IOSTREAM - if (!LoadObject(store)) + LoadObject(store); + if ( !store && !store.eof() ) #else int res = LoadObject(store).LastError(); if ((res != wxSTREAM_NOERROR) && @@ -507,6 +511,17 @@ void wxDocument::UpdateAllViews(wxView *sender, wxObject *hint) } } +void wxDocument::NotifyClosing() +{ + wxNode *node = m_documentViews.First(); + while (node) + { + wxView *view = (wxView *)node->Data(); + view->OnClosingDocument(); + node = node->Next(); + } +} + void wxDocument::SetFilename(const wxString& filename, bool notifyViews) { m_documentFile = filename; @@ -593,7 +608,7 @@ bool wxView::Close(bool deleteWindow) void wxView::Activate(bool activate) { - if (GetDocumentManager()) + if (GetDocument() && GetDocumentManager()) { OnActivateView(activate, this, GetDocumentManager()->GetCurrentView()); GetDocumentManager()->ActivateView(this, activate); @@ -698,6 +713,7 @@ bool wxDocTemplate::FileMatchesTemplate(const wxString& path) BEGIN_EVENT_TABLE(wxDocManager, wxEvtHandler) EVT_MENU(wxID_OPEN, wxDocManager::OnFileOpen) EVT_MENU(wxID_CLOSE, wxDocManager::OnFileClose) + EVT_MENU(wxID_CLOSE_ALL, wxDocManager::OnFileCloseAll) EVT_MENU(wxID_REVERT, wxDocManager::OnFileRevert) EVT_MENU(wxID_NEW, wxDocManager::OnFileNew) EVT_MENU(wxID_SAVE, wxDocManager::OnFileSave) @@ -707,6 +723,7 @@ BEGIN_EVENT_TABLE(wxDocManager, wxEvtHandler) EVT_UPDATE_UI(wxID_OPEN, wxDocManager::OnUpdateFileOpen) EVT_UPDATE_UI(wxID_CLOSE, wxDocManager::OnUpdateFileClose) + EVT_UPDATE_UI(wxID_CLOSE_ALL, wxDocManager::OnUpdateFileClose) EVT_UPDATE_UI(wxID_REVERT, wxDocManager::OnUpdateFileRevert) EVT_UPDATE_UI(wxID_NEW, wxDocManager::OnUpdateFileNew) EVT_UPDATE_UI(wxID_SAVE, wxDocManager::OnUpdateFileSave) @@ -747,7 +764,7 @@ wxDocManager::~wxDocManager() sm_docManager = (wxDocManager*) NULL; } -bool wxDocManager::Clear(bool force) +bool wxDocManager::CloseDocuments(bool force) { wxNode *node = m_docs.First(); while (node) @@ -771,7 +788,15 @@ bool wxDocManager::Clear(bool force) // delete another. node = next; } - node = m_templates.First(); + return TRUE; +} + +bool wxDocManager::Clear(bool force) +{ + if (!CloseDocuments(force)) + return FALSE; + + wxNode *node = m_templates.First(); while (node) { wxDocTemplate *templ = (wxDocTemplate*) node->Data(); @@ -806,6 +831,11 @@ void wxDocManager::OnFileClose(wxCommandEvent& WXUNUSED(event)) } } +void wxDocManager::OnFileCloseAll(wxCommandEvent& WXUNUSED(event)) +{ + CloseDocuments(FALSE); +} + void wxDocManager::OnFileNew(wxCommandEvent& WXUNUSED(event)) { CreateDocument(wxString(""), wxDOC_NEW); @@ -945,7 +975,7 @@ void wxDocManager::OnUpdateFileNew(wxUpdateUIEvent& event) void wxDocManager::OnUpdateFileSave(wxUpdateUIEvent& event) { wxDocument *doc = GetCurrentDocument(); - event.Enable( (doc != (wxDocument*) NULL) ); + event.Enable( doc && doc->IsModified() ); } void wxDocManager::OnUpdateFileSaveAs(wxUpdateUIEvent& event) @@ -958,12 +988,16 @@ void wxDocManager::OnUpdateUndo(wxUpdateUIEvent& event) { wxDocument *doc = GetCurrentDocument(); event.Enable( (doc && doc->GetCommandProcessor() && doc->GetCommandProcessor()->CanUndo()) ); + if (doc && doc->GetCommandProcessor()) + doc->GetCommandProcessor()->SetMenuStrings(); } void wxDocManager::OnUpdateRedo(wxUpdateUIEvent& event) { wxDocument *doc = GetCurrentDocument(); event.Enable( (doc && doc->GetCommandProcessor() && doc->GetCommandProcessor()->CanRedo()) ); + if (doc && doc->GetCommandProcessor()) + doc->GetCommandProcessor()->SetMenuStrings(); } void wxDocManager::OnUpdatePrint(wxUpdateUIEvent& event) @@ -1176,8 +1210,9 @@ bool wxDocManager::FlushDoc(wxDocument *WXUNUSED(doc)) wxDocument *wxDocManager::GetCurrentDocument() const { - if (m_currentView) - return m_currentView->GetDocument(); + wxView *view = GetCurrentView(); + if (view) + return view->GetDocument(); else return (wxDocument *) NULL; } @@ -1441,13 +1476,26 @@ wxDocTemplate *wxDocManager::SelectDocumentType(wxDocTemplate **templates, wxDocTemplate **data = new wxDocTemplate *[noTemplates]; int i; int n = 0; + for (i = 0; i < noTemplates; i++) { if (templates[i]->IsVisible()) { - strings.Add(templates[i]->m_description); - if (!sort) + int j; + bool want = TRUE; + for (j = 0; j < n; j++) + { + //filter out NOT unique documents + view combinations + if ( templates[i]->m_docTypeName == data[j]->m_docTypeName && + templates[i]->m_viewTypeName == data[j]->m_viewTypeName + ) + want = FALSE; + } + + if ( want ) { + strings.Add(templates[i]->m_description); + data[n] = templates[i]; n ++; } @@ -1508,14 +1556,24 @@ wxDocTemplate *wxDocManager::SelectViewType(wxDocTemplate **templates, wxDocTemplate **data = new wxDocTemplate *[noTemplates]; int i; int n = 0; + for (i = 0; i < noTemplates; i++) { wxDocTemplate *templ = templates[i]; if ( templ->IsVisible() && !templ->GetViewName().empty() ) { - strings.Add(templ->m_viewTypeName); - if (!sort) + int j; + bool want = TRUE; + for (j = 0; j < n; j++) { + //filter out NOT unique views + if ( templates[i]->m_viewTypeName == data[j]->m_viewTypeName ) + want = FALSE; + } + + if ( want ) + { + strings.Add(templ->m_viewTypeName); data[n] = templ; n ++; }