From 475c2ca2019bad974f3b4fe2473a4e2d51fb5d76 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 12 Jun 2022 00:32:36 +0100 Subject: [PATCH] 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. --- interface/wx/filedlgcustomize.h | 1 + samples/dialogs/dialogs.cpp | 36 +++++++++++++++++++++++++++++++-- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/interface/wx/filedlgcustomize.h b/interface/wx/filedlgcustomize.h index e49bbbbf44..818eedc878 100644 --- a/interface/wx/filedlgcustomize.h +++ b/interface/wx/filedlgcustomize.h @@ -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 ) { diff --git a/samples/dialogs/dialogs.cpp b/samples/dialogs/dialogs.cpp index 81458a6d06..581f9428d3 100644 --- a/samples/dialogs/dialogs.cpp +++ b/samples/dialogs/dialogs.cpp @@ -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" : ""); } }