Merge branch 'mac-filedlg-improvements' of https://github.com/discnl/wxWidgets
macOS wxFileDialog improvements. See https://github.com/wxWidgets/wxWidgets/pull/2234
This commit is contained in:
@@ -181,6 +181,9 @@ protected:
|
||||
{ return m_extraControlCreator != NULL; }
|
||||
// get the size of the extra control by creating and deleting it
|
||||
wxSize GetExtraControlSize();
|
||||
// Helper function for native file dialog usage where no wx events
|
||||
// are processed.
|
||||
void UpdateExtraControlUI();
|
||||
|
||||
private:
|
||||
ExtraControlCreatorFunction m_extraControlCreator;
|
||||
|
@@ -236,10 +236,11 @@ public:
|
||||
control to update its state depending on the currently selected file
|
||||
type filter.
|
||||
|
||||
Currently this function is fully implemented only under MSW and
|
||||
Currently this function is fully implemented under macOS and MSW and
|
||||
always returns @c wxNOT_FOUND elsewhere.
|
||||
|
||||
@since 3.1.3
|
||||
@since 3.1.3 - MSW
|
||||
@since 3.1.5 - macOS
|
||||
|
||||
@return The 0-based index of the currently selected file type filter or
|
||||
wxNOT_FOUND if nothing is selected.
|
||||
|
@@ -203,6 +203,7 @@ wxBEGIN_EVENT_TABLE(MyFrame, wxFrame)
|
||||
EVT_MENU(DIALOGS_FILES_OPEN_WINDOW_MODAL, MyFrame::FilesOpenWindowModal)
|
||||
EVT_MENU(DIALOGS_FILE_SAVE, MyFrame::FileSave)
|
||||
EVT_MENU(DIALOGS_FILE_SAVE_WINDOW_MODAL, MyFrame::FileSaveWindowModal)
|
||||
EVT_MENU(DIALOGS_MAC_TOGGLE_ALWAYS_SHOW_TYPES, MyFrame::MacToggleAlwaysShowTypes)
|
||||
#endif // wxUSE_FILEDLG
|
||||
|
||||
#if USE_FILEDLG_GENERIC
|
||||
@@ -504,6 +505,13 @@ bool MyApp::OnInit()
|
||||
filedlg_menu->Append(DIALOGS_FILE_SAVE_GENERIC, "Sa&ve file (generic)");
|
||||
#endif // USE_FILEDLG_GENERIC
|
||||
|
||||
#ifdef __WXOSX_COCOA__
|
||||
filedlg_menu->AppendSeparator();
|
||||
filedlg_menu->AppendCheckItem(DIALOGS_MAC_TOGGLE_ALWAYS_SHOW_TYPES,
|
||||
"macOS only: Toggle open file "
|
||||
"\"Always show types\"\tRawCtrl+Ctrl+S");
|
||||
#endif
|
||||
|
||||
menuDlg->Append(wxID_ANY,"&File operations",filedlg_menu);
|
||||
|
||||
#endif // wxUSE_FILEDLG
|
||||
@@ -1853,6 +1861,16 @@ void MyFrame::FileSaveWindowModalClosed(wxWindowModalDialogEvent& event)
|
||||
|
||||
#endif // wxUSE_FILEDLG
|
||||
|
||||
void MyFrame::MacToggleAlwaysShowTypes(wxCommandEvent& event)
|
||||
{
|
||||
#ifdef wxOSX_FILEDIALOG_ALWAYS_SHOW_TYPES
|
||||
wxSystemOptions::SetOption(wxOSX_FILEDIALOG_ALWAYS_SHOW_TYPES,
|
||||
event.IsChecked());
|
||||
#else
|
||||
wxUnusedVar(event);
|
||||
#endif
|
||||
}
|
||||
|
||||
#if USE_FILEDLG_GENERIC
|
||||
void MyFrame::FileOpenGeneric(wxCommandEvent& WXUNUSED(event) )
|
||||
{
|
||||
|
@@ -433,6 +433,7 @@ public:
|
||||
void FileSave(wxCommandEvent& event);
|
||||
void FileSaveWindowModal(wxCommandEvent& event);
|
||||
void FileSaveWindowModalClosed(wxWindowModalDialogEvent& event);
|
||||
void MacToggleAlwaysShowTypes(wxCommandEvent& event);
|
||||
#endif // wxUSE_FILEDLG
|
||||
|
||||
#if USE_FILEDLG_GENERIC
|
||||
@@ -616,6 +617,7 @@ enum
|
||||
DIALOGS_FILE_OPEN_GENERIC,
|
||||
DIALOGS_FILES_OPEN_GENERIC,
|
||||
DIALOGS_FILE_SAVE_GENERIC,
|
||||
DIALOGS_MAC_TOGGLE_ALWAYS_SHOW_TYPES,
|
||||
DIALOGS_DIR_CHOOSE,
|
||||
DIALOGS_DIR_CHOOSE_WINDOW_MODAL,
|
||||
DIALOGS_DIRNEW_CHOOSE,
|
||||
|
@@ -192,6 +192,12 @@ wxSize wxFileDialogBase::GetExtraControlSize()
|
||||
return (*m_extraControlCreator)(&dlg)->GetSize();
|
||||
}
|
||||
|
||||
void wxFileDialogBase::UpdateExtraControlUI()
|
||||
{
|
||||
if ( m_extraControl )
|
||||
m_extraControl->UpdateWindowUI(wxUPDATE_UI_RECURSE);
|
||||
}
|
||||
|
||||
void wxFileDialogBase::SetPath(const wxString& path)
|
||||
{
|
||||
wxString ext;
|
||||
|
@@ -496,8 +496,7 @@ void wxFileDialog::GTKSelectionChanged(const wxString& filename)
|
||||
{
|
||||
m_currentlySelectedFilename = filename;
|
||||
|
||||
if (m_extraControl)
|
||||
m_extraControl->UpdateWindowUI(wxUPDATE_UI_RECURSE);
|
||||
UpdateExtraControlUI();
|
||||
}
|
||||
|
||||
#endif // wxUSE_FILEDLG
|
||||
|
@@ -353,8 +353,7 @@ void wxFileDialog::MSWOnSelChange(WXHWND hDlg)
|
||||
else
|
||||
m_currentlySelectedFilename.clear();
|
||||
|
||||
if ( m_extraControl )
|
||||
m_extraControl->UpdateWindowUI(wxUPDATE_UI_RECURSE);
|
||||
UpdateExtraControlUI();
|
||||
}
|
||||
|
||||
void wxFileDialog::MSWOnTypeChange(WXHWND WXUNUSED(hDlg), int nFilterIndex)
|
||||
@@ -364,8 +363,7 @@ void wxFileDialog::MSWOnTypeChange(WXHWND WXUNUSED(hDlg), int nFilterIndex)
|
||||
// circumstances, so take care before decrementing it.
|
||||
m_currentlySelectedFilterIndex = nFilterIndex ? nFilterIndex - 1 : 0;
|
||||
|
||||
if ( m_extraControl )
|
||||
m_extraControl->UpdateWindowUI(wxUPDATE_UI_RECURSE);
|
||||
UpdateExtraControlUI();
|
||||
}
|
||||
|
||||
// helper used below in ShowCommFileDialog(): style is used to determine
|
||||
|
@@ -246,25 +246,36 @@ void wxFileDialog::ShowWindowModal()
|
||||
|
||||
}
|
||||
|
||||
// Create a panel with the file type drop down list
|
||||
// If extra controls need to be added (see wxFileDialog::SetExtraControlCreator), add
|
||||
// them to the panel as well
|
||||
// Returns the newly created wxPanel
|
||||
// Fill a new or existing panel with the file type drop down list.
|
||||
// If extra controls need to be added (see wxFileDialog::SetExtraControlCreator),
|
||||
// use that as a panel if possible, otherwise add them to a new panel.
|
||||
// Returns a newly created wxPanel or extracontrol if it's suitable as a filter
|
||||
// panel.
|
||||
|
||||
wxWindow* wxFileDialog::CreateFilterPanel(wxWindow *extracontrol)
|
||||
{
|
||||
wxPanel *extrapanel = new wxPanel(this, wxID_ANY, wxDefaultPosition, wxDefaultSize);
|
||||
// Try to use extracontrol as a filter panel instead of creating a new one
|
||||
// and then reparenting extracontrol. Reparenting is less desired as user
|
||||
// code may expect the parent to be a wxFileDialog as on other platforms.
|
||||
const bool useExtraControlAsPanel = extracontrol &&
|
||||
wxDynamicCast(extracontrol, wxPanel) != NULL;
|
||||
|
||||
wxWindow* extrapanel = useExtraControlAsPanel
|
||||
? extracontrol
|
||||
: static_cast<wxWindow*>(new wxPanel(this));
|
||||
|
||||
wxBoxSizer *verticalSizer = new wxBoxSizer(wxVERTICAL);
|
||||
extrapanel->SetSizer(verticalSizer);
|
||||
|
||||
// the file type control
|
||||
{
|
||||
wxBoxSizer *horizontalSizer = new wxBoxSizer(wxHORIZONTAL);
|
||||
verticalSizer->Add(horizontalSizer, 0, wxEXPAND, 0);
|
||||
horizontalSizer->AddStretchSpacer();
|
||||
wxStaticText *stattext = new wxStaticText( extrapanel, wxID_ANY, _("File type:") );
|
||||
horizontalSizer->Add(stattext, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
|
||||
m_filterChoice = new wxChoice(extrapanel, wxID_ANY);
|
||||
horizontalSizer->Add(m_filterChoice, 1, wxALIGN_CENTER_VERTICAL|wxALL, 5);
|
||||
horizontalSizer->Add(m_filterChoice, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5);
|
||||
horizontalSizer->AddStretchSpacer();
|
||||
m_filterChoice->Append(m_filterNames);
|
||||
if( m_filterNames.GetCount() > 0)
|
||||
{
|
||||
@@ -276,13 +287,29 @@ wxWindow* wxFileDialog::CreateFilterPanel(wxWindow *extracontrol)
|
||||
|
||||
if(extracontrol)
|
||||
{
|
||||
wxBoxSizer *horizontalSizer = new wxBoxSizer(wxHORIZONTAL);
|
||||
verticalSizer->Add(horizontalSizer, 0, wxEXPAND, 0);
|
||||
// Either use an extra control's existing sizer or the extra control
|
||||
// itself, to be in the vertical sizer.
|
||||
|
||||
extracontrol->Reparent(extrapanel);
|
||||
horizontalSizer->Add(extracontrol);
|
||||
wxSizer* existingSizer = extracontrol->GetSizer();
|
||||
if ( useExtraControlAsPanel && existingSizer )
|
||||
{
|
||||
// Move extra control's sizer to verticalSizer.
|
||||
extracontrol->SetSizer(NULL, /* deleteOld = */ false);
|
||||
verticalSizer->Add(existingSizer);
|
||||
}
|
||||
else
|
||||
{
|
||||
wxBoxSizer* horizontalSizer = new wxBoxSizer(wxHORIZONTAL);
|
||||
verticalSizer->Add(horizontalSizer, 0, wxEXPAND, 0);
|
||||
|
||||
if ( !useExtraControlAsPanel )
|
||||
extracontrol->Reparent(extrapanel);
|
||||
horizontalSizer->Add(extracontrol);
|
||||
}
|
||||
}
|
||||
|
||||
extrapanel->SetSizer(verticalSizer);
|
||||
|
||||
verticalSizer->Layout();
|
||||
verticalSizer->SetSizeHints(extrapanel);
|
||||
return extrapanel;
|
||||
@@ -293,6 +320,10 @@ void wxFileDialog::DoOnFilterSelected(int index)
|
||||
NSArray* types = GetTypesFromExtension(m_filterExtensions[index],m_currentExtensions);
|
||||
NSSavePanel* panel = (NSSavePanel*) GetWXWindow();
|
||||
[panel setAllowedFileTypes:types];
|
||||
|
||||
m_currentlySelectedFilterIndex = index;
|
||||
|
||||
UpdateExtraControlUI();
|
||||
}
|
||||
|
||||
// An item has been selected in the file filter wxChoice:
|
||||
|
Reference in New Issue
Block a user