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
// event handler for our picker
void OnFileDirChange(wxFileDirPickerEvent &);
// 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;
// TRUE if any textctrl change should update the current working directory
virtual bool IsCwdToUpdate() const = 0;
const wxValidator& validator,
const wxString &name )
{
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;
if (!wxPickerBase::CreateBase(parent, id, path, pos, size,
style, validator, name))
return false;
// 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());
// 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)
{
if (m_pickerIface->GetPath() != newpath)
{
-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
wxString wxFilePickerCtrl::GetTextCtrlValue() const
{
// filter it through wxFileName to remove any spurious path separator
-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
wxString wxDirPickerCtrl::GetTextCtrlValue() const
{
// filter it through wxFileName to remove any spurious path separator