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
This commit is contained in:
Vadim Zeitlin
2012-09-13 17:14:37 +00:00
parent be7a086c0c
commit 3ccea0978c
2 changed files with 7 additions and 24 deletions

View File

@@ -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;

View File

@@ -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