Fix setting the title for the wxDirDialog on OSX

OSX 10.11+ doesn't actually display the title, so update documentation
to reference SetMessage instead. For pre-10.11 override the SetTitle
method to set the title of the NSOpenPanel instead of the window.

Also change so the directory is not updated unless it is provided.

Closes #15143.
This commit is contained in:
Ian McInerney
2020-01-17 00:59:16 +00:00
committed by Vadim Zeitlin
parent 61afcae0be
commit 7230acd110
3 changed files with 22 additions and 0 deletions

View File

@@ -47,6 +47,10 @@ public:
virtual int ShowModal() wxOVERRIDE;
// MacOS 10.11 has removed the titlebar from the dialog, so this is provided
// only for compatibility with older versions
virtual void SetTitle(const wxString& title) wxOVERRIDE;
virtual wxString GetPath() const wxOVERRIDE;
virtual void GetPaths(wxArrayString& paths) const wxOVERRIDE;
@@ -69,6 +73,7 @@ private:
void Init();
wxArrayString m_paths;
wxString m_title;
wxDECLARE_DYNAMIC_CLASS(wxDirDialog);
};

View File

@@ -71,6 +71,11 @@ const char wxDirDialogNameStr[] = "wxDirCtrl";
@endcode
instead of just using @c wxDD_DIR_MUST_EXIST style alone.
@remarks MacOS 10.11+ does not display a title bar on the dialog. Use SetMessage()
to change the string displayed to the user at the top of the dialog after creation.
The SetTitle() method is provided for compatibility with pre-10.11 MacOS versions
that do still support displaying the title bar.
@library{wxcore}
@category{cmndlg}

View File

@@ -73,6 +73,12 @@ WX_NSOpenPanel wxDirDialog::OSXCreatePanel() const
wxCFStringRef cf( m_message );
[oPanel setMessage:cf.AsNSString()];
if ( !m_title.empty() )
{
wxCFStringRef cfTitle(m_title);
[oPanel setTitle:cfTitle.AsNSString()];
}
if ( !HasFlag(wxDD_DIR_MUST_EXIST) )
[oPanel setCanCreateDirectories:YES];
@@ -159,6 +165,12 @@ void wxDirDialog::ModalFinishedCallback(void* panel, int returnCode)
SendWindowModalDialogEvent ( wxEVT_WINDOW_MODAL_DIALOG_CLOSED );
}
void wxDirDialog::SetTitle(const wxString &title)
{
m_title = title;
wxDialog::SetTitle(title);
}
wxString wxDirDialog::GetPath() const
{
return m_paths.Last();