Save and restore file history in docview sample.

Show how the file history can be saved to and restored from wxConfig.

This makes it much easier to test file history related stuff as the history
doesn't need to be recreated during every sample run.

It is also closer to what real applications using docview framework do as the
file history is relatively useless if it's not saved.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@68332 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2011-07-22 16:16:03 +00:00
parent 90693f47f2
commit a6b7e90b5d

View File

@@ -55,6 +55,7 @@
#include "view.h" #include "view.h"
#include "wx/cmdline.h" #include "wx/cmdline.h"
#include "wx/config.h"
#ifdef __WXMAC__ #ifdef __WXMAC__
#include "wx/filename.h" #include "wx/filename.h"
@@ -150,7 +151,10 @@ bool MyApp::OnInit()
::wxInitAllImageHandlers(); ::wxInitAllImageHandlers();
SetAppName("DocView Sample"); // Fill in the application information fields before creating wxConfig.
SetVendorName("wxWidgets");
SetAppName("wx_docview_sample");
SetAppDisplayName("wxWidgets DocView Sample");
//// Create a document manager //// Create a document manager
wxDocManager *docManager = new wxDocManager; wxDocManager *docManager = new wxDocManager;
@@ -217,6 +221,10 @@ bool MyApp::OnInit()
// A nice touch: a history of files visited. Use this menu. // A nice touch: a history of files visited. Use this menu.
docManager->FileHistoryUseMenu(menuFile); docManager->FileHistoryUseMenu(menuFile);
#if wxUSE_CONFIG
docManager->FileHistoryLoad(*wxConfig::Get());
#endif // wxUSE_CONFIG
if ( m_mode == Mode_Single ) if ( m_mode == Mode_Single )
{ {
@@ -236,7 +244,11 @@ bool MyApp::OnInit()
int MyApp::OnExit() int MyApp::OnExit()
{ {
delete wxDocManager::GetDocumentManager(); wxDocManager * const manager = wxDocManager::GetDocumentManager();
#if wxUSE_CONFIG
manager->FileHistorySave(*wxConfig::Get());
#endif // wxUSE_CONFIG
delete manager;
return wxApp::OnExit(); return wxApp::OnExit();
} }