14

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.

intika
  • 13,920
  • 7
  • 41
  • 79
Martin Vegter
  • 69
  • 66
  • 195
  • 326
  • 2
    I've been researching this in vain and do not believe it to be possible. – slm Jun 02 '14 at 07: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 '20 at 11:37
  • An edited question should ideally not invalidate any existing answers. – Jeff Schaller Jun 21 '20 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 '20 at 16:38
  • 3
    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 '20 at 12:41
  • @JeffSchaller - Often times it is hard to satisfy the two following requirements (which I deem reasonable) at the same time: 1) not write a whole new question/answer, 2) keep it readable for either of the two versions (GTK2/GTK3, in this case). If I were to sacrifice one of the two (to meet your "ideal case", which is the same as mine), that would be the first... then my suggestion. – sancho.s ReinstateMonicaCellio Jun 22 '20 at 13:21

6 Answers6

4

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.

intika
  • 13,920
  • 7
  • 41
  • 79
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

intika
  • 13,920
  • 7
  • 41
  • 79
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

arnefm
  • 3,132
  • 18
  • 16
  • 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 02 '14 at 01: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 02 '14 at 07:26
  • @slm: the ini file is automatically picked up by GTK+, this is the [relevant code](https://git.gnome.org/browse/gtk+/tree/gtk/gtkfilechoosersettings.c?id=2.24.24#n72). – ntd Aug 02 '14 at 12:11
  • @Martin Vegter: `gtkfilechooser.ini` must be already present there (it is [saved](https://git.gnome.org/browse/gtk+/tree/gtk/gtkfilechoosersettings.c?id=2.24.24#n388) 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 02 '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](https://developer.gnome.org/gtk2/stable/GtkFileChooser.html): _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 06 '15 at 01: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.

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.

1

This topic is around for quite some time, but a simple solution to omit the growing list of mostly useless mount point items in the sidebar still appears not to exist yet.

As a quick fix, the following patch disables all places besides the home directory, the user bookmarks and the "Recent" item (if configured so).

Perhaps this is helpful.

--- gtk+3.0-3.24.24.orig/gtk/gtkplacessidebar.c
+++ gtk+3.0-3.24.24/gtk/gtkplacessidebar.c
@@ -106,6 +106,16 @@
  * - .has-open-popup when a popup is open for a row
  */
 
+/* Workaround switch for a concise places sidebar.
+ *
+ *   2023-01-05 Gundolf Kiefer <[email protected]>
+ *
+ * The following switch disables all automatically generated places from the
+ * sidebar except the home directory and the user-defined bookmarks.
+ */
+#define SHORT_SIDEBAR 1
+
+
 /* These are used when a destination-side DND operation is taking place.
  * Normally, when a common drag action is taking place, the state will be
  * DROP_STATE_NEW_BOOKMARK_ARMED, however, if the client of GtkPlacesSidebar
@@ -1097,6 +1107,8 @@ update_places (GtkPlacesSidebar *sidebar
   g_object_unref (start_icon);
   g_free (home_uri);
 
+#if SHORT_SIDEBAR == 0
+
   /* desktop */
   if (sidebar->show_desktop)
     {
@@ -1416,6 +1428,8 @@ update_places (GtkPlacesSidebar *sidebar
     }
   g_list_free (mounts);
 
+#endif    // SHORT_SIDEBAR == 0
+
   /* add bookmarks */
   bookmarks = _gtk_bookmarks_manager_list_bookmarks     (sidebar->bookmarks_manager);
  • thank you! that works beautifully – Martin Vegter Jan 10 '23 at 06:56
  • I have another annoyance in gtkfilechooser: when I accidentally click on the "name" column header, it changes the sort order between ascending/descending. This usually happens when I want to click on the first file, biut accidentally click on the header. I only ever want ascending, I don't want this to be toggle-ble. Can this be "locked" ? I can create a new question for that – Martin Vegter Jan 10 '23 at 07:08