From 3ccea0978ce5a3f4f68c3abdb3f4aa0e60f49fc4 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 13 Sep 2012 17:14:37 +0000 Subject: [PATCH] Don't ignore invalid files entered into wxFileDirPickerCtrlBase. File/directory picker controls with wxFLP_FILE_MUST_EXIST/wxDIRP_DIR_MUST_EXIST style simply ignored any value entered by user if it didn't correspond to an existing file/directory. This meant that the program didn't use the value that was shown on the screen resulting in very confusing UI -- e.g. a program could complain that no value was entered when actually it was and just corresponded to a non-existing file. As we can't prevent the entry of arbitrary strings in the text field of the file picker control, stop pretending that we can validate it and just update the control value, and send the corresponding event, whenever the text control value changes. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@72475 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/filepicker.h | 5 ----- src/common/filepickercmn.cpp | 26 +++++++------------------- 2 files changed, 7 insertions(+), 24 deletions(-) diff --git a/include/wx/filepicker.h b/include/wx/filepicker.h index 7445ff6c89..7d1ebc8762 100644 --- a/include/wx/filepicker.h +++ b/include/wx/filepicker.h @@ -183,11 +183,6 @@ public: // internal functions // event handler for our picker void OnFileDirChange(wxFileDirPickerEvent &); - // Returns TRUE if the current path is a valid one - // (i.e. a valid file for a wxFilePickerWidget or a valid - // folder for a wxDirPickerWidget). - virtual bool CheckPath(const wxString &str) const = 0; - // TRUE if any textctrl change should update the current working directory virtual bool IsCwdToUpdate() const = 0; diff --git a/src/common/filepickercmn.cpp b/src/common/filepickercmn.cpp index 49abded37f..c6dd71d6d0 100644 --- a/src/common/filepickercmn.cpp +++ b/src/common/filepickercmn.cpp @@ -63,8 +63,6 @@ bool wxFileDirPickerCtrlBase::CreateBase(wxWindow *parent, const wxValidator& validator, const wxString &name ) { - wxASSERT_MSG(path.empty() || CheckPath(path), wxT("Invalid initial path!")); - if (!wxPickerBase::CreateBase(parent, id, path, pos, size, style, validator, name)) return false; @@ -119,8 +117,13 @@ void wxFileDirPickerCtrlBase::UpdatePickerFromTextCtrl() // string otherwise we would generate a wxFileDirPickerEvent when changing // from e.g. /home/user to /home/user/ and we want to avoid it ! wxString newpath(GetTextCtrlValue()); - if (!CheckPath(newpath)) - return; // invalid user input + + // Notice that we use to check here whether the current path is valid, i.e. + // if the corresponding file or directory exists for the controls with + // wxFLP_FILE_MUST_EXIST or wxDIRP_DIR_MUST_EXIST flag, however we don't do + // this any more as we still must notify the program about any changes in + // the control, otherwise its view of it would be different from what is + // actually shown on the screen, resulting in very confusing UI. if (m_pickerIface->GetPath() != newpath) { @@ -199,15 +202,6 @@ bool wxFilePickerCtrl::Create(wxWindow *parent, return true; } -bool wxFilePickerCtrl::CheckPath(const wxString& path) const -{ - // if wxFLP_SAVE was given or wxFLP_FILE_MUST_EXIST has NOT been given we - // must accept any path - return HasFlag(wxFLP_SAVE) || - !HasFlag(wxFLP_FILE_MUST_EXIST) || - wxFileName::FileExists(path); -} - wxString wxFilePickerCtrl::GetTextCtrlValue() const { // filter it through wxFileName to remove any spurious path separator @@ -246,12 +240,6 @@ bool wxDirPickerCtrl::Create(wxWindow *parent, return true; } -bool wxDirPickerCtrl::CheckPath(const wxString& path) const -{ - // if wxDIRP_DIR_MUST_EXIST has NOT been given we must accept any path - return !HasFlag(wxDIRP_DIR_MUST_EXIST) || wxFileName::DirExists(path); -} - wxString wxDirPickerCtrl::GetTextCtrlValue() const { // filter it through wxFileName to remove any spurious path separator -- 2.47.2