12

In almost any program, when I click on open, a file chooser dialog opens as shown below. This dialog shows Recent, Home, Desktop and so on.

enter image description here

This is extremely annoying. I am not using Desktop to store data, and I don't care about Recent. I would like to get consistently same view each time the open dialog appears, regardless of what I happen to have opened recently.

Also, it can be seen on my screenshot, how idiotic this dialog window is. I have tmpfs mounted on /tmp, and another tmpfs mounted in /home/<user>/tmp.

Yet, in the Locations list, these two mountpoints are only referred to as tmp and are indistinguishable.

Ideally on the left, I would like to see my home directory in the upper part, and plain good old filesystem tree starting with / in the lower part.

Or maybe even better, only show filesystem tree on the left, but with current location /home/<user>/ alredy "pre-selected" automatically, and contents of my home displayed on the right.

I can remove Recent by adding the following to .config/gtk-3.0/settings.ini:

gtk-recent-files-enabled=false

But still, Desktop is there in the upper part, and the absolute chaos of randomly assembled shares is there in the lower part.

In GTK2/GTK3 how can I bring back some order and logic to the file chooser, as described above ?

Update June, 2020: I am using Openbox on Debian 10, with GTK3 library without any desktop environment. Also I have updated the screenshot.

  • 1
    I've been researching this in vain and do not believe it to be possible. – slm Jun 2 '14 at 7:22
  • 2
    Wouldn' t it be worth asking a new question targeted at gtk3, so the old question, its answers, etc., are easier to read and follow? Some may still be interested in such a track, and it would get somewhat confusing. – sancho.s ReinstateMonicaCellio Jun 21 at 11:37
  • An edited question should ideally not invalidate any existing answers. – Jeff Schaller Jun 21 at 14:32
  • 1
    @JeffSchaller & Martin Vegter I have updated the question to avoid invalidating the old one while keeping the focus on the updated version, roll back the last edit if it is not suitable to your question. In any case there was no answer neither for GTK2 nor for GTK3 as a correct solution require writing a patch. – intika Jun 21 at 16:38
  • 2
    In Mozilla Firefox you can configure not to use the "system" file chooser but its own by setting ui.allow_platform_file_picker to false in the about:config window. I know this is only one program but better than nothing? – Ned64 Jun 22 at 12:41
3
+300

GTK File Chooser?

A perfect solution would be an upstream commit/patch to at least gtkfilechooserdialog.c and gtkfilechooserwidget.c to implement additional features answering this question needs and making it available to all users through updates. The documentation for the current implementation is available for GTK2 and GTK3.


Patching it locally?

A patch for such features is not a quick task and other than the upstream solution, applying such patch locally would require using a custom patched version of the GTK library that may lead to system updates complication.

The other way to apply such patch is by using LD_PRELOAD environment variable along with a newly developed patching library to replace the current GTK code with the patched one. this can be applied separately to each application or system wide. Such solution would be considered as a workaround/hack as it's far from being clean but still this can be efficient. (as an additional dev. note, the newly ld_preload library may contain code implementing something similar to this).


Any workaround?

For users that have multiple desktop installed (for instance Gnome and KDE) can force some application to use the KDE dialog which is more customizable. As example with chromium this can be done with the following

XDG_CURRENT_DESKTOP=KDE chromium

There are also other workaround to replace GTK dialogs such as KGtk or xdg-desktop-portal-kde.

| improve this answer | |
2

Available customization?

The setting gtk-recent-files-enabled=false can be added to ~/.config/gtk-3.0/settings.ini that would disable the recent entry. Also not directly related but gtk-recent-files-limit=0 and gtk-recent-files-max-age=0 can be used as well to disable recent files. For Gtk2 this solution is used to disable recent files.

Other settings suck as show hidden files or startup mode can be set with

gsettings set org.gtk.Settings.FileChooser show-hidden true
gsettings set org.gtk.Settings.FileChooser startup-mode cwd

Screenshot of dconf-editor with other available settings

FileChooser Settings

FileChooser Startup Mode

| improve this answer | |
1

I don't have gtk2 installed to verify this, but you can try this:

Add StartupMode=cwd to $HOME/.config/gtk-2.0/gtkfilechooser.ini.

I got this from this thread: http://ubuntuforums.org/archive/index.php/t-2160654.html

| improve this answer | |
  • 1
    It's not a GTK2 desktop that controls this, the applications that are GTK2 vs. GTK3 will decide on picking up this option or not. That being said all GTK2 apps will then present the file chooser dialog using the current working dir. with cwd set as above. – slm Jun 2 '14 at 1:29
  • @arnefm - the file $HOME/.config/gtk-2.0/gtkfilechooser.ini did not exist. When I create it and add StartupMode=cwd and restart, I see no effect. – Martin Vegter Jun 2 '14 at 7:26
  • @slm: the ini file is automatically picked up by GTK+, this is the relevant code. – ntd Aug 2 '14 at 12:11
  • @Martin Vegter: gtkfilechooser.ini must be already present there (it is saved every time you exit the filechooser dialog). If not you probably have a non standard XDG_CONFIG_HOME, wrong privileges or some sort of other file system problems. – ntd Aug 2 '14 at 12:15
  • 1
    OP wants the file chooser to default to / (not cwd) which is not possible. As per the official gtk2 docs: The StartupMode key controls whether the file chooser starts up showing the list of recently-used files, or the contents of the current working directory. Respectively, the values can be recent or cwd. The same applies to gtk3, you can only choose between recent or cwd (those values are hard-coded). – don_crissti May 6 '15 at 1:41
1

As people already said here, you can set StartupMode=cwd in ~/.config/gtk-2.0/gtkfilechooser.ini. This file exists already, if it is GTK+2, but I am not sure if your screenshot shows GTK+3.

In this case insert this line into your ~/.config/gtk-3.0/settings.ini:

gtk-recent-files-enabled=false

If you want "/" to appear as first view, you need to chdir / before starting the application.

| improve this answer | |
  • neither has any effect. It still looks exactly same as on the screenshot. – Martin Vegter Sep 9 '16 at 17:05
  • I checked on Firefox, Thunderbird and Gimp. It seems to work for me. What application is this? Maybe it's programmed that way that it ignores the system's default behavior. – Martin Sugioarto Sep 9 '16 at 17:40
  • all applications (gpicview, leafpad, .Now I tried Firefox, and that's same as well. – Martin Vegter Sep 9 '16 at 17:45
1

Short answer: There is no Configurable way of achieving this. Available options are not simple.

As stated here and elsewhere (e.g., a related post that you already saw Disable "Recently used" in GTK file/directory selector), options are recent or cwd.

Now, to remove Desktop from the dialog, and to get it reorganized as intend to do, it seems not available as a configuration. That would require changing code in GTK3. I guess the options are doing it yourself, or file a feature request and wait.

I am giving here a few pointers about where is the related code residing, in case you want to commit an update for this. This is clearly not a finalized solution to your intended changes (that would be a lot of work, good for closing the as-of-yet-not-existing feature request).

The struct GtkFileChooserDialog is created with gtk_file_chooser_dialog_new.

It calls gtk_file_chooser_dialog_new_valist in turn (gtkfilechooserdialog.c:769, as of this writing).

The dialog is finally created with (gtkfilechooserdialog.c:727)

g_object_new (GTK_TYPE_FILE_CHOOSER_DIALOG,
                     "title", title,
                     "action", action,
                     NULL);

so you would have likely to find where to add calls to one of the methods for adding entries to the GtkFileChooser: gtk_file_chooser_add_choice, gtk_file_chooser_add_filter, gtk_file_chooser_add_shortcut_folder (probably the most useful), and gtk_file_chooser_add_shortcut_folder_uri, with the locations of your liking to change this.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.