diff --git a/docs/changes.txt b/docs/changes.txt index 48230da796..91e460d770 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -99,6 +99,9 @@ Changes in behaviour not resulting in compilation errors - wxSizer::RecalcSizes() shouldn't be called directly (note that it was never supposed to be called, only implemented), call Layout() instead. +- wxFileDialog::GetPath() and wxFileDialog::GetFilename() now assert and return + an empty string if called on dialogs with the wxFD_MULTIPLE style. + Changes in behaviour which may result in build errors ----------------------------------------------------- diff --git a/include/wx/filedlg.h b/include/wx/filedlg.h index d1a451f657..da0cb96c13 100644 --- a/include/wx/filedlg.h +++ b/include/wx/filedlg.h @@ -104,10 +104,19 @@ public: virtual void SetFilterIndex(int filterIndex) { m_filterIndex = filterIndex; } virtual wxString GetMessage() const { return m_message; } - virtual wxString GetPath() const { return m_path; } + virtual wxString GetPath() const + { + wxCHECK_MSG( !HasFlag(wxFD_MULTIPLE), wxString(), "When using wxFD_MULTIPLE, must call GetPaths() instead" ); + return m_path; + } + virtual void GetPaths(wxArrayString& paths) const { paths.Empty(); paths.Add(m_path); } virtual wxString GetDirectory() const { return m_dir; } - virtual wxString GetFilename() const { return m_fileName; } + virtual wxString GetFilename() const + { + wxCHECK_MSG( !HasFlag(wxFD_MULTIPLE), wxString(), "When using wxFD_MULTIPLE, must call GetFilenames() instead" ); + return m_fileName; + } virtual void GetFilenames(wxArrayString& files) const { files.Empty(); files.Add(m_fileName); } virtual wxString GetWildcard() const { return m_wildCard; } virtual int GetFilterIndex() const { return m_filterIndex; } diff --git a/include/wx/generic/filedlgg.h b/include/wx/generic/filedlgg.h index 6c00f2020f..29ea5d4d36 100644 --- a/include/wx/generic/filedlgg.h +++ b/include/wx/generic/filedlgg.h @@ -73,13 +73,19 @@ public: { m_filectrl->SetWildcard(wildCard); } virtual wxString GetPath() const wxOVERRIDE - { return m_filectrl->GetPath(); } + { + wxCHECK_MSG( !HasFlag(wxFD_MULTIPLE), wxString(), "When using wxFD_MULTIPLE, must call GetPaths() instead" ); + return m_filectrl->GetPath(); + } virtual void GetPaths(wxArrayString& paths) const wxOVERRIDE { m_filectrl->GetPaths(paths); } virtual wxString GetDirectory() const wxOVERRIDE { return m_filectrl->GetDirectory(); } virtual wxString GetFilename() const wxOVERRIDE - { return m_filectrl->GetFilename(); } + { + wxCHECK_MSG( !HasFlag(wxFD_MULTIPLE), wxString(), "When using wxFD_MULTIPLE, must call GetFilenames() instead" ); + return m_filectrl->GetFilename(); + } virtual void GetFilenames(wxArrayString& files) const wxOVERRIDE { m_filectrl->GetFilenames(files); } virtual wxString GetWildcard() const wxOVERRIDE diff --git a/interface/wx/filedlg.h b/interface/wx/filedlg.h index c061bc51b7..ab47b84781 100644 --- a/interface/wx/filedlg.h +++ b/interface/wx/filedlg.h @@ -264,6 +264,9 @@ public: /** Returns the default filename. + + @note This function can't be used with dialogs which have the @c wxFD_MULTIPLE style, + use GetFilenames() instead. */ virtual wxString GetFilename() const; @@ -298,6 +301,9 @@ public: /** Returns the full path (directory and filename) of the selected file. + + @note This function can't be used with dialogs which have the @c wxFD_MULTIPLE style, + use GetPaths() instead. */ virtual wxString GetPath() const; diff --git a/src/gtk/filedlg.cpp b/src/gtk/filedlg.cpp index 9439f4b58a..ef23c2de18 100644 --- a/src/gtk/filedlg.cpp +++ b/src/gtk/filedlg.cpp @@ -396,6 +396,7 @@ void wxFileDialog::OnSize(wxSizeEvent&) wxString wxFileDialog::GetPath() const { + wxCHECK_MSG( !HasFlag(wxFD_MULTIPLE), wxString(), "When using wxFD_MULTIPLE, must call GetPaths() instead" ); return m_fc.GetPath(); } @@ -463,6 +464,8 @@ void wxFileDialog::SetFilename(const wxString& name) wxString wxFileDialog::GetFilename() const { + wxCHECK_MSG( !HasFlag(wxFD_MULTIPLE), wxString(), "When using wxFD_MULTIPLE, must call GetFilenames() instead" ); + wxString currentFilename( m_fc.GetFilename() ); if (currentFilename.empty()) { diff --git a/src/qt/filedlg.cpp b/src/qt/filedlg.cpp index 04408ac8ea..f3c4c728be 100644 --- a/src/qt/filedlg.cpp +++ b/src/qt/filedlg.cpp @@ -103,6 +103,8 @@ bool wxFileDialog::Create(wxWindow *parent, wxString wxFileDialog::GetPath() const { + wxCHECK_MSG( !HasFlag(wxFD_MULTIPLE), wxString(), "When using wxFD_MULTIPLE, must call GetPaths() instead" ); + wxArrayString paths; GetPaths(paths); if (paths.empty()) @@ -120,6 +122,8 @@ void wxFileDialog::GetPaths(wxArrayString& paths) const wxString wxFileDialog::GetFilename() const { + wxCHECK_MSG( !HasFlag(wxFD_MULTIPLE), wxString(), "When using wxFD_MULTIPLE, must call GetFilenames() instead" ); + wxArrayString filenames; GetFilenames(filenames); if ( filenames.empty() )