1

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 1

2

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 widget
  • gtkfilesystemmodel.c — a GtkTreeModel implementation mapping the file system
  • gtkpathbar.c — the path bar at the top of the file selection widget
  • gtkplacessidebar.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.

Sign up to request clarification or add additional context in comments.

1 Comment

As a stopgap you could probably just reject selections that are outside your desired directory after the user has made their selection, and force them to select again (either by acting as if the user had clicked Cancel or by presenting the dialog again).

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.