added DoCreate/Load/SaveDocument() (patches 983570 and 983571)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@28474 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -162,6 +162,12 @@ protected:
|
|||||||
wxCommandProcessor* m_commandProcessor;
|
wxCommandProcessor* m_commandProcessor;
|
||||||
bool m_savedYet;
|
bool m_savedYet;
|
||||||
|
|
||||||
|
// Called by OnSaveDocument and OnOpenDocument to implement standard
|
||||||
|
// Save/Load behavior. Re-implement in derived class for custom
|
||||||
|
// behavior.
|
||||||
|
virtual bool DoSaveDocument(const wxString& file);
|
||||||
|
virtual bool DoOpenDocument(const wxString& file);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
DECLARE_ABSTRACT_CLASS(wxDocument)
|
DECLARE_ABSTRACT_CLASS(wxDocument)
|
||||||
DECLARE_NO_COPY_CLASS(wxDocument)
|
DECLARE_NO_COPY_CLASS(wxDocument)
|
||||||
@@ -295,6 +301,12 @@ protected:
|
|||||||
wxClassInfo* m_docClassInfo;
|
wxClassInfo* m_docClassInfo;
|
||||||
wxClassInfo* m_viewClassInfo;
|
wxClassInfo* m_viewClassInfo;
|
||||||
|
|
||||||
|
// Called by CreateDocument and CreateView to create the actual document/view object.
|
||||||
|
// By default uses the ClassInfo provided to the constructor. Override these functions
|
||||||
|
// to provide a different method of creation.
|
||||||
|
virtual wxDocument *DoCreateDocument();
|
||||||
|
virtual wxView *DoCreateView();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
DECLARE_CLASS(wxDocTemplate)
|
DECLARE_CLASS(wxDocTemplate)
|
||||||
DECLARE_NO_COPY_CLASS(wxDocTemplate)
|
DECLARE_NO_COPY_CLASS(wxDocTemplate)
|
||||||
|
@@ -340,32 +340,9 @@ bool wxDocument::OnSaveDocument(const wxString& file)
|
|||||||
if ( !file )
|
if ( !file )
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
wxString msgTitle;
|
if ( !DoSaveDocument(file) )
|
||||||
if (wxTheApp->GetAppName() != wxT(""))
|
return FALSE;
|
||||||
msgTitle = wxTheApp->GetAppName();
|
|
||||||
else
|
|
||||||
msgTitle = wxString(_("File error"));
|
|
||||||
|
|
||||||
#if wxUSE_STD_IOSTREAM
|
|
||||||
wxSTD ofstream store(file.mb_str());
|
|
||||||
if (store.fail() || store.bad())
|
|
||||||
#else
|
|
||||||
wxFileOutputStream store(file);
|
|
||||||
if (store.GetLastError() != wxSTREAM_NO_ERROR)
|
|
||||||
#endif
|
|
||||||
{
|
|
||||||
(void)wxMessageBox(_("Sorry, could not open this file for saving."), msgTitle, wxOK | wxICON_EXCLAMATION,
|
|
||||||
GetDocumentWindow());
|
|
||||||
// Saving error
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
if (!SaveObject(store))
|
|
||||||
{
|
|
||||||
(void)wxMessageBox(_("Sorry, could not save this file."), msgTitle, wxOK | wxICON_EXCLAMATION,
|
|
||||||
GetDocumentWindow());
|
|
||||||
// Saving error
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
Modify(FALSE);
|
Modify(FALSE);
|
||||||
SetFilename(file);
|
SetFilename(file);
|
||||||
SetDocumentSaved(TRUE);
|
SetDocumentSaved(TRUE);
|
||||||
@@ -381,37 +358,9 @@ bool wxDocument::OnOpenDocument(const wxString& file)
|
|||||||
if (!OnSaveModified())
|
if (!OnSaveModified())
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
wxString msgTitle;
|
if ( !DoOpenDocument(file) )
|
||||||
if (wxTheApp->GetAppName() != wxT(""))
|
return FALSE;
|
||||||
msgTitle = wxTheApp->GetAppName();
|
|
||||||
else
|
|
||||||
msgTitle = wxString(_("File error"));
|
|
||||||
|
|
||||||
#if wxUSE_STD_IOSTREAM
|
|
||||||
wxSTD ifstream store(file.mb_str());
|
|
||||||
if (store.fail() || store.bad())
|
|
||||||
#else
|
|
||||||
wxFileInputStream store(file);
|
|
||||||
if (store.GetLastError() != wxSTREAM_NO_ERROR)
|
|
||||||
#endif
|
|
||||||
{
|
|
||||||
(void)wxMessageBox(_("Sorry, could not open this file."), msgTitle, wxOK|wxICON_EXCLAMATION,
|
|
||||||
GetDocumentWindow());
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
#if wxUSE_STD_IOSTREAM
|
|
||||||
LoadObject(store);
|
|
||||||
if ( !store && !store.eof() )
|
|
||||||
#else
|
|
||||||
int res = LoadObject(store).GetLastError();
|
|
||||||
if ((res != wxSTREAM_NO_ERROR) &&
|
|
||||||
(res != wxSTREAM_EOF))
|
|
||||||
#endif
|
|
||||||
{
|
|
||||||
(void)wxMessageBox(_("Sorry, could not open this file."), msgTitle, wxOK|wxICON_EXCLAMATION,
|
|
||||||
GetDocumentWindow());
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
SetFilename(file, TRUE);
|
SetFilename(file, TRUE);
|
||||||
Modify(FALSE);
|
Modify(FALSE);
|
||||||
m_savedYet = TRUE;
|
m_savedYet = TRUE;
|
||||||
@@ -595,6 +544,76 @@ void wxDocument::SetFilename(const wxString& filename, bool notifyViews)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool wxDocument::DoSaveDocument(const wxString& file)
|
||||||
|
{
|
||||||
|
wxString msgTitle;
|
||||||
|
if (wxTheApp->GetAppName() != wxT(""))
|
||||||
|
msgTitle = wxTheApp->GetAppName();
|
||||||
|
else
|
||||||
|
msgTitle = wxString(_("File error"));
|
||||||
|
|
||||||
|
#if wxUSE_STD_IOSTREAM
|
||||||
|
wxSTD ofstream store(file.mb_str());
|
||||||
|
if (store.fail() || store.bad())
|
||||||
|
#else
|
||||||
|
wxFileOutputStream store(file);
|
||||||
|
if (store.GetLastError() != wxSTREAM_NO_ERROR)
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
(void)wxMessageBox(_("Sorry, could not open this file for saving."), msgTitle, wxOK | wxICON_EXCLAMATION,
|
||||||
|
GetDocumentWindow());
|
||||||
|
// Saving error
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
if (!SaveObject(store))
|
||||||
|
{
|
||||||
|
(void)wxMessageBox(_("Sorry, could not save this file."), msgTitle, wxOK | wxICON_EXCLAMATION,
|
||||||
|
GetDocumentWindow());
|
||||||
|
// Saving error
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool wxDocument::DoOpenDocument(const wxString& file)
|
||||||
|
{
|
||||||
|
wxString msgTitle;
|
||||||
|
if (wxTheApp->GetAppName() != wxT(""))
|
||||||
|
msgTitle = wxTheApp->GetAppName();
|
||||||
|
else
|
||||||
|
msgTitle = wxString(_("File error"));
|
||||||
|
|
||||||
|
#if wxUSE_STD_IOSTREAM
|
||||||
|
wxSTD ifstream store(file.mb_str());
|
||||||
|
if (store.fail() || store.bad())
|
||||||
|
#else
|
||||||
|
wxFileInputStream store(file);
|
||||||
|
if (store.GetLastError() != wxSTREAM_NO_ERROR)
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
(void)wxMessageBox(_("Sorry, could not open this file."), msgTitle, wxOK|wxICON_EXCLAMATION,
|
||||||
|
GetDocumentWindow());
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
#if wxUSE_STD_IOSTREAM
|
||||||
|
LoadObject(store);
|
||||||
|
if ( !store && !store.eof() )
|
||||||
|
#else
|
||||||
|
int res = LoadObject(store).GetLastError();
|
||||||
|
if ((res != wxSTREAM_NO_ERROR) &&
|
||||||
|
(res != wxSTREAM_EOF))
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
(void)wxMessageBox(_("Sorry, could not open this file."), msgTitle, wxOK|wxICON_EXCLAMATION,
|
||||||
|
GetDocumentWindow());
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// Document view
|
// Document view
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
@@ -719,9 +738,9 @@ wxDocTemplate::~wxDocTemplate()
|
|||||||
// Tries to dynamically construct an object of the right class.
|
// Tries to dynamically construct an object of the right class.
|
||||||
wxDocument *wxDocTemplate::CreateDocument(const wxString& path, long flags)
|
wxDocument *wxDocTemplate::CreateDocument(const wxString& path, long flags)
|
||||||
{
|
{
|
||||||
if (!m_docClassInfo)
|
wxDocument *doc = DoCreateDocument();
|
||||||
|
if ( doc == NULL )
|
||||||
return (wxDocument *) NULL;
|
return (wxDocument *) NULL;
|
||||||
wxDocument *doc = (wxDocument *)m_docClassInfo->CreateObject();
|
|
||||||
|
|
||||||
if (InitDocument(doc, path, flags))
|
if (InitDocument(doc, path, flags))
|
||||||
{
|
{
|
||||||
@@ -752,9 +771,10 @@ bool wxDocTemplate::InitDocument(wxDocument* doc, const wxString& path, long fla
|
|||||||
|
|
||||||
wxView *wxDocTemplate::CreateView(wxDocument *doc, long flags)
|
wxView *wxDocTemplate::CreateView(wxDocument *doc, long flags)
|
||||||
{
|
{
|
||||||
if (!m_viewClassInfo)
|
wxView *view = DoCreateView();
|
||||||
|
if ( view == NULL )
|
||||||
return (wxView *) NULL;
|
return (wxView *) NULL;
|
||||||
wxView *view = (wxView *)m_viewClassInfo->CreateObject();
|
|
||||||
view->SetDocument(doc);
|
view->SetDocument(doc);
|
||||||
if (view->OnCreate(doc, flags))
|
if (view->OnCreate(doc, flags))
|
||||||
{
|
{
|
||||||
@@ -774,6 +794,22 @@ bool wxDocTemplate::FileMatchesTemplate(const wxString& path)
|
|||||||
return GetDefaultExtension().IsSameAs(FindExtension(path));
|
return GetDefaultExtension().IsSameAs(FindExtension(path));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wxDocument *wxDocTemplate::DoCreateDocument()
|
||||||
|
{
|
||||||
|
if (!m_docClassInfo)
|
||||||
|
return (wxDocument *) NULL;
|
||||||
|
|
||||||
|
return (wxDocument *)m_docClassInfo->CreateObject();
|
||||||
|
}
|
||||||
|
|
||||||
|
wxView *wxDocTemplate::DoCreateView()
|
||||||
|
{
|
||||||
|
if (!m_viewClassInfo)
|
||||||
|
return (wxView *) NULL;
|
||||||
|
|
||||||
|
return (wxView *)m_viewClassInfo->CreateObject();
|
||||||
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// wxDocManager
|
// wxDocManager
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
Reference in New Issue
Block a user