Oddity with filechooser widget in notebook tab

Hi
I am using filechooserwidget in a notebook tab and everything works fine except for an annoyance
WhenI move to another tab and move back to the file selector tab the cursor moves to and selects ‘Recent Files’ rather than the directory/files I had selected.

This is prior to any action.
Any idea why this is happening?

The default location is set to be the one configured in the org.gtk.Settings.FileChooser/startup-mode GSettings key; the settings for the file chooser are loaded when the widget is mapped.

Whenever you switch to a different GtkNotebook page, the notebook will set the child-visible property on the widget in the newly visible page to TRUE, and in the old page to FALSE. Changing the child visibility will cause a widget to be mapped or unmapped. This means that the file chooser will reload its settings every time you switch a page, thus resetting the current location.

You can connect to the unmap signal on the file chooser widget to store the current location, and to the map signal to set that location back.

1 Like

Thanks
Is there a way to select more than one file via code in the file selector? I cant find anything

Have you tried calling gtk_file_chooser_set_select_multiple() and then gtk_file_chooser_select_filename()? You’ll need to call gtk_file_chooser_get_filenames() to retrieve all the selected files.

Yeah it only shows selected one of the files selected before switching tabs

Assuming you’re looping over your stored selected-file list (since gtk_file_chooser_select_filename() only accepts a single filename argument), I’m guessing it clears any existing selection every time it’s called.

The docs don’t say it does that… but they also don’t say it doesn’t, and the ability to grow an existing selection list feels like the kind of thing that would be mentioned. (There’s also the fact that gtk_file_chooser_select_filename() can implicitly change folder when making the selection, which would preclude multiple-file selection.)

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