From ade5030c565843de3afac5fc15eb1152e8f9c54e Mon Sep 17 00:00:00 2001 From: Ian McInerney Date: Tue, 2 Jun 2020 10:36:53 +0100 Subject: [PATCH] Warn on incompatible wxDirDialog styles --- include/wx/dirdlg.h | 7 ++++++- interface/wx/dirdlg.h | 3 +++ src/gtk/dirdlg.cpp | 1 + src/osx/cocoa/dirdlg.mm | 1 + 4 files changed, 11 insertions(+), 1 deletion(-) diff --git a/include/wx/dirdlg.h b/include/wx/dirdlg.h index 8a732eef20..8e1a589ee9 100644 --- a/include/wx/dirdlg.h +++ b/include/wx/dirdlg.h @@ -88,7 +88,12 @@ public: virtual void SetPath(const wxString& path) { m_path = path; } virtual wxString GetMessage() const { return m_message; } - virtual wxString GetPath() const { return m_path; } + virtual wxString GetPath() const + { + wxCHECK_MSG( !HasFlag(wxDD_MULTIPLE), wxString(), "When using wxDD_MULTIPLE, must call GetPaths() instead" ); + return m_path; + } + virtual void GetPaths(wxArrayString& paths) const { paths.Empty(); paths.Add(m_path); } protected: diff --git a/interface/wx/dirdlg.h b/interface/wx/dirdlg.h index c8f5b29728..bd46febbec 100644 --- a/interface/wx/dirdlg.h +++ b/interface/wx/dirdlg.h @@ -122,6 +122,9 @@ public: /** Returns the default or user-selected path. + + @note This function can't be used with dialogs which have the @c wxDD_MULTIPLE style, + use GetPaths() instead. */ virtual wxString GetPath() const; diff --git a/src/gtk/dirdlg.cpp b/src/gtk/dirdlg.cpp index 65fa6a6bf5..5aeb52924e 100644 --- a/src/gtk/dirdlg.cpp +++ b/src/gtk/dirdlg.cpp @@ -190,6 +190,7 @@ 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(); } diff --git a/src/osx/cocoa/dirdlg.mm b/src/osx/cocoa/dirdlg.mm index 9c21b7ea95..d526b57774 100644 --- a/src/osx/cocoa/dirdlg.mm +++ b/src/osx/cocoa/dirdlg.mm @@ -173,6 +173,7 @@ void wxDirDialog::SetTitle(const wxString &title) wxString wxDirDialog::GetPath() const { + wxCHECK_MSG( !HasFlag(wxDD_MULTIPLE), wxString(), "When using wxDD_MULTIPLE, must call GetPaths() instead" ); return m_paths.Last(); }