Ticket #10917 (closed defect: fixed)
wxGTK wxFileDialog::SetDirectory and ::SetFilename problems
| Reported by: | dghart | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | 2.9.1 |
| Component: | wxGTK | Version: | 2.9-svn |
| Keywords: | wxFileDialog | Cc: | |
| Blocked By: | Patch: | yes | |
| Blocking: |
Description
A recent wxForum post, http://wxforum.shadonet.com/viewtopic.php?t=24490, revealed that the wxGTK wxFileDialog (which uses the native control) has problems with setting and getting the default directory and file. There are three issues:
Supplying default values via the ctor get passed to the gtk control, and also stored in m_dir and m_fileName. Calls to SetDirectory() and SetFilename() do only the former.
GetDirectory() and GetFilename() don't try to use m_dir and m_fileName.
gtk_file_chooser_get_current_folder() doesn't seem to return the value set by gtk_file_chooser_set_current_folder() until after the dialog has been shown.
So GetDirectory() and GetFilename() will return "" until the dialog has been shown. Also, SetFilename() calls SetPath(wxFileName(GetDirectory(), name).GetFullPath()). Since the dialog won't have been shown yet, GetDirectory() returns "", so SetPath() receives just a filename; which causes gtk_file_chooser_set_filename() to fail with the assert:
Gtk-CRITICAL **: gtk_file_system_unix_get_parent: assertion `g_path_is_absolute (filename)' failed.
Passing a default dir and filename to the wxFileDialog ctor does work: the file is selected within the default dir, and both GetDirectory() and GetFilename() return the correct values once the dialog has closed.
The patches (for trunk and WX_2_8_BRANCH, which has the same problem) make the setters set m_dir and m_fileName; the getters now use these values if the gtk2 calls fail. The trunk one includes a doc patch. Also attached is a diff to the minimal sample that demonstrates the problem; the first dialog has defaults set in its ctor, the second using the setters.

