Improve extra controls support in wxGenericFileDialog
Update the extra controls whenever anything changes in the dialog to make the example in the dialogs sample actually work with the generic dialog (previously nothing was updated at all). Also delete the extra controls earlier to make the behaviour more consistent with the native dialogs. Use the new customization API for the generic dialogs in the sample too.
This commit is contained in:
@@ -1680,7 +1680,10 @@ static wxWindow* createMyExtraPanel(wxWindow *parent)
|
||||
class MyCustomizeHook : public wxFileDialogCustomizeHook
|
||||
{
|
||||
public:
|
||||
explicit MyCustomizeHook(wxFileDialog& dialog)
|
||||
// Normally we would just use wxFileDialog, but this sample allows using
|
||||
// both the real wxFileDialog and wxGenericFileDialog, so allow passing
|
||||
// either of them here.
|
||||
explicit MyCustomizeHook(wxFileDialogBase& dialog)
|
||||
: m_dialog(&dialog)
|
||||
{
|
||||
}
|
||||
@@ -1733,7 +1736,7 @@ private:
|
||||
wxOK | wxICON_INFORMATION, m_dialog);
|
||||
}
|
||||
|
||||
wxFileDialog* const m_dialog;
|
||||
wxFileDialogBase* const m_dialog;
|
||||
|
||||
wxFileDialogButton* m_btn;
|
||||
wxFileDialogCheckBox* m_cb;
|
||||
@@ -2005,7 +2008,8 @@ void MyFrame::FileOpenGeneric(wxCommandEvent& WXUNUSED(event) )
|
||||
"C++ files (*.cpp;*.h)|*.cpp;*.h"
|
||||
);
|
||||
|
||||
dialog.SetExtraControlCreator(&createMyExtraPanel);
|
||||
MyCustomizeHook myCustomizer(dialog);
|
||||
dialog.SetCustomizeHook(myCustomizer);
|
||||
dialog.SetDirectory(wxGetHomeDir());
|
||||
|
||||
if (dialog.ShowModal() == wxID_OK)
|
||||
@@ -2013,10 +2017,12 @@ void MyFrame::FileOpenGeneric(wxCommandEvent& WXUNUSED(event) )
|
||||
wxString info;
|
||||
info.Printf("Full file name: %s\n"
|
||||
"Path: %s\n"
|
||||
"Name: %s",
|
||||
"Name: %s\n"
|
||||
"Custom window: %s",
|
||||
dialog.GetPath(),
|
||||
dialog.GetDirectory(),
|
||||
dialog.GetFilename());
|
||||
dialog.GetFilename(),
|
||||
myCustomizer.GetInfo());
|
||||
wxMessageDialog dialog2(this, info, "Selected file");
|
||||
dialog2.ShowModal();
|
||||
}
|
||||
|
||||
@@ -301,7 +301,17 @@ int wxGenericFileDialog::ShowModal()
|
||||
|
||||
m_filectrl->SetDirectory(m_dir);
|
||||
|
||||
return wxDialog::ShowModal();
|
||||
const int rc = wxDialog::ShowModal();
|
||||
|
||||
// Destroy the extra controls before ShowModal() returns for consistency
|
||||
// with the native implementations.
|
||||
if (m_extraControl)
|
||||
{
|
||||
m_extraControl->Destroy();
|
||||
m_extraControl = NULL;
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
bool wxGenericFileDialog::Show( bool show )
|
||||
@@ -402,6 +412,8 @@ void wxGenericFileDialog::OnUpdateButtonsUI(wxUpdateUIEvent& event)
|
||||
// wxFileCtrl ctor itself can generate idle events, so we need this test
|
||||
if ( m_filectrl )
|
||||
event.Enable( !IsTopMostDir(m_filectrl->GetShownDirectory()) );
|
||||
|
||||
UpdateExtraControlUI();
|
||||
}
|
||||
|
||||
#ifdef wxHAS_GENERIC_FILEDIALOG
|
||||
|
||||
Reference in New Issue
Block a user