Skip to content

FileChooser portal: Handle 'current_filter'

This implements the 'current_filter' option for FileChooser portal which can be used to preselect a specific file filter.

From the FileChooser portal spec:

current_filter (sa(us))

Request that this filter be set by default at dialog creation. If
the filters list is nonempty, it should match a filter in the list
to set the default filter from the list. Alternatively, it may be
specified when the list is empty to apply the filter

Attached is a gtk sample program that can be used to test the functionality (According to this Gtk issue, GTK+ 3.24.4 and xdg-desktop-portal 1.2 are required.): main_setfilter.cpp:

  1. Compile sample program:
gcc -o main_setfilter main_setfilter.cpp
  1. Run sample program using portal in a KDE Plasma session (so that Plasma-native file chooser is actually used):
GTK_USE_PORTAL=1 ./main_setfilter
  1. check what file filter is preselected in the file dialog:

Filter "filter2" should be preselected, since it has been set with gtk_file_chooser_set_filter(chooser, filter2); and this merge requests actually makes this work.

Merge request reports