From 35b45b332b1dc1bf9f84f7e1a886a46a521500e5 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Wed, 23 Aug 2000 22:47:33 +0000 Subject: [PATCH] added test of wxFileSelector() def ext handling git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@8167 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- samples/dialogs/dialogs.cpp | 27 +++++++++++++++++++++++++++ samples/dialogs/dialogs.h | 2 ++ 2 files changed, 29 insertions(+) diff --git a/samples/dialogs/dialogs.cpp b/samples/dialogs/dialogs.cpp index 4abdd98dca..8617990daa 100644 --- a/samples/dialogs/dialogs.cpp +++ b/samples/dialogs/dialogs.cpp @@ -61,6 +61,7 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame) EVT_MENU(DIALOGS_NUM_ENTRY, MyFrame::NumericEntry) EVT_MENU(DIALOGS_SINGLE_CHOICE, MyFrame::SingleChoice) EVT_MENU(DIALOGS_FILE_OPEN, MyFrame::FileOpen) + EVT_MENU(DIALOGS_FILE_OPEN2, MyFrame::FileOpen2) EVT_MENU(DIALOGS_FILES_OPEN, MyFrame::FilesOpen) EVT_MENU(DIALOGS_FILE_SAVE, MyFrame::FileSave) EVT_MENU(DIALOGS_DIR_CHOOSE, MyFrame::DirChoose) @@ -130,6 +131,7 @@ bool MyApp::OnInit() file_menu->Append(DIALOGS_TIP, "&Tip of the day\tCtrl-T"); file_menu->AppendSeparator(); file_menu->Append(DIALOGS_FILE_OPEN, "&Open file\tCtrl-O"); + file_menu->Append(DIALOGS_FILE_OPEN2, "&Second open file\tCtrl-2"); file_menu->Append(DIALOGS_FILES_OPEN, "Open &files\tCtrl-Q"); file_menu->Append(DIALOGS_FILE_SAVE, "Sa&ve file\tCtrl-S"); file_menu->Append(DIALOGS_DIR_CHOOSE, "&Choose a directory\tCtrl-D"); @@ -365,6 +367,31 @@ void MyFrame::FileOpen(wxCommandEvent& WXUNUSED(event) ) } } +// this shows how to take advantage of specifying a default extension in the +// call to wxFileSelector: it is remembered after each new call and the next +// one will use it by default +void MyFrame::FileOpen2(wxCommandEvent& WXUNUSED(event) ) +{ + static wxString s_extDef; + wxString path = wxFileSelector( + _T("Select the file to load"), + _T(""), _T(""), + s_extDef, + _T("Waveform (*.wav)|*.wav|Plain text (*.txt)|*.txt|All files (*.*)|*.*"), + 0, + this + ); + + if ( !path ) + return; + + // it is just a sample, would use wxSplitPath in real program + s_extDef = path.AfterLast(_T('.')); + + wxLogMessage(_T("You selected the file '%s', remembered extension '%s'"), + path, s_extDef); +} + void MyFrame::FilesOpen(wxCommandEvent& WXUNUSED(event) ) { wxFileDialog dialog(this, "Testing open multiple file dialog", diff --git a/samples/dialogs/dialogs.h b/samples/dialogs/dialogs.h index d1bb0fe773..56493424e8 100644 --- a/samples/dialogs/dialogs.h +++ b/samples/dialogs/dialogs.h @@ -65,6 +65,7 @@ public: void PasswordEntry(wxCommandEvent& event); void NumericEntry(wxCommandEvent& event); void FileOpen(wxCommandEvent& event); + void FileOpen2(wxCommandEvent& event); void FilesOpen(wxCommandEvent& event); void FileSave(wxCommandEvent& event); void DirChoose(wxCommandEvent& event); @@ -112,6 +113,7 @@ enum DIALOGS_TEXT_ENTRY, DIALOGS_PASSWORD_ENTRY, DIALOGS_FILE_OPEN, + DIALOGS_FILE_OPEN2, DIALOGS_FILES_OPEN, DIALOGS_FILE_SAVE, DIALOGS_DIR_CHOOSE, -- 2.45.2