[gtk+] file chooser: Avoid a crash



commit 450056cdfe5cbf6fdff9c9def77570d37c0b3cd4
Author: Matthias Clasen <mclasen redhat com>
Date:   Wed Sep 16 07:39:19 2015 -0700

    file chooser: Avoid a crash
    
    When right-clicking in an empty folder, you should get a context
    menu, not a crash. The code for positioning the popover was not
    handling the eventuality of no row under the pointer. Just position
    the popover right at the click location in this case.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=755021

 gtk/gtkfilechooserwidget.c |   23 ++++++++++++++++-------
 1 files changed, 16 insertions(+), 7 deletions(-)
---
diff --git a/gtk/gtkfilechooserwidget.c b/gtk/gtkfilechooserwidget.c
index 8c25741..d286fcf 100644
--- a/gtk/gtkfilechooserwidget.c
+++ b/gtk/gtkfilechooserwidget.c
@@ -2312,18 +2312,27 @@ file_list_show_popover (GtkFileChooserWidget *impl,
 
   selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->browse_files_tree_view));
   list = gtk_tree_selection_get_selected_rows (selection, &model);
-  path = list->data;
-  gtk_tree_view_get_cell_area (GTK_TREE_VIEW (priv->browse_files_tree_view), path, NULL, &rect);
-  gtk_tree_view_convert_bin_window_to_widget_coords (GTK_TREE_VIEW (priv->browse_files_tree_view),
+  if (list)
+    {
+      path = list->data;
+      gtk_tree_view_get_cell_area (GTK_TREE_VIEW (priv->browse_files_tree_view), path, NULL, &rect);
+      gtk_tree_view_convert_bin_window_to_widget_coords (GTK_TREE_VIEW (priv->browse_files_tree_view),
                                                      rect.x, rect.y, &rect.x, &rect.y);
 
-  rect.x = CLAMP (x - 20, 0, gtk_widget_get_allocated_width (priv->browse_files_tree_view) - 40);
-  rect.width = 40;
+      rect.x = CLAMP (x - 20, 0, gtk_widget_get_allocated_width (priv->browse_files_tree_view) - 40);
+      rect.width = 40;
 
-  g_list_free_full (list, (GDestroyNotify) gtk_tree_path_free);
+      g_list_free_full (list, (GDestroyNotify) gtk_tree_path_free);
+    }
+  else
+    {
+      rect.x = x;
+      rect.y = y;
+      rect.width = 1;
+      rect.height = 1;
+    }
 
   gtk_popover_set_pointing_to (GTK_POPOVER (priv->browse_files_popover), &rect);
-
   gtk_widget_show (priv->browse_files_popover);
 }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]