From 7b2061eaefff00ba93bace9562d9c2cc2ce2e197 Mon Sep 17 00:00:00 2001 From: PB Date: Mon, 6 Jul 2020 12:57:57 +0200 Subject: [PATCH 1/3] Disallow invalid flag combination for wxFileCtrl in Widgets sample wxFC_SAVE cannot be used with wxFC_MULTIPLE so prevent the user from setting this flag combination. Also rename the event handler for switching between Open and Save modes to indicate what it does. --- samples/widgets/filectrl.cpp | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/samples/widgets/filectrl.cpp b/samples/widgets/filectrl.cpp index 1ec56bd8ff..df08a26f77 100644 --- a/samples/widgets/filectrl.cpp +++ b/samples/widgets/filectrl.cpp @@ -83,7 +83,7 @@ protected: void OnButtonSetFilename( wxCommandEvent& event ); void OnButtonReset( wxCommandEvent& event ); void OnCheckBox( wxCommandEvent& event ); - void OnRadioBox( wxCommandEvent& event ); + void OnSwitchMode( wxCommandEvent& event ); void OnFileCtrl( wxFileCtrlEvent& event ); // reset the control parameters @@ -127,7 +127,7 @@ wxBEGIN_EVENT_TABLE( FileCtrlWidgetsPage, WidgetsPage ) EVT_BUTTON( FileCtrlPage_SetPath, FileCtrlWidgetsPage::OnButtonSetPath ) EVT_BUTTON( FileCtrlPage_SetFilename, FileCtrlWidgetsPage::OnButtonSetFilename ) EVT_CHECKBOX( wxID_ANY, FileCtrlWidgetsPage::OnCheckBox ) - EVT_RADIOBOX( wxID_ANY, FileCtrlWidgetsPage::OnRadioBox ) + EVT_RADIOBOX( wxID_ANY, FileCtrlWidgetsPage::OnSwitchMode ) EVT_FILECTRL_FILTERCHANGED( wxID_ANY, FileCtrlWidgetsPage::OnFileCtrl ) EVT_FILECTRL_FOLDERCHANGED( wxID_ANY, FileCtrlWidgetsPage::OnFileCtrl ) @@ -228,11 +228,22 @@ void FileCtrlWidgetsPage::CreateFileCtrl() wxWindowUpdateLocker noUpdates( this ); long style = GetAttrs().m_defaultFlags; - style |= m_radioFileCtrlMode->GetSelection() == FileCtrlMode_Open - ? wxFC_OPEN - : wxFC_SAVE; - if ( m_chkMultiple->IsChecked() ) - style |= wxFC_MULTIPLE; + + if ( m_radioFileCtrlMode->GetSelection() == FileCtrlMode_Open ) + { + style |= wxFC_OPEN; + m_chkMultiple->Enable(); + if ( m_chkMultiple->IsChecked() ) + style |= wxFC_MULTIPLE; + } + else + { + style |= wxFC_SAVE; + // wxFC_SAVE is incompatible with wxFC_MULTIPLE + m_chkMultiple->SetValue(false); + m_chkMultiple->Enable(false); + } + if ( m_chkNoShowHidden->IsChecked() ) style |= wxFC_NOSHOWHIDDEN; @@ -301,7 +312,7 @@ void FileCtrlWidgetsPage::OnCheckBox( wxCommandEvent& WXUNUSED( event ) ) CreateFileCtrl(); } -void FileCtrlWidgetsPage::OnRadioBox( wxCommandEvent& WXUNUSED( event ) ) +void FileCtrlWidgetsPage::OnSwitchMode( wxCommandEvent& WXUNUSED( event ) ) { CreateFileCtrl(); } From 0f22f25d37b48463abaaedd9eeff075876c93a24 Mon Sep 17 00:00:00 2001 From: PB Date: Mon, 6 Jul 2020 13:13:00 +0200 Subject: [PATCH 2/3] Preserve the path when changing flags for wxDirCtrl in Widgets sample Do not reset the path in wxDirCtrl when changing its flags. Resetting the path to the default view where no files are shown may make showing off some flags more difficult. --- samples/widgets/dirctrl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/widgets/dirctrl.cpp b/samples/widgets/dirctrl.cpp index 7a2c60f717..3632b530d6 100644 --- a/samples/widgets/dirctrl.cpp +++ b/samples/widgets/dirctrl.cpp @@ -263,7 +263,7 @@ void DirCtrlWidgetsPage::CreateDirCtrl() wxGenericDirCtrl *dirCtrl = new wxGenericDirCtrl( this, DirCtrlPage_Ctrl, - wxDirDialogDefaultFolderStr, + m_dirCtrl->GetPath(), wxDefaultPosition, wxDefaultSize, style From fec7abd54e72f6e29c9152bd8189d6c820986eed Mon Sep 17 00:00:00 2001 From: PB Date: Mon, 6 Jul 2020 20:28:15 +0200 Subject: [PATCH 3/3] Reset displayed wxDirCtrl in Widgets sample after pressing Reset button --- samples/widgets/dirctrl.cpp | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/samples/widgets/dirctrl.cpp b/samples/widgets/dirctrl.cpp index 3632b530d6..062d003d3a 100644 --- a/samples/widgets/dirctrl.cpp +++ b/samples/widgets/dirctrl.cpp @@ -118,7 +118,7 @@ protected: void Reset(); // (re)create the m_dirCtrl - void CreateDirCtrl(); + void CreateDirCtrl(bool defaultPath = false); // the controls // ------------ @@ -231,18 +231,32 @@ void DirCtrlWidgetsPage::CreateContent() sizerTop->Add(m_radioStdPath, 0, wxGROW | wxALL , 10); sizerTop->Add(m_dirCtrl, 1, wxGROW | (wxALL & ~wxRIGHT), 10); + SetSizer(sizerTop); + // final initializations Reset(); - - SetSizer(sizerTop); } void DirCtrlWidgetsPage::Reset() { - m_path->SetValue(m_dirCtrl->GetPath()); + m_path->Clear(); + + m_chkDirOnly->SetValue(false); + m_chk3D->SetValue(false); + m_chkFirst->SetValue(false); + m_chkFilters->SetValue(false); + m_chkLabels->SetValue(false); + m_chkMulti->SetValue(false); + + m_radioStdPath->SetSelection(0); + + for ( size_t i = 0; i < WXSIZEOF(m_fltr); ++i ) + m_fltr[i]->SetValue(false); + + CreateDirCtrl(true); } -void DirCtrlWidgetsPage::CreateDirCtrl() +void DirCtrlWidgetsPage::CreateDirCtrl(bool defaultPath) { wxWindowUpdateLocker noUpdates(this); @@ -260,10 +274,11 @@ void DirCtrlWidgetsPage::CreateDirCtrl() if ( m_chkMulti->IsChecked() ) style |= wxDIRCTRL_MULTIPLE; + wxGenericDirCtrl *dirCtrl = new wxGenericDirCtrl( this, DirCtrlPage_Ctrl, - m_dirCtrl->GetPath(), + defaultPath ? wxDirDialogDefaultFolderStr : m_dirCtrl->GetPath(), wxDefaultPosition, wxDefaultSize, style