From 0bb6377a3aa0aef7343d18cf037a34d4f986eb22 Mon Sep 17 00:00:00 2001 From: Georges Basile Stavracas Neto Date: Sat, 22 Oct 2022 12:39:40 -0300 Subject: [PATCH] filechooserwidget: Use correct view in various places Most of the pointer comparisons against 'browse_files_column_view' should actually be performed against the current view widget. As it turns out, it weren't that many places after all. --- gtk/gtkfilechooserwidget.c | 37 ++++++++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/gtk/gtkfilechooserwidget.c b/gtk/gtkfilechooserwidget.c index 8a90e4e805..3d6945ee78 100644 --- a/gtk/gtkfilechooserwidget.c +++ b/gtk/gtkfilechooserwidget.c @@ -1714,6 +1714,24 @@ popup_file_list_menu (GSimpleAction *action, file_list_show_popover (impl, x, y); } +static GtkWidget* +get_current_view_widget (GtkFileChooserWidget *impl) +{ + switch (impl->view_type) + { + case VIEW_TYPE_LIST: + return impl->browse_files_column_view; + + case VIEW_TYPE_GRID: + return impl->browse_files_grid_view; + + default: + g_assert_not_reached (); + } + + return NULL; +} + static void set_view_type (GtkFileChooserWidget *impl, ViewType view_type) @@ -1935,10 +1953,11 @@ list_popup_menu_cb (GtkWidget *widget, { GtkFileChooserWidget *impl = GTK_FILE_CHOOSER_WIDGET (user_data); graphene_rect_t bounds; + GtkWidget *view_widget; + + view_widget = get_current_view_widget (impl); - if (!gtk_widget_compute_bounds (impl->browse_files_column_view, - GTK_WIDGET (impl), - &bounds)) + if (!gtk_widget_compute_bounds (view_widget, GTK_WIDGET (impl), &bounds)) return FALSE; file_list_show_popover (impl, @@ -2472,7 +2491,7 @@ location_mode_set (GtkFileChooserWidget *impl, location_switch_to_path_bar (impl); if (switch_to_file_list) - gtk_widget_grab_focus (impl->browse_files_column_view); + gtk_widget_grab_focus (get_current_view_widget (impl)); break; @@ -4729,7 +4748,7 @@ gtk_file_chooser_widget_get_files (GtkFileChooser *chooser) current_focus = NULL; file_list_seen = FALSE; - if (current_focus == impl->browse_files_column_view) + if (current_focus == get_current_view_widget (impl)) { GtkBitsetIter iter; GtkBitset *bitset; @@ -4792,7 +4811,7 @@ gtk_file_chooser_widget_get_files (GtkFileChooser *chooser) else goto empty; } - else if (impl->toplevel_last_focus_widget == impl->browse_files_column_view) + else if (impl->toplevel_last_focus_widget == get_current_view_widget (impl)) goto file_list; else if (impl->location_entry && impl->toplevel_last_focus_widget == impl->location_entry) goto file_entry; @@ -5399,7 +5418,7 @@ gtk_file_chooser_widget_should_respond (GtkFileChooserWidget *impl) current_focus = gtk_root_get_focus (GTK_ROOT (toplevel)); - if (current_focus == impl->browse_files_column_view) + if (current_focus == get_current_view_widget (impl)) { /* The following array encodes what we do based on the impl->action and the * number of files selected. @@ -5601,7 +5620,7 @@ gtk_file_chooser_widget_should_respond (GtkFileChooserWidget *impl) g_object_unref (file); } - else if (impl->toplevel_last_focus_widget == impl->browse_files_column_view) + else if (impl->toplevel_last_focus_widget == get_current_view_widget (impl)) { /* The focus is on a dialog's action area button, *and* the widget that * was focused immediately before it is the file list. @@ -5645,7 +5664,7 @@ gtk_file_chooser_widget_initial_focus (GtkFileChooserWidget *impl) { if (impl->location_mode == LOCATION_MODE_PATH_BAR || impl->operation_mode == OPERATION_MODE_RECENT) - widget = impl->browse_files_column_view; + widget = get_current_view_widget (impl); else widget = impl->location_entry; } -- 2.30.2