#include "wx/list.h"
#include "wx/filedlg.h"
#include "wx/intl.h"
+ #include "wx/log.h"
#endif
bool wxDocument::OnCloseDocument()
{
+ // Tell all views that we're about to close
+ NotifyClosing();
DeleteContents();
Modify(FALSE);
return TRUE;
if (ext.IsEmpty() || ext == wxT(""))
{
- fileName += ".";
+ fileName += wxT(".");
fileName += docTemplate->GetDefaultExtension();
}
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,
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,
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
{
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();
}
}
void wxView::Activate(bool activate)
{
- if (GetDocumentManager())
+ if (GetDocument() && GetDocumentManager())
{
OnActivateView(activate, this, GetDocumentManager()->GetCurrentView());
GetDocumentManager()->ActivateView(this, activate);
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)
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)
sm_docManager = (wxDocManager*) NULL;
}
-bool wxDocManager::Clear(bool force)
+bool wxDocManager::CloseDocuments(bool force)
{
wxNode *node = m_docs.First();
while (node)
// 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();
}
}
+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();
}
void wxDocManager::OnUpdateFileSave(wxUpdateUIEvent& event)
{
wxDocument *doc = GetCurrentDocument();
- event.Enable( (doc != (wxDocument*) NULL) );
+ event.Enable( doc && doc->IsModified() );
}
void wxDocManager::OnUpdateFileSaveAs(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)
wxDocument *wxDocManager::GetCurrentDocument() const
{
- if (m_currentView)
- return m_currentView->GetDocument();
+ wxView *view = GetCurrentView();
+ if (view)
+ return view->GetDocument();
else
return (wxDocument *) NULL;
}
// 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),
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;
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 ++;
}
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 ++;
}
return FALSE;
}
- int len = stream.StreamSize();
+ int len = stream.GetSize();
// TODO: is this the correct test for EOF?
while (stream.TellI() < (len - 1))
{