#19163: wxFilePickerCtrl::SetPath() doesn't update the displayed path with wxGTK

59 views
Skip to first unread message

wxTrac

unread,
Apr 27, 2021, 11:40:03 AM4/27/21
to wx-...@googlegroups.com
#19163: wxFilePickerCtrl::SetPath() doesn't update the displayed path with wxGTK
--------------------+--------------------
Reporter: vadz | Owner:
Type: defect | Status: new
Priority: normal | Milestone:
Component: wxGTK | Version: 3.1.5
Keywords: | Blocked By:
Blocking: | Patch: 0
--------------------+--------------------
As [https://stackoverflow.com/questions/67267750/wxfilepickerctrl-not-
actualizing-widget-after-setting-path reported on SO], calling
`wxFilePickerCtrl::SetPath()` doesn't update the path displayed by the
control in wxGTK. This can be seen with e.g. just

{{{
#!diff
diff --git a/samples/widgets/filepicker.cpp
b/samples/widgets/filepicker.cpp
index 8706743858..3dfb72f902 100644
--- a/samples/widgets/filepicker.cpp
+++ b/samples/widgets/filepicker.cpp
@@ -300,6 +300,7 @@ void
FilePickerWidgetsPage::OnButtonSetDir(wxCommandEvent& WXUNUSED(event))

void FilePickerWidgetsPage::OnButtonReset(wxCommandEvent&
WXUNUSED(event))
{
+ m_filePicker->SetPath("/tmp/foo"); return;
Reset();

RecreatePicker();
}}}
and pressing "Reset".

I hoped
{{{
#!diff
diff --git a/src/gtk/filepicker.cpp b/src/gtk/filepicker.cpp
index 600a785cb1..a9e42f0993 100644
--- a/src/gtk/filepicker.cpp
+++ b/src/gtk/filepicker.cpp
@@ -135,6 +135,8 @@ void wxFileButton::SetPath(const wxString &str)
{
m_path = str;

+ if (GTK_IS_FILE_CHOOSER(m_widget))
+ gtk_file_chooser_set_filename((GtkFileChooser*)m_widget,
str.utf8_str());
if (m_dialog)
UpdateDialogPath(m_dialog);
}
}}}
would fix it, but it doesn't seem to have any effect and I don't know why
nor what else could we do here.

--
Ticket URL: <https://trac.wxwidgets.org/ticket/19163>

wxTrac

unread,
Apr 27, 2021, 2:59:19 PM4/27/21
to wx-...@googlegroups.com
#19163: wxFilePickerCtrl::SetPath() doesn't update the displayed path with wxGTK
---------------------+-------------------
Reporter: vadz | Owner:
Type: defect | Status: new
Priority: normal | Milestone:
Component: wxGTK | Version: 3.1.5
Resolution: | Keywords:
Blocked By: | Blocking:
Patch: 0 |
---------------------+-------------------

Comment (by pcor):

The documentation for `gtk_file_chooser_set_filename()` says "Note that
the file must exist, or nothing will be done except for the directory
change."

You can't set a non-existent path into the button. It will appear in the
text control, if there is one.

--
Ticket URL: <https://trac.wxwidgets.org/ticket/19163#comment:1>

wxTrac

unread,
Apr 28, 2021, 3:42:15 AM4/28/21
to wx-...@googlegroups.com
#19163: wxFilePickerCtrl::SetPath() doesn't update the displayed path with wxGTK
----------------------+--------------------
Reporter: vadz | Owner:
Type: defect | Status: closed
Priority: normal | Milestone:
Component: wxGTK | Version: 3.1.5
Resolution: invalid | Keywords:
Blocked By: | Blocking:
Patch: 0 |
----------------------+--------------------
Changes (by vadz):

* status: new => closed
* resolution: => invalid


Comment:

Oops, you're, of course, right, thanks, and I even think I had already run
into this in the past and just forgot about it. It's really annoying that
this `GtkFileChooserButton` is only for choosing the existing files, but I
guess we can't do anything about it and the documentation already mentions
this since 3eae97d2d7 (Improve documentation of pickers MUST_EXIST styles,
2016-06-09), so I'll just close this one.

--
Ticket URL: <https://trac.wxwidgets.org/ticket/19163#comment:2>

wxTrac

unread,
Sep 20, 2021, 12:22:56 PM9/20/21
to wx-...@googlegroups.com
#19163: wxFilePickerCtrl::SetPath() doesn't update the displayed path with wxGTK
---------------------+----------------------
Reporter: vadz | Owner:
Type: defect | Status: reopened
Priority: normal | Milestone:
Component: wxGTK | Version: 3.1.5
Resolution: | Keywords:
Blocked By: | Blocking:
Patch: 0 |
---------------------+----------------------
Changes (by afalkenhahn):

* status: closed => reopened
* cc: andreas@… (added)
* resolution: invalid =>


Comment:

Um, actually, `SetPath()` doesn't work with existing paths either. This
can be fixed by applying Vadim's patch from above so I wonder why this
wasn't applied earlier?

I'm not sure if Vadim's patch is 100% correct because the
`wxDirButton::SetPath` code is like this:


{{{
if (GTK_IS_FILE_CHOOSER(m_widget))
gtk_file_chooser_set_filename((GtkFileChooser*)m_widget,
str.utf8_str());
else if (m_dialog)
UpdateDialogPath(m_dialog);
}}}

Vadim's proposed patch, however, doesn't use that ELSE IF check for
`m_dialog` but just a normal IF. I'm not familiar enough with
`wxFilePickerCtrl` to tell if Vadim's patch should be changed to use ELSE
IF as well but I'm sure someone can tell...

--
Ticket URL: <https://trac.wxwidgets.org/ticket/19163#comment:3>

wxTrac

unread,
Sep 20, 2021, 1:43:50 PM9/20/21
to wx-...@googlegroups.com
#19163: wxFilePickerCtrl::SetPath() doesn't update the displayed path with wxGTK
---------------------+----------------------
Reporter: vadz | Owner:
Type: defect | Status: reopened
Priority: normal | Milestone:
Component: wxGTK | Version: 3.1.5
Resolution: | Keywords:
Blocked By: | Blocking:
Patch: 0 |
---------------------+----------------------

Comment (by vadz):

I think the conditions `GTK_IS_FILE_CHOOSER(m_widget)` and `m_dialog !=
NULL` are exclusive, so I don't think it matter whether we use `if` or
`else if` here.

Anyhow, I'll apply the patch above if it helps with the existing files, it
doesn't seem like it could do any harm (`>> famous_last_words.txt`).

--
Ticket URL: <https://trac.wxwidgets.org/ticket/19163#comment:4>

wxTrac

unread,
Sep 22, 2021, 10:48:06 AM9/22/21
to wx-...@googlegroups.com
#19163: wxFilePickerCtrl::SetPath() doesn't update the displayed path with wxGTK
---------------------+-------------------------------------
Reporter: vadz | Owner: Vadim Zeitlin <vadim@…>
Type: defect | Status: closed
Priority: normal | Milestone:
Component: wxGTK | Version: 3.1.5
Resolution: fixed | Keywords:
Blocked By: | Blocking:
Patch: 0 |
---------------------+-------------------------------------
Changes (by Vadim Zeitlin <vadim@…>):

* owner: => Vadim Zeitlin <vadim@…>
* status: reopened => closed
* resolution: => fixed


Comment:

In [changeset:"9604c729bf0939669cc6f19ab65d9402afdda2af/git-wxWidgets"
9604c729b/git-wxWidgets]:
{{{
#!CommitTicketReference repository="git-wxWidgets"
revision="9604c729bf0939669cc6f19ab65d9402afdda2af"
Update the shown file name in wxGTK wxFilePickerCtrl::SetPath()

This still doesn't work if the file doesn't exist, but at least shows
the correct file name if it does exist, which is better than nothing and
the best we can reasonably do when using the native control.

Closes #19163.
}}}

--
Ticket URL: <https://trac.wxwidgets.org/ticket/19163#comment:5>
Reply all
Reply to author
Forward
0 new messages