[nautilus] Fix up eject button hover in places sidebar



commit f294a4e80626793624d76d6002b094d1c0809de4
Author: Alexander Larsson <alexl redhat com>
Date:   Wed Mar 30 21:15:24 2011 +0200

    Fix up eject button hover in places sidebar
    
    We were calling gtk_tree_view_column_cell_get_position() without
    properly loading the cell attribute for the right row before.
    We fix this by calling gtk_tree_view_column_cell_set_cell_data().
    
    With this in place we can also use the x_offset for the position and
    avoid the whole summing of widths.
    
    Due to a bug in Gtk which expands the eject icon cell renderer we
    have to right align it so that it lines up properly.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=640741

 src/nautilus-places-sidebar.c |   60 ++++++++++++++--------------------------
 1 files changed, 21 insertions(+), 39 deletions(-)
---
diff --git a/src/nautilus-places-sidebar.c b/src/nautilus-places-sidebar.c
index ed8addf..91c20c5 100644
--- a/src/nautilus-places-sidebar.c
+++ b/src/nautilus-places-sidebar.c
@@ -61,10 +61,7 @@
 typedef struct {
 	GtkScrolledWindow  parent;
 	GtkTreeView        *tree_view;
-	GtkCellRenderer    *eject_text_cell_renderer;
-	GtkCellRenderer    *icon_cell_renderer;
-	GtkCellRenderer    *icon_padding_cell_renderer;
-	GtkCellRenderer    *padding_cell_renderer;
+	GtkCellRenderer    *eject_icon_cell_renderer;
 	char 	           *uri;
 	GtkListStore       *store;
 	GtkTreeModel       *filter_model;
@@ -922,8 +919,7 @@ over_eject_button (NautilusPlacesSidebar *sidebar,
 		   GtkTreePath **path)
 {
 	GtkTreeViewColumn *column;
-	GtkTextDirection direction;
-	int width, total_width;
+	int width, x_offset, hseparator;
 	int eject_button_size;
 	gboolean show_eject;
 	GtkTreeIter iter;
@@ -945,42 +941,28 @@ over_eject_button (NautilusPlacesSidebar *sidebar,
 			goto out;
 		}
 
-		total_width = 0;
 
 		gtk_widget_style_get (GTK_WIDGET (sidebar->tree_view),
-				      "horizontal-separator", &width,
+				      "horizontal-separator", &hseparator,
 				      NULL);
-		total_width += width;
-
-		direction = gtk_widget_get_direction (GTK_WIDGET (sidebar->tree_view));
-		if (direction != GTK_TEXT_DIR_RTL) {
-			gtk_tree_view_column_cell_get_position (column,
-								sidebar->padding_cell_renderer,
-								NULL, &width);
-			total_width += width;
-
-			gtk_tree_view_column_cell_get_position (column,
-								sidebar->icon_padding_cell_renderer,
-								NULL, &width);
-			total_width += width;
-			
-			gtk_tree_view_column_cell_get_position (column,
-								sidebar->icon_cell_renderer,
-								NULL, &width);
-			total_width += width;
-
-			gtk_tree_view_column_cell_get_position (column,
-								sidebar->eject_text_cell_renderer,
-								NULL, &width);
-			total_width += width;
-		}
 
-		total_width += EJECT_BUTTON_XPAD;
+		/* Reload cell attributes for this particular row */
+		gtk_tree_view_column_cell_set_cell_data (column,
+							 model, &iter, FALSE, FALSE);
+
+		gtk_tree_view_column_cell_get_position (column,
+							sidebar->eject_icon_cell_renderer,
+							&x_offset, &width);
 
 		eject_button_size = nautilus_get_icon_size_for_stock_size (GTK_ICON_SIZE_MENU);
 
-		if (x - total_width >= 0 &&
-		    x - total_width <= eject_button_size) {
+		/* This is kinda weird, but we have to do it to workaround gtk+ expanding
+		 * the eject cell renderer (even thought we told it not to) and we then
+		 * had to set it right-aligned */
+		x_offset += width - hseparator - EJECT_BUTTON_XPAD - eject_button_size;
+
+		if (x - x_offset >= 0 &&
+		    x - x_offset <= eject_button_size) {
 			return TRUE;
 		}
 	}
@@ -3061,7 +3043,6 @@ nautilus_places_sidebar_init (NautilusPlacesSidebar *sidebar)
 
 	/* initial padding */
 	cell = gtk_cell_renderer_text_new ();
-	sidebar->padding_cell_renderer = cell;
 	gtk_tree_view_column_pack_start (col, cell, FALSE);
 	g_object_set (cell,
 		      "xpad", 6,
@@ -3085,7 +3066,6 @@ nautilus_places_sidebar_init (NautilusPlacesSidebar *sidebar)
 
 	/* icon padding */
 	cell = gtk_cell_renderer_text_new ();
-	sidebar->icon_padding_cell_renderer = cell;
 	gtk_tree_view_column_pack_start (col, cell, FALSE);
 	gtk_tree_view_column_set_cell_data_func (col, cell,
 						 padding_cell_renderer_func,
@@ -3093,7 +3073,6 @@ nautilus_places_sidebar_init (NautilusPlacesSidebar *sidebar)
 
 	/* icon renderer */
 	cell = gtk_cell_renderer_pixbuf_new ();
-	sidebar->icon_cell_renderer = cell;
 	gtk_tree_view_column_pack_start (col, cell, FALSE);
 	gtk_tree_view_column_set_attributes (col, cell,
 					     "pixbuf", PLACES_SIDEBAR_COLUMN_ICON,
@@ -3104,7 +3083,6 @@ nautilus_places_sidebar_init (NautilusPlacesSidebar *sidebar)
 
 	/* eject text renderer */
 	cell = gtk_cell_renderer_text_new ();
-	sidebar->eject_text_cell_renderer = cell;
 	gtk_tree_view_column_pack_start (col, cell, TRUE);
 	gtk_tree_view_column_set_attributes (col, cell,
 					     "text", PLACES_SIDEBAR_COLUMN_NAME,
@@ -3117,10 +3095,14 @@ nautilus_places_sidebar_init (NautilusPlacesSidebar *sidebar)
 
 	/* eject icon renderer */
 	cell = gtk_cell_renderer_pixbuf_new ();
+	sidebar->eject_icon_cell_renderer = cell;
 	g_object_set (cell,
 		      "mode", GTK_CELL_RENDERER_MODE_ACTIVATABLE,
 		      "stock-size", GTK_ICON_SIZE_MENU,
 		      "xpad", EJECT_BUTTON_XPAD,
+		      /* align right, because for some reason gtk+ expands
+			 this even though we tell it not to. */
+		      "xalign", 1.0,
 		      NULL);
 	gtk_tree_view_column_pack_start (col, cell, FALSE);
 	gtk_tree_view_column_set_attributes (col, cell,



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