Merge branch 'mac-filedlg'

Fix transferring data from custom wxFileDialog controls and some
simplifications in wxOSX wxFileDialog code.

See #22544.
This commit is contained in:
Vadim Zeitlin 2022-06-17 01:10:16 +02:00
commit 49bbb00850
7 changed files with 38 additions and 50 deletions

View file

@ -206,6 +206,9 @@ protected:
// Helper function for native file dialog usage where no wx events
// are processed.
void UpdateExtraControlUI();
// Helper function simply transferring data from custom controls if they
// are used -- must be called if the dialog was accepted.
void TransferDataFromExtraControl();
private:
ExtraControlCreatorFunction m_extraControlCreator;

View file

@ -617,7 +617,6 @@ public:
Panel(wxWindow* parent, wxFileDialogCustomizeHook& customizeHook)
: wxPanel(parent),
wxFileDialogCustomize(this),
m_customizeHook(customizeHook),
m_lastWasRadio(false)
{
// Use a simple horizontal sizer to layout all the controls for now.
@ -628,18 +627,13 @@ public:
sizer->AddSpacer(wxSizerFlags::GetDefaultBorder());
// This will call our own AddXXX().
m_customizeHook.AddCustomControls(*this);
customizeHook.AddCustomControls(*this);
// Now that everything was created, resize and layout.
SetClientSize(sizer->ComputeFittingClientSize(this));
sizer->Layout();
}
virtual ~Panel()
{
m_customizeHook.TransferDataFromCustomControls();
}
// Implement wxFileDialogCustomizeImpl pure virtual methods.
wxFileDialogButtonImpl* AddButton(const wxString& label) wxOVERRIDE
@ -720,8 +714,6 @@ private:
}
wxFileDialogCustomizeHook& m_customizeHook;
bool m_lastWasRadio;
wxDECLARE_NO_COPY_CLASS(Panel);
@ -921,6 +913,12 @@ void wxFileDialogBase::UpdateExtraControlUI()
m_extraControl->UpdateWindowUI(wxUPDATE_UI_RECURSE);
}
void wxFileDialogBase::TransferDataFromExtraControl()
{
if ( m_customizeHook )
m_customizeHook->TransferDataFromCustomControls();
}
void wxFileDialogBase::SetPath(const wxString& path)
{
wxString ext;

View file

@ -366,6 +366,8 @@ void wxGenericFileDialog::OnOk( wxCommandEvent &WXUNUSED(event) )
return;
}
TransferDataFromExtraControl();
EndModal(wxID_OK);
}

View file

@ -370,6 +370,8 @@ void wxFileDialog::OnFakeOk(wxCommandEvent& WXUNUSED(event))
str(gtk_file_chooser_get_current_folder(GTK_FILE_CHOOSER(m_widget)));
m_dir = wxString::FromUTF8(str);
TransferDataFromExtraControl();
EndDialog(wxID_OK);
}

View file

@ -333,6 +333,8 @@ int wxFileDialog::ShowModal()
if (m_fileName.empty())
return wxID_CANCEL;
else
return wxID_OK;
TransferDataFromExtraControl();
return wxID_OK;
}

View file

@ -1144,24 +1144,7 @@ void wxFileDialog::MSWOnTypeChange(int nFilterIndex)
void wxFileDialog::MSWOnFileOK()
{
if ( m_customizeHook )
{
if ( m_extraControl )
{
// If we've created the old style extra controls even though we're
// using the customize hook, we must delete them now, to ensure
// that TransferDataFromCustomControls() called from the extra
// controls panel destructor is called while the controls still
// exist.
DestroyExtraControl();
}
else // This is the normal case, when using IFileDialog.
{
// Just call TransferDataFromCustomControls() directly, it won't be
// called from anywhere else.
m_customizeHook->TransferDataFromCustomControls();
}
}
TransferDataFromExtraControl();
}
// helper used below in ShowCommFileDialog(): style is used to determine

View file

@ -627,32 +627,24 @@ int wxFileDialog::ShowModal()
void wxFileDialog::ModalFinishedCallback(void* panel, int returnCode)
{
int result = wxID_CANCEL;
NSSavePanel* const sPanel = static_cast<NSSavePanel*>(panel);
const bool wasAccepted = returnCode == NSModalResponseOK;
if (HasFlag(wxFD_SAVE))
{
if (returnCode == NSModalResponseOK )
if (wasAccepted)
{
NSSavePanel* sPanel = (NSSavePanel*)panel;
result = wxID_OK;
NSString* unsafePath = [NSString stringWithUTF8String:[[sPanel URL] fileSystemRepresentation]];
m_path = wxCFStringRef([[unsafePath precomposedStringWithCanonicalMapping] retain]).AsString();
m_fileName = wxFileNameFromPath(m_path);
m_dir = wxPathOnly( m_path );
if (m_filterChoice)
m_filterIndex = m_filterChoice->GetSelection();
else
m_filterIndex = GetMatchingFilterExtension(m_fileName);
}
}
else
{
NSOpenPanel* oPanel = (NSOpenPanel*)panel;
if (returnCode == NSModalResponseOK )
NSOpenPanel* const oPanel = static_cast<NSOpenPanel*>(sPanel);
if (wasAccepted)
{
panel = oPanel;
result = wxID_OK;
bool isFirst = true;
for (NSURL* filename in [oPanel URLs])
{
@ -668,11 +660,6 @@ void wxFileDialog::ModalFinishedCallback(void* panel, int returnCode)
isFirst = false;
}
}
if (m_filterChoice)
m_filterIndex = m_filterChoice->GetSelection();
else
m_filterIndex = GetMatchingFilterExtension(m_fileName);
}
if ( m_delegate )
{
@ -681,7 +668,18 @@ void wxFileDialog::ModalFinishedCallback(void* panel, int returnCode)
m_delegate = nil;
}
}
SetReturnCode(result);
if (wasAccepted)
{
if (m_filterChoice)
m_filterIndex = m_filterChoice->GetSelection();
else
m_filterIndex = GetMatchingFilterExtension(m_fileName);
TransferDataFromExtraControl();
}
SetReturnCode(wasAccepted ? wxID_OK : wxID_CANCEL);
// workaround for sandboxed app, see above, must be executed before window modal handler
// because there this instance will be deleted
@ -691,7 +689,7 @@ void wxFileDialog::ModalFinishedCallback(void* panel, int returnCode)
if (GetModality() == wxDIALOG_MODALITY_WINDOW_MODAL)
SendWindowModalDialogEvent ( wxEVT_WINDOW_MODAL_DIALOG_CLOSED );
[(NSSavePanel*) panel setAccessoryView:nil];
[sPanel setAccessoryView:nil];
}
#endif // wxUSE_FILEDLG