X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/d06a66f52670ed5258b6a1dcf52ed5cd3a06ae1a..77416abdc5e242946d16e1b087e1adea25f2a0d6:/src/common/docview.cpp diff --git a/src/common/docview.cpp b/src/common/docview.cpp index 95b9f93b46..c001cac43a 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; @@ -259,7 +262,7 @@ bool wxDocument::SaveAs() if (ext.IsEmpty() || ext == wxT("")) { - fileName += "."; + fileName += wxT("."); fileName += docTemplate->GetDefaultExtension(); } @@ -292,11 +295,11 @@ bool wxDocument::OnSaveDocument(const wxString& file) msgTitle = wxString(_("File error")); #if wxUSE_STD_IOSTREAM - wxSTD ofstream store(wxString(file.fn_str()).mb_str()); + wxSTD ofstream store(wxString(file.fn_str()).mb_str()); // ????? if (store.fail() || store.bad()) #else - wxFileOutputStream store(wxString(file.fn_str())); - if (store.LastError() != wxSTREAM_NOERROR) + wxFileOutputStream store( file ); + if (store.GetLastError() != wxSTREAM_NO_ERROR) #endif { (void)wxMessageBox(_("Sorry, could not open this file for saving."), msgTitle, wxOK | wxICON_EXCLAMATION, @@ -329,11 +332,11 @@ bool wxDocument::OnOpenDocument(const wxString& file) msgTitle = wxString(_("File error")); #if wxUSE_STD_IOSTREAM - wxSTD ifstream store(wxString(file.fn_str()).mb_str()); + wxSTD ifstream store(wxString(file.fn_str()).mb_str()); // ???? if (store.fail() || store.bad()) #else - wxFileInputStream store(wxString(file.fn_str())); - if (store.LastError() != wxSTREAM_NOERROR) + wxFileInputStream store( file ); + if (store.GetLastError() != wxSTREAM_NO_ERROR) #endif { (void)wxMessageBox(_("Sorry, could not open this file."), msgTitle, wxOK|wxICON_EXCLAMATION, @@ -341,10 +344,11 @@ 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) && + int res = LoadObject(store).GetLastError(); + if ((res != wxSTREAM_NO_ERROR) && (res != wxSTREAM_EOF)) #endif { @@ -502,7 +506,19 @@ void wxDocument::UpdateAllViews(wxView *sender, wxObject *hint) while (node) { wxView *view = (wxView *)node->Data(); - view->OnUpdate(sender, hint); + if (view != sender) + view->OnUpdate(sender, hint); + node = node->Next(); + } +} + +void wxDocument::NotifyClosing() +{ + wxNode *node = m_documentViews.First(); + while (node) + { + wxView *view = (wxView *)node->Data(); + view->OnClosingDocument(); node = node->Next(); } } @@ -593,7 +609,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 +714,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 +724,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 +765,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 +789,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,14 +832,19 @@ void wxDocManager::OnFileClose(wxCommandEvent& WXUNUSED(event)) } } +void wxDocManager::OnFileCloseAll(wxCommandEvent& WXUNUSED(event)) +{ + CloseDocuments(FALSE); +} + void wxDocManager::OnFileNew(wxCommandEvent& WXUNUSED(event)) { - CreateDocument(wxString(""), wxDOC_NEW); + CreateDocument( wxT(""), wxDOC_NEW ); } void wxDocManager::OnFileOpen(wxCommandEvent& WXUNUSED(event)) { - if ( !CreateDocument(wxString(""), 0) ) + if ( !CreateDocument( wxT(""), 0) ) { OnOpenFileFailure(); } @@ -945,7 +976,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 +989,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 +1211,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; } @@ -1333,7 +1369,7 @@ static wxWindow* wxFindSuitableParent() // template extension. wxDocTemplate *wxDocManager::SelectDocumentPath(wxDocTemplate **templates, -#if defined(__WXMSW__) || defined(__WXGTK__) +#if defined(__WXMSW__) || defined(__WXGTK__) || defined(__WXMAC__) int noTemplates, #else int WXUNUSED(noTemplates), @@ -1343,7 +1379,7 @@ wxDocTemplate *wxDocManager::SelectDocumentPath(wxDocTemplate **templates, bool WXUNUSED(save)) { // We can only have multiple filters in Windows and GTK -#if defined(__WXMSW__) || defined(__WXGTK__) +#if defined(__WXMSW__) || defined(__WXGTK__) || defined(__WXMAC__) wxString descrBuf; int i; @@ -1441,13 +1477,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 +1557,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 ++; } @@ -2156,7 +2215,7 @@ bool wxTransferStreamToFile(wxInputStream& stream, const wxString& filename) return FALSE; } - int len = stream.StreamSize(); + int len = stream.GetSize(); // TODO: is this the correct test for EOF? while (stream.TellI() < (len - 1)) {