filechooserwidget: Use correct view in various places
authorGeorges Basile Stavracas Neto <georges.stavracas@gmail.com>
Sat, 22 Oct 2022 15:39:40 +0000 (12:39 -0300)
committerGeorges Basile Stavracas Neto <georges.stavracas@gmail.com>
Tue, 13 Dec 2022 17:45:15 +0000 (14:45 -0300)
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

index 8a90e4e805a8f274a669bed403f8825d5786517d..3d6945ee78cf5b1698f232fafb1574c1b66d4b69 100644 (file)
@@ -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;
     }