added test for writing empty value to the config

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@11165 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2001-07-23 17:46:15 +00:00
parent 0516e0e8ec
commit aba4387c4c

View File

@@ -28,6 +28,7 @@
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// classes // classes
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
class MyApp: public wxApp class MyApp: public wxApp
{ {
public: public:
@@ -46,7 +47,6 @@ public:
void OnQuit(wxCommandEvent& event); void OnQuit(wxCommandEvent& event);
void OnAbout(wxCommandEvent& event); void OnAbout(wxCommandEvent& event);
void OnDelete(wxCommandEvent& event); void OnDelete(wxCommandEvent& event);
void OnCloseWindow(wxCloseEvent& event);
private: private:
wxTextCtrl *m_text; wxTextCtrl *m_text;
@@ -57,19 +57,19 @@ private:
enum enum
{ {
Minimal_Quit, ConfTest_Quit,
Minimal_About, ConfTest_About,
Minimal_Delete ConfTest_Delete
}; };
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// event tables // event tables
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
BEGIN_EVENT_TABLE(MyFrame, wxFrame) BEGIN_EVENT_TABLE(MyFrame, wxFrame)
EVT_MENU(Minimal_Quit, MyFrame::OnQuit) EVT_MENU(ConfTest_Quit, MyFrame::OnQuit)
EVT_MENU(Minimal_About, MyFrame::OnAbout) EVT_MENU(ConfTest_About, MyFrame::OnAbout)
EVT_MENU(Minimal_Delete, MyFrame::OnDelete) EVT_MENU(ConfTest_Delete, MyFrame::OnDelete)
EVT_CLOSE(MyFrame::OnCloseWindow)
END_EVENT_TABLE() END_EVENT_TABLE()
// ============================================================================ // ============================================================================
@@ -79,6 +79,7 @@ END_EVENT_TABLE()
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// application // application
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
IMPLEMENT_APP(MyApp) IMPLEMENT_APP(MyApp)
// `Main program' equivalent, creating windows and returning main app frame // `Main program' equivalent, creating windows and returning main app frame
@@ -141,20 +142,14 @@ int MyApp::OnExit()
MyFrame::MyFrame() MyFrame::MyFrame()
: wxFrame((wxFrame *) NULL, -1, "wxConfig Demo") : wxFrame((wxFrame *) NULL, -1, "wxConfig Demo")
{ {
// submenu
wxMenu *sub_menu = new wxMenu( wxEmptyString, wxMENU_TEAROFF );
sub_menu->Append(Minimal_About, "&About", "About this sample");
sub_menu->Append(Minimal_About, "&About", "About this sample");
sub_menu->Append(Minimal_About, "&About", "About this sample");
// menu // menu
wxMenu *file_menu = new wxMenu; wxMenu *file_menu = new wxMenu;
file_menu->Append(Minimal_Delete, "&Delete", "Delete config file"); file_menu->Append(ConfTest_Delete, "&Delete", "Delete config file");
file_menu->AppendSeparator(); file_menu->AppendSeparator();
file_menu->Append(Minimal_About, "&About", "About this sample"); file_menu->Append(ConfTest_About, "&About\tF1", "About this sample");
file_menu->AppendSeparator(); file_menu->AppendSeparator();
file_menu->Append(Minimal_Quit, "E&xit", "Exit the program"); file_menu->Append(ConfTest_Quit, "E&xit\tAlt-X", "Exit the program");
wxMenuBar *menu_bar = new wxMenuBar; wxMenuBar *menu_bar = new wxMenuBar;
menu_bar->Append(file_menu, "&File"); menu_bar->Append(file_menu, "&File");
SetMenuBar(menu_bar); SetMenuBar(menu_bar);
@@ -194,11 +189,17 @@ MyFrame::MyFrame()
h = pConfig->Read("h", 200); h = pConfig->Read("h", 200);
Move(x, y); Move(x, y);
SetClientSize(w, h); SetClientSize(w, h);
}
void MyFrame::OnCloseWindow(wxCloseEvent& event) pConfig->SetPath("/");
{ wxString s;
this->Destroy(); if ( pConfig->Read("TestValue", &s) )
{
wxLogStatus(this, "TestValue from config is '%s'", s.c_str());
}
else
{
wxLogStatus(this, "TestValue not found in the config");
}
} }
void MyFrame::OnQuit(wxCommandEvent&) void MyFrame::OnQuit(wxCommandEvent&)
@@ -214,7 +215,8 @@ void MyFrame::OnAbout(wxCommandEvent&)
void MyFrame::OnDelete(wxCommandEvent&) void MyFrame::OnDelete(wxCommandEvent&)
{ {
if ( wxConfigBase::Get()->DeleteAll() ) { if ( wxConfigBase::Get()->DeleteAll() )
{
wxLogMessage(_T("Config file/registry key successfully deleted.")); wxLogMessage(_T("Config file/registry key successfully deleted."));
delete wxConfigBase::Set((wxConfigBase *) NULL); delete wxConfigBase::Set((wxConfigBase *) NULL);
@@ -243,4 +245,6 @@ MyFrame::~MyFrame()
pConfig->Write("/MainFrame/y", (long) y); pConfig->Write("/MainFrame/y", (long) y);
pConfig->Write("/MainFrame/w", (long) w); pConfig->Write("/MainFrame/w", (long) w);
pConfig->Write("/MainFrame/h", (long) h); pConfig->Write("/MainFrame/h", (long) h);
pConfig->Write("/TestValue", "");
} }