GTK 4: GtkFileChooserWidget seems to be always in "search-mode"

I have successfully used in GTK 3.98.4 gtk_file_chooser_widget_new() to open files. But when I try to call it with gtk_file_chooser_widget_new(GTK_FILE_CHOOSER_ACTION_SAVE), it half works:

  • If I choose an already existing file, I successfully obtain the GFile. I can obtain its path with g_file_get_path(). It’s OK.
  • But when I try to type a name in the “Name:” field in order to create a new file, it always opens a “Search” field.

https://developer.gnome.org/gtk4/unstable/GtkFileChooserWidget.html

You need to focus the entry; the focus can some times switch to the files list, and that will automatically begin searching when you start typing.

You need to focus the entry;

If you mean “focus the entry by clicking in it”, each time I do that, I can type only one character, then the search field appears and has the focus. By clicking in the entry before typing each character, I can finally type a file name. But when I click on “Open” it fails to give a readable path.

If you mean “focus the entry by calling a function”, should I use something like gtk_widget_child_focus() ?

Thanks for your help

Is there a special reason why you are using GtkFileChooserWidget instead of the full dialog GtkFileChooserDialog, or the preferred GtkFileChooserNative?

I’m thinking that it was a mistake to expose GtkFileChooserWidget in the public API, it looks like just the contents of a file chooser dialog, but actually it depends on a lot of interaction with the dialog itself - something which is not really documented, and applications don’t do by default.

1 Like

Hi,
no special reason. I am just trying to port three demos of my gtk-fortran binding from GTK3 (where it worked) to GTK 4, one demonstrating GtkFileChooserButton and GtkFileChooserWidget, the two others using GtkFileChooserWidget.

As a last resort, I could effectively suppress GtkFileChooserWidget. But I still have hope that there is a solution.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.