I want to modify GtkFileChooser to view just a specific dir. Is there any configuration to apply this limitation? Or if I must manipulate the source code of GTK+, where should I modify?
1 Answer
There is currently no API, and no effort is being spent in trying to sandbox the file selection widget — sandboxing the whole application is, instead, a much bigger priority, see for instance Flatpak and Bubblewrap.
Modifying the GtkFileChooserWidget is not for the faint of heart; you'll have to change the way the widget determines the current directory, and navigates through the parent directories, both from a user interaction standpoint and from an API standpoint.
You'll need to modify:
gtkfilechooserwidget.c— the main file selection widgetgtkfilesystemmodel.c— aGtkTreeModelimplementation mapping the file systemgtkpathbar.c— the path bar at the top of the file selection widgetgtkplacessidebar.c— the side bar at the left of the file selection widget
This is probably on of the most complex sites inside the GTK+ code base, alongside with GtkTreeView, GtkMenu, and GtkTextView.