From a47fd95e45d6fa0e39fc947bb036796e4fe81928 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 10 Jul 2020 03:52:15 +0200 Subject: [PATCH] Avoid overriding wxDirDialog::GetPath[s]() unnecessarily Don't duplicate practically the same code in all ports, just add m_paths itself to the base class. The only drawback of doing this is that it's unused in the ports not (yet) using it, but this saves enough code in the aggregate to be worth it. --- include/wx/dirdlg.h | 7 ++++--- include/wx/gtk/dirdlg.h | 4 ---- include/wx/msw/dirdlg.h | 9 --------- include/wx/osx/dirdlg.h | 5 ----- src/gtk/dirdlg.cpp | 16 +++++----------- src/msw/dirdlg.cpp | 15 +-------------- src/osx/cocoa/dirdlg.mm | 17 +++++------------ 7 files changed, 15 insertions(+), 58 deletions(-) diff --git a/include/wx/dirdlg.h b/include/wx/dirdlg.h index edad929cfe..fba5f4d6e4 100644 --- a/include/wx/dirdlg.h +++ b/include/wx/dirdlg.h @@ -90,19 +90,20 @@ public: virtual wxString GetMessage() const { return m_message; } virtual wxString GetPath() const { - wxCHECK_MSG( !HasFlag(wxDD_MULTIPLE), wxString(), "When using wxDD_MULTIPLE, must call GetPaths() instead" ); + wxCHECK_MSG( !HasFlag(wxDD_MULTIPLE), wxString(), + "When using wxDD_MULTIPLE, must call GetPaths() instead" ); return m_path; } virtual void GetPaths(wxArrayString& paths) const { - paths.clear(); - paths.push_back(m_path); + paths = m_paths; } protected: wxString m_message; wxString m_path; + wxArrayString m_paths; }; diff --git a/include/wx/gtk/dirdlg.h b/include/wx/gtk/dirdlg.h index d4b00cf0d8..e8029a21c7 100644 --- a/include/wx/gtk/dirdlg.h +++ b/include/wx/gtk/dirdlg.h @@ -37,9 +37,7 @@ public: public: // overrides from wxGenericDirDialog - wxString GetPath() const wxOVERRIDE; void SetPath(const wxString& path) wxOVERRIDE; - void GetPaths(wxArrayString& paths) const wxOVERRIDE; // Implementation only. @@ -56,8 +54,6 @@ protected: private: - wxArrayString m_paths; - wxDECLARE_DYNAMIC_CLASS(wxDirDialog); }; diff --git a/include/wx/msw/dirdlg.h b/include/wx/msw/dirdlg.h index c06404cd0f..b99ff5b4f8 100644 --- a/include/wx/msw/dirdlg.h +++ b/include/wx/msw/dirdlg.h @@ -24,18 +24,9 @@ public: void SetPath(const wxString& path) wxOVERRIDE; - // can be used only when wxDD_MULTIPLE flag is not set - wxString GetPath() const wxOVERRIDE; - - // should be used only when wxDD_MULTIPLE flag is set - void GetPaths(wxArrayString& paths) const wxOVERRIDE; - virtual int ShowModal() wxOVERRIDE; private: - // Used for wxDD_MULTIPLE - wxArrayString m_paths; - // The real implementations of ShowModal(), used for Windows versions // before and since Vista. int ShowSHBrowseForFolder(WXHWND owner); diff --git a/include/wx/osx/dirdlg.h b/include/wx/osx/dirdlg.h index ea95b70c5a..376905b029 100644 --- a/include/wx/osx/dirdlg.h +++ b/include/wx/osx/dirdlg.h @@ -51,10 +51,6 @@ public: // 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; - - #if wxOSX_USE_COCOA virtual void ShowWindowModal() wxOVERRIDE; virtual void ModalFinishedCallback(void* panel, int returnCode) wxOVERRIDE; @@ -72,7 +68,6 @@ private: // Common part of all ctors. void Init(); - wxArrayString m_paths; wxString m_title; wxDECLARE_DYNAMIC_CLASS(wxDirDialog); diff --git a/src/gtk/dirdlg.cpp b/src/gtk/dirdlg.cpp index b7246b262e..317acab13e 100644 --- a/src/gtk/dirdlg.cpp +++ b/src/gtk/dirdlg.cpp @@ -163,6 +163,11 @@ void wxDirDialog::GTKOnAccept() wxSetWorkingDirectory(m_paths.Last()); } + if (!HasFlag(wxDD_MULTIPLE)) + { + m_path = m_paths.Last(); + } + EndDialog(wxID_OK); } @@ -188,15 +193,4 @@ void wxDirDialog::SetPath(const wxString& dir) } } -wxString wxDirDialog::GetPath() const -{ - wxCHECK_MSG( !HasFlag(wxDD_MULTIPLE), wxString(), "When using wxDD_MULTIPLE, must call GetPaths() instead" ); - return m_paths.Last(); -} - -void wxDirDialog::GetPaths(wxArrayString& paths) const -{ - paths = m_paths; -} - #endif // wxUSE_DIRDLG diff --git a/src/msw/dirdlg.cpp b/src/msw/dirdlg.cpp index 3e8044d1d5..21e0dc8224 100644 --- a/src/msw/dirdlg.cpp +++ b/src/msw/dirdlg.cpp @@ -151,19 +151,6 @@ void wxDirDialog::SetPath(const wxString& path) } } -wxString wxDirDialog::GetPath() const -{ - wxCHECK_MSG( !HasFlag(wxDD_MULTIPLE), wxEmptyString, - "When using wxDD_MULTIPLE, must call GetPaths() instead" ); - - return m_path; -} - -void wxDirDialog::GetPaths(wxArrayString& paths) const -{ - paths = m_paths; -} - int wxDirDialog::ShowModal() { WX_HOOK_MODAL_DIALOG(); @@ -293,7 +280,7 @@ int wxDirDialog::ShowIFileOpenDialog(WXHWND owner) { if ( !HasFlag(wxDD_MULTIPLE) ) { - m_path = m_paths.front(); + m_path = m_paths.Last(); } return wxID_OK; diff --git a/src/osx/cocoa/dirdlg.mm b/src/osx/cocoa/dirdlg.mm index 8e446a8d10..373e1e8a94 100644 --- a/src/osx/cocoa/dirdlg.mm +++ b/src/osx/cocoa/dirdlg.mm @@ -157,6 +157,11 @@ void wxDirDialog::ModalFinishedCallback(void* panel, int returnCode) m_paths.Add([url fileSystemRepresentation]); } + if ( !HasFlag(wxDD_MULTIPLE) ) + { + m_path = m_paths.Last(); + } + result = wxID_OK; } SetReturnCode(result); @@ -171,16 +176,4 @@ void wxDirDialog::SetTitle(const wxString &title) wxDialog::SetTitle(title); } -wxString wxDirDialog::GetPath() const -{ - wxCHECK_MSG( !HasFlag(wxDD_MULTIPLE), wxString(), "When using wxDD_MULTIPLE, must call GetPaths() instead" ); - return m_paths.Last(); -} - -void wxDirDialog::GetPaths(wxArrayString& paths) const -{ - paths = m_paths; -} - - #endif // wxUSE_DIRDLG