From 6d3cf209af25e03255bdb9d75863bbba0cbfa971 Mon Sep 17 00:00:00 2001 From: Daemonratte Date: Sun, 18 Oct 2026 13:31:17 +0200 Subject: [PATCH] filechooser: search, location and mount fixes from GTK 3 Backported from GTK 3: - search results - the location entry in local-only mode - folder activation - long bookmark names - recent filters by MIME type - the process list of mount operations - icon caches Upstream commits: - 8a53ed9e55 (Christoph Reiter) - d254089308 (Cosimo Cecchi) - abef21776d (Philip Withnall) - 3923ba1605 (Matthias Clasen) --- gtk/gtkfilechooserbutton.c | 5 +++-- gtk/gtkfilechooserdefault.c | 7 +++++-- gtk/gtkiconcache.c | 3 +++ gtk/gtkmountoperation-x11.c | 4 ++-- gtk/gtkmountoperation.c | 14 ++++++++++---- gtk/gtkrecentchoosermenu.c | 3 +++ gtk/gtkrecentfilter.c | 5 +++-- gtk/updateiconcache.c | 4 +--- 8 files changed, 30 insertions(+), 15 deletions(-) diff --git a/gtk/gtkfilechooserbutton.c b/gtk/gtkfilechooserbutton.c index 4bc93b5de..61fb04c52 100644 --- a/gtk/gtkfilechooserbutton.c +++ b/gtk/gtkfilechooserbutton.c @@ -625,10 +625,9 @@ unselect_current_file (GtkFileChooserButton *button) { g_object_unref (priv->selection_while_inactive); priv->selection_while_inactive = NULL; + priv->is_changing_selection = TRUE; } - priv->is_changing_selection = TRUE; - update_label_and_image (button); update_combo_box (button); } @@ -2347,6 +2346,8 @@ name_cell_data_func (GtkCellLayout *layout, if (type == ROW_TYPE_CURRENT_FOLDER) g_object_set (cell, "ellipsize", PANGO_ELLIPSIZE_END, NULL); + else if (type == ROW_TYPE_BOOKMARK || type == ROW_TYPE_SHORTCUT) + g_object_set (cell, "ellipsize", PANGO_ELLIPSIZE_MIDDLE, NULL); else g_object_set (cell, "ellipsize", PANGO_ELLIPSIZE_NONE, NULL); } diff --git a/gtk/gtkfilechooserdefault.c b/gtk/gtkfilechooserdefault.c index 673305025..e085ead43 100644 --- a/gtk/gtkfilechooserdefault.c +++ b/gtk/gtkfilechooserdefault.c @@ -7000,6 +7000,7 @@ location_switch_to_filename_entry (GtkFileChooserDefault *impl) /* Configure the entry */ _gtk_file_chooser_entry_set_base_folder (GTK_FILE_CHOOSER_ENTRY (impl->location_entry), impl->current_folder); + _gtk_file_chooser_entry_set_local_only (GTK_FILE_CHOOSER_ENTRY (impl->location_entry), impl->local_only); /* Done */ @@ -12573,7 +12574,7 @@ search_selected_foreach_get_file_cb (GtkTreeModel *model, list = data; gtk_tree_model_get (model, iter, MODEL_COL_FILE, &file, -1); - *list = g_slist_prepend (*list, g_object_ref (file)); + *list = g_slist_prepend (*list, file); /* The file already has a new ref courtesy of gtk_tree_model_get(); this will be unreffed by the caller */ } /* Constructs a list of the selected paths in search mode */ @@ -13680,13 +13681,15 @@ item_activated (GtkTreeModel *model, if (is_sensitive && is_folder && file) { change_folder_and_display_error (impl, file, FALSE); - return; + goto out; } if (impl->action == GTK_FILE_CHOOSER_ACTION_OPEN || impl->action == GTK_FILE_CHOOSER_ACTION_SAVE) g_signal_emit_by_name (impl, "file-activated"); + out: + if (file) g_object_unref (file); } diff --git a/gtk/gtkiconcache.c b/gtk/gtkiconcache.c index 3df44fbff..cc3a4483a 100644 --- a/gtk/gtkiconcache.c +++ b/gtk/gtkiconcache.c @@ -233,6 +233,9 @@ find_image_offset (GtkIconCache *cache, guint32 image_list_offset, n_images; int i; + if (!icon_name) + return 0; + chain_offset = cache->last_chain_offset; if (chain_offset) { diff --git a/gtk/gtkmountoperation-x11.c b/gtk/gtkmountoperation-x11.c index 6be3b65ad..0752c496b 100644 --- a/gtk/gtkmountoperation-x11.c +++ b/gtk/gtkmountoperation-x11.c @@ -658,7 +658,7 @@ pid_get_env (GPid pid, n = 0; while (TRUE) { - if (env[n] == '\0' || n >= env_len) + if (n >= env_len || env[n] == '\0') break; if (g_str_has_prefix (env + n, key) && (*(env + n + key_len) == '=')) @@ -671,7 +671,7 @@ pid_get_env (GPid pid, break; } - for (; env[n] != '\0' && n < env_len; n++) + for (; n < env_len && env[n] != '\0'; n++) ; n++; } diff --git a/gtk/gtkmountoperation.c b/gtk/gtkmountoperation.c index 618446354..cf182c476 100644 --- a/gtk/gtkmountoperation.c +++ b/gtk/gtkmountoperation.c @@ -1180,7 +1180,7 @@ on_button_press_event_for_process_tree_view (GtkWidget *widget, return ret; } -static void +static GtkWidget * create_show_processes_dialog (GMountOperation *op, const char *message, const char *choices[]) @@ -1308,9 +1308,9 @@ create_show_processes_dialog (GMountOperation *op, g_object_add_weak_pointer (G_OBJECT (tree_view), (gpointer *) &priv->process_tree_view); g_object_unref (list_store); - - gtk_widget_show_all (dialog); g_object_ref (op); + + return dialog; } static void @@ -1320,6 +1320,7 @@ gtk_mount_operation_show_processes (GMountOperation *op, const char *choices[]) { GtkMountOperationPrivate *priv; + GtkWidget *dialog = NULL; g_return_if_fail (GTK_IS_MOUNT_OPERATION (op)); g_return_if_fail (message != NULL); @@ -1331,7 +1332,7 @@ gtk_mount_operation_show_processes (GMountOperation *op, if (priv->process_list_store == NULL) { /* need to create the dialog */ - create_show_processes_dialog (op, message, choices); + dialog = create_show_processes_dialog (op, message, choices); } /* otherwise, we're showing the dialog, assume messages+choices hasn't changed */ @@ -1339,6 +1340,11 @@ gtk_mount_operation_show_processes (GMountOperation *op, update_process_list_store (GTK_MOUNT_OPERATION (op), priv->process_list_store, processes); + + if (dialog != NULL) + { + gtk_widget_show_all (dialog); + } } static void diff --git a/gtk/gtkrecentchoosermenu.c b/gtk/gtkrecentchoosermenu.c index cd5ad6df0..1e2b04195 100644 --- a/gtk/gtkrecentchoosermenu.c +++ b/gtk/gtkrecentchoosermenu.c @@ -1183,6 +1183,9 @@ static void gtk_recent_chooser_sync_action_properties (GtkActivatable *activatable, GtkAction *action) { + if (!action) + return; + gtk_widget_set_sensitive (GTK_WIDGET (activatable), gtk_action_is_sensitive (action)); _gtk_recent_chooser_sync_action_properties (activatable, action); diff --git a/gtk/gtkrecentfilter.c b/gtk/gtkrecentfilter.c index b5f933b0d..5747a0786 100644 --- a/gtk/gtkrecentfilter.c +++ b/gtk/gtkrecentfilter.c @@ -488,11 +488,12 @@ gtk_recent_filter_filter (GtkRecentFilter *filter, if (filter_info->mime_type != NULL) { gchar *filter_content_type, *rule_content_type; - gboolean match; + gboolean match = FALSE; filter_content_type = g_content_type_from_mime_type (filter_info->mime_type); rule_content_type = g_content_type_from_mime_type (rule->u.mime_type); - match = g_content_type_is_a (filter_content_type, rule_content_type); + if (filter_content_type != NULL && rule_content_type != NULL) + match = g_content_type_is_a (filter_content_type, rule_content_type); g_free (filter_content_type); g_free (rule_content_type); diff --git a/gtk/updateiconcache.c b/gtk/updateiconcache.c index 20a88a14d..00e687f8d 100644 --- a/gtk/updateiconcache.c +++ b/gtk/updateiconcache.c @@ -314,8 +314,7 @@ load_icon_data (const char *path) data->n_attach_points = g_strv_length (split); data->attach_points = g_new (int, 2 * data->n_attach_points); - i = 0; - while (split[i] != NULL && i < data->n_attach_points) + for (i = 0; i < data->n_attach_points; ++i) { split_point = strchr (split[i], ','); if (split_point) @@ -325,7 +324,6 @@ load_icon_data (const char *path) data->attach_points[2 * i] = atoi (split[i]); data->attach_points[2 * i + 1] = atoi (split_point); } - i++; } g_strfreev (split);