Add an example of customizing "Save" file dialog too

Show doing it in the sample and also add a missing line to the example
in the documentation.
This commit is contained in:
Vadim Zeitlin 2022-06-12 00:32:36 +01:00
parent 88bade66ac
commit 475c2ca201
2 changed files with 35 additions and 2 deletions

View File

@ -331,6 +331,7 @@ public:
// This object may be destroyed before the dialog, but must remain
// alive until ShowModal() returns.
EncryptHook customizeHook;
dialog.SetCustomizeHook(customHook);
if ( dialog.ShowModal() == wxID_OK )
{

View File

@ -2009,10 +2009,42 @@ void MyFrame::FileSave(wxCommandEvent& WXUNUSED(event) )
dialog.SetFilterIndex(1);
// This tests the (even more simplified) example from the docs.
class EncryptHook : public wxFileDialogCustomizeHook
{
public:
EncryptHook()
: m_encrypt(false)
{
}
void AddCustomControls(wxFileDialogCustomize& customizer) wxOVERRIDE
{
m_checkbox = customizer.AddCheckBox("Encrypt");
}
void TransferDataFromCustomControls() wxOVERRIDE
{
m_encrypt = m_checkbox->GetValue();
}
bool Encrypt() const { return m_encrypt; }
private:
wxFileDialogCheckBox* m_checkbox;
bool m_encrypt;
};
EncryptHook customHook;
dialog.SetCustomizeHook(customHook);
if (dialog.ShowModal() == wxID_OK)
{
wxLogMessage("%s, filter %d",
dialog.GetPath(), dialog.GetFilterIndex());
wxLogMessage("%s, filter %d%s",
dialog.GetPath(),
dialog.GetFilterIndex(),
customHook.Encrypt() ? ", encrypt" : "");
}
}