Show using window-modal file open dialog in the sample

This commit is contained in:
Stefan Csomor
2020-07-09 10:12:32 +02:00
committed by Vadim Zeitlin
parent dd0033d817
commit f585878136
2 changed files with 62 additions and 0 deletions

View File

@@ -194,6 +194,7 @@ wxBEGIN_EVENT_TABLE(MyFrame, wxFrame)
EVT_MENU(DIALOGS_FILE_OPEN, MyFrame::FileOpen) EVT_MENU(DIALOGS_FILE_OPEN, MyFrame::FileOpen)
EVT_MENU(DIALOGS_FILE_OPEN2, MyFrame::FileOpen2) EVT_MENU(DIALOGS_FILE_OPEN2, MyFrame::FileOpen2)
EVT_MENU(DIALOGS_FILES_OPEN, MyFrame::FilesOpen) EVT_MENU(DIALOGS_FILES_OPEN, MyFrame::FilesOpen)
EVT_MENU(DIALOGS_FILES_OPEN_WINDOW_MODAL, MyFrame::FilesOpenWindowModal)
EVT_MENU(DIALOGS_FILE_SAVE, MyFrame::FileSave) EVT_MENU(DIALOGS_FILE_SAVE, MyFrame::FileSave)
#endif // wxUSE_FILEDLG #endif // wxUSE_FILEDLG
@@ -479,6 +480,7 @@ bool MyApp::OnInit()
filedlg_menu->Append(DIALOGS_FILE_OPEN, "&Open file\tCtrl-O"); filedlg_menu->Append(DIALOGS_FILE_OPEN, "&Open file\tCtrl-O");
filedlg_menu->Append(DIALOGS_FILE_OPEN2, "&Second open file\tCtrl-2"); filedlg_menu->Append(DIALOGS_FILE_OPEN2, "&Second open file\tCtrl-2");
filedlg_menu->Append(DIALOGS_FILES_OPEN, "Open &files\tShift-Ctrl-O"); filedlg_menu->Append(DIALOGS_FILES_OPEN, "Open &files\tShift-Ctrl-O");
filedlg_menu->Append(DIALOGS_FILES_OPEN_WINDOW_MODAL, "Window Modal Open files");
filedlg_menu->Append(DIALOGS_FILE_SAVE, "Sa&ve file\tCtrl-S"); filedlg_menu->Append(DIALOGS_FILE_SAVE, "Sa&ve file\tCtrl-S");
#if USE_FILEDLG_GENERIC #if USE_FILEDLG_GENERIC
@@ -1699,6 +1701,63 @@ void MyFrame::FilesOpen(wxCommandEvent& WXUNUSED(event) )
} }
} }
void MyFrame::FilesOpenWindowModal(wxCommandEvent& WXUNUSED(event) )
{
wxString wildcards =
#ifdef __WXMOTIF__
"C++ files (*.cpp)|*.cpp";
#else
wxString::Format
(
"All files (%s)|%s|C++ files (*.cpp;*.h)|*.cpp;*.h",
wxFileSelectorDefaultWildcardStr,
wxFileSelectorDefaultWildcardStr
);
#endif
wxFileDialog* dialog = new wxFileDialog(this, "Testing open multiple file dialog",
wxEmptyString, wxEmptyString, wildcards,
wxFD_OPEN|wxFD_MULTIPLE);
dialog->Bind(wxEVT_WINDOW_MODAL_DIALOG_CLOSED,
&MyFrame::FilesOpenWindowModalClosed, this);
dialog->ShowWindowModal();
}
void MyFrame::FilesOpenWindowModalClosed(wxWindowModalDialogEvent& event)
{
wxFileDialog* dialog = dynamic_cast<wxFileDialog*>(event.GetDialog());
if ( dialog->GetReturnCode() == wxID_OK)
{
wxArrayString paths, filenames;
dialog->GetPaths(paths);
dialog->GetFilenames(filenames);
wxString msg, s;
size_t count = paths.GetCount();
for ( size_t n = 0; n < count; n++ )
{
s.Printf("File %d: %s (%s)\n",
(int)n, paths[n], filenames[n]);
msg += s;
}
s.Printf("Filter index: %d", dialog->GetFilterIndex());
msg += s;
wxMessageDialog dialog2(this, msg, "Selected files");
dialog2.ShowModal();
}
else
{
wxLogError("Unexpected window modal wxFileDialog return code!");
}
delete dialog;
}
void MyFrame::FileSave(wxCommandEvent& WXUNUSED(event) ) void MyFrame::FileSave(wxCommandEvent& WXUNUSED(event) )
{ {
wxFileDialog dialog(this, wxFileDialog dialog(this,

View File

@@ -422,6 +422,8 @@ public:
void FileOpen(wxCommandEvent& event); void FileOpen(wxCommandEvent& event);
void FileOpen2(wxCommandEvent& event); void FileOpen2(wxCommandEvent& event);
void FilesOpen(wxCommandEvent& event); void FilesOpen(wxCommandEvent& event);
void FilesOpenWindowModal(wxCommandEvent& event);
void FilesOpenWindowModalClosed(wxWindowModalDialogEvent& event);
void FileSave(wxCommandEvent& event); void FileSave(wxCommandEvent& event);
#endif // wxUSE_FILEDLG #endif // wxUSE_FILEDLG
@@ -596,6 +598,7 @@ enum
DIALOGS_FILE_OPEN, DIALOGS_FILE_OPEN,
DIALOGS_FILE_OPEN2, DIALOGS_FILE_OPEN2,
DIALOGS_FILES_OPEN, DIALOGS_FILES_OPEN,
DIALOGS_FILES_OPEN_WINDOW_MODAL,
DIALOGS_FILE_SAVE, DIALOGS_FILE_SAVE,
DIALOGS_FILE_OPEN_GENERIC, DIALOGS_FILE_OPEN_GENERIC,
DIALOGS_FILES_OPEN_GENERIC, DIALOGS_FILES_OPEN_GENERIC,