From 7430a4bbf8bcbff0497449568f51eef0907ad790 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 26 Nov 2009 16:17:00 +0000 Subject: [PATCH] Make wxFileDialog::Set/SetPath() behave consistently. wxFileDialog::GetPath() didn't return the value set by a previous call to SetPath() in wxMSW version. Fix this and also implement SetPath() and SetDirectory() methods in the generic versions in the same way as SetFilename(). Closes #3672. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@62722 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/filedlg.h | 6 +++--- include/wx/generic/filedlgg.h | 4 ++++ include/wx/msw/filedlg.h | 1 - src/common/fldlgcmn.cpp | 22 ++++++++++++++++++++++ src/msw/filedlg.cpp | 8 -------- 5 files changed, 29 insertions(+), 12 deletions(-) diff --git a/include/wx/filedlg.h b/include/wx/filedlg.h index 11e720f864..f0b23110a6 100644 --- a/include/wx/filedlg.h +++ b/include/wx/filedlg.h @@ -107,9 +107,9 @@ public: bool HasFdFlag(int flag) const { return HasFlag(flag); } virtual void SetMessage(const wxString& message) { m_message = message; } - virtual void SetPath(const wxString& path) { m_path = path; } - virtual void SetDirectory(const wxString& dir) { m_dir = dir; } - virtual void SetFilename(const wxString& name) { m_fileName = name; } + virtual void SetPath(const wxString& path); + virtual void SetDirectory(const wxString& dir); + virtual void SetFilename(const wxString& name); virtual void SetWildcard(const wxString& wildCard) { m_wildCard = wildCard; } virtual void SetFilterIndex(int filterIndex) { m_filterIndex = filterIndex; } diff --git a/include/wx/generic/filedlgg.h b/include/wx/generic/filedlgg.h index 2f66fee199..b4f35b3afd 100644 --- a/include/wx/generic/filedlgg.h +++ b/include/wx/generic/filedlgg.h @@ -61,6 +61,10 @@ public: virtual ~wxGenericFileDialog(); + virtual void SetDirectory(const wxString& dir) + { m_filectrl->SetDirectory(dir); } + virtual void SetFilename(const wxString& name) + { m_filectrl->SetFilename(name); } virtual void SetMessage(const wxString& message) { SetTitle(message); } virtual void SetPath(const wxString& path) { m_filectrl->SetPath(path); } diff --git a/include/wx/msw/filedlg.h b/include/wx/msw/filedlg.h index 9f7fd8b34e..4c4ec74993 100644 --- a/include/wx/msw/filedlg.h +++ b/include/wx/msw/filedlg.h @@ -29,7 +29,6 @@ public: const wxSize& sz = wxDefaultSize, const wxString& name = wxFileDialogNameStr); - virtual void SetPath(const wxString& path); virtual void GetPaths(wxArrayString& paths) const; virtual void GetFilenames(wxArrayString& files) const; #ifndef __WXWINCE__ diff --git a/src/common/fldlgcmn.cpp b/src/common/fldlgcmn.cpp index 1d68284280..f4b4e0a778 100644 --- a/src/common/fldlgcmn.cpp +++ b/src/common/fldlgcmn.cpp @@ -20,6 +20,7 @@ #include "wx/filedlg.h" #include "wx/dirdlg.h" +#include "wx/filename.h" #ifndef WX_PRECOMP #include "wx/string.h" @@ -180,6 +181,27 @@ wxSize wxFileDialogBase::GetExtraControlSize() return (*m_extraControlCreator)(&dlg)->GetSize(); } +void wxFileDialogBase::SetPath(const wxString& path) +{ + wxString ext; + wxFileName::SplitPath(path, &m_dir, &m_fileName, &ext); + if ( !ext.empty() ) + m_fileName << _T('.') << ext; + m_path = path; +} + +void wxFileDialogBase::SetDirectory(const wxString& dir) +{ + m_dir = dir; + m_path = wxFileName(m_dir, m_fileName).GetFullPath(); +} + +void wxFileDialogBase::SetFilename(const wxString& name) +{ + m_fileName = name; + m_path = wxFileName(m_dir, m_fileName).GetFullPath(); +} + //---------------------------------------------------------------------------- // wxFileDialog convenience functions //---------------------------------------------------------------------------- diff --git a/src/msw/filedlg.cpp b/src/msw/filedlg.cpp index 8aae8b46b1..1fb4bc288c 100644 --- a/src/msw/filedlg.cpp +++ b/src/msw/filedlg.cpp @@ -174,14 +174,6 @@ void wxFileDialog::GetFilenames(wxArrayString& files) const files = m_fileNames; } -void wxFileDialog::SetPath(const wxString& path) -{ - wxString ext; - wxFileName::SplitPath(path, &m_dir, &m_fileName, &ext); - if ( !ext.empty() ) - m_fileName << wxT('.') << ext; -} - void wxFileDialog::DoGetPosition(int *x, int *y) const { if ( x ) -- 2.45.2