summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBarnabás Pőcze <pobrn@protonmail.com>2023-03-08 20:20:35 +0100
committerBarnabás Pőcze <pobrn@protonmail.com>2023-03-08 20:46:17 +0100
commit111e8d2808ac99dedb9942386011b9f14d7f3ab5 (patch)
tree2e0edab995f5268e6e34622b1a5acba35d4bf950
parent9b0b3029a6b90834aa96ca3ad2123fd9dd9a64f5 (diff)
downloadgtk+-111e8d2808ac99dedb9942386011b9f14d7f3ab5.tar.gz
filechooser: Do not look up parents of directories
If the `GtkRecentInfo` represents a directory, simply use it, and do not try to find its parent in `_gtk_file_chooser_extract_recent_folders()`. For example, there is an entry in my recently-used database from the Amberol music player about the folder I have opened with it, but the folder is not listed on the "Recent" tab of the file chooser widget, only its parent. After this change, the directory itself is shown.
-rw-r--r--gtk/gtkfilechooserwidget.c27
1 files changed, 18 insertions, 9 deletions
diff --git a/gtk/gtkfilechooserwidget.c b/gtk/gtkfilechooserwidget.c
index f2c76d56ee..3a0dc6e41b 100644
--- a/gtk/gtkfilechooserwidget.c
+++ b/gtk/gtkfilechooserwidget.c
@@ -637,8 +637,8 @@ _gtk_file_chooser_extract_recent_folders (GList *infos)
for (l = infos; l; l = l->next)
{
GtkRecentInfo *info = l->data;
- const char *uri;
- GFile *parent;
+ const char *uri, *mime_type;
+ GFile *dir;
GFile *file;
if (!gtk_recent_info_is_local (info))
@@ -646,18 +646,27 @@ _gtk_file_chooser_extract_recent_folders (GList *infos)
uri = gtk_recent_info_get_uri (info);
file = g_file_new_for_uri (uri);
- parent = g_file_get_parent (file);
- g_object_unref (file);
- if (parent)
+ mime_type = gtk_recent_info_get_mime_type (info);
+ if (strcmp (mime_type, "inode/directory") != 0)
+ {
+ dir = g_file_get_parent (file);
+ g_object_unref (file);
+ }
+ else
+ {
+ dir = file;
+ }
+
+ if (dir)
{
- if (!g_hash_table_lookup (folders, parent))
+ if (!g_hash_table_lookup (folders, dir))
{
- g_hash_table_insert (folders, parent, (gpointer) 1);
- result = g_list_prepend (result, g_object_ref (parent));
+ g_hash_table_insert (folders, dir, (gpointer) 1);
+ result = g_list_prepend (result, g_object_ref (dir));
}
- g_object_unref (parent);
+ g_object_unref (dir);
}
}