[gtk+] bgo#327152 - Ellipsize long directory names in GtkPathBar, and better layout for the pathbar



commit 4d7bbd058ebf4451d8f5856f2193bf176df87644
Author: Denis Chertykov <chertykov gmail com>
Date:   Fri Jun 5 14:07:10 2009 -0500

    bgo#327152 - Ellipsize long directory names in GtkPathBar, and better layout for the pathbar
    
    Ellipsize labels in the Save folder's combo so they don't grow too wide.
    
    Ellipsize labels in normal directory buttons in the pathbar, and make
    their requisition's width reasonably small.  Use a tooltip for buttons
    that got ellipsized.
    
    Instead of placing the down-slider directly beside the last button in
    the pathbar, use the remaining space in the pathbar for the last
    button.  Use a different method to find the first visible button.
    Walk down from the end, adding buttons until we use all free space.
    
    Signed-off-by: Federico Mena Quintero <federico novell com>
---
 gtk/gtkfilechooserdefault.c |    1 +
 gtk/gtkpathbar.c            |  100 +++++++++++++++++++++----------------------
 2 files changed, 50 insertions(+), 51 deletions(-)

diff --git a/gtk/gtkfilechooserdefault.c b/gtk/gtkfilechooserdefault.c
index 5f40411..9c98d87 100644
--- a/gtk/gtkfilechooserdefault.c
+++ b/gtk/gtkfilechooserdefault.c
@@ -4852,6 +4852,7 @@ save_folder_combo_create (GtkFileChooserDefault *impl)
 				  NULL);
 
   cell = gtk_cell_renderer_text_new ();
+  g_object_set (cell, "ellipsize", PANGO_ELLIPSIZE_END, NULL);
   gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo), cell, TRUE);
   gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combo), cell,
 				  "text", SHORTCUTS_COL_NAME,
diff --git a/gtk/gtkpathbar.c b/gtk/gtkpathbar.c
index a1a5093..621d487 100644
--- a/gtk/gtkpathbar.c
+++ b/gtk/gtkpathbar.c
@@ -330,7 +330,13 @@ gtk_path_bar_size_request (GtkWidget      *widget,
     {
       button_data = BUTTON_DATA (list->data);
       gtk_widget_size_request (button_data->button, &child_requisition);
-      requisition->width = MAX (child_requisition.width, requisition->width);
+      
+      if (button_data->type == NORMAL_BUTTON)
+	/* Use 2*Height as button width because of ellipsized label.  */
+	requisition->width = MAX (child_requisition.height * 2, requisition->width);
+      else
+	requisition->width = MAX (child_requisition.width, requisition->width);
+
       requisition->height = MAX (child_requisition.height, requisition->height);
     }
 
@@ -455,7 +461,6 @@ gtk_path_bar_size_allocate (GtkWidget     *widget,
   gint border_width;
   gboolean need_sliders = FALSE;
   gint up_slider_offset = 0;
-  gint down_slider_offset = 0;
 
   widget->allocation = *allocation;
 
@@ -572,9 +577,14 @@ gtk_path_bar_size_allocate (GtkWidget     *widget,
 
   for (list = first_button; list; list = list->prev)
     {
-      child = BUTTON_DATA (list->data)->button;
+      ButtonData *button_data;
+
+      button_data = BUTTON_DATA (list->data);
+      child = button_data->button;
+
+      child_allocation.width = MIN (child->requisition.width,
+				    allocation_width - (path_bar->spacing + path_bar->slider_width) * 2);
 
-      child_allocation.width = child->requisition.width;
       if (direction == GTK_TEXT_DIR_RTL)
 	child_allocation.x -= child_allocation.width;
 
@@ -591,21 +601,21 @@ gtk_path_bar_size_allocate (GtkWidget     *widget,
 	    break;
 	}
 
-      gtk_widget_set_child_visible (BUTTON_DATA (list->data)->button, TRUE);
+      if (child_allocation.width < child->requisition.width)
+	{
+	  if (!gtk_widget_get_has_tooltip (child))
+	    gtk_widget_set_tooltip_text (child, button_data->dir_name);
+	}
+      else if (gtk_widget_get_has_tooltip (child))
+	gtk_widget_set_tooltip_text (child, NULL);
+      
+      gtk_widget_set_child_visible (child, TRUE);
       gtk_widget_size_allocate (child, &child_allocation);
 
       if (direction == GTK_TEXT_DIR_RTL)
-	{
-	  child_allocation.x -= path_bar->spacing;
-	  down_slider_offset = child_allocation.x - widget->allocation.x - path_bar->slider_width;
-	  down_slider_offset = border_width;
-	}
+	child_allocation.x -= path_bar->spacing;
       else
-	{
-	  down_slider_offset = child_allocation.x - widget->allocation.x;
-	  down_slider_offset = allocation->width - border_width - path_bar->slider_width;
-	  child_allocation.x += child_allocation.width + path_bar->spacing;
-	}
+	child_allocation.x += child_allocation.width + path_bar->spacing;
     }
   /* Now we go hide all the widgets that don't fit */
   while (list)
@@ -633,7 +643,14 @@ gtk_path_bar_size_allocate (GtkWidget     *widget,
   if (need_sliders)
     {
       child_allocation.width = path_bar->slider_width;
-      child_allocation.x = down_slider_offset + allocation->x;
+
+      if (direction == GTK_TEXT_DIR_RTL)
+	child_allocation.x = border_width;
+      else
+	child_allocation.x = allocation->width - border_width - path_bar->slider_width;
+
+      child_allocation.x += allocation->x;
+      
       gtk_widget_size_allocate (path_bar->down_slider_button, &child_allocation);
 
       gtk_widget_set_child_visible (path_bar->down_slider_button, TRUE);
@@ -775,11 +792,7 @@ gtk_path_bar_scroll_down (GtkPathBar *path_bar)
 {
   GList *list;
   GList *down_button = NULL;
-  GList *up_button = NULL;
   gint space_available;
-  gint space_needed;
-  gint border_width;
-  GtkTextDirection direction;
 
   if (path_bar->ignore_click)
     {
@@ -795,9 +808,6 @@ gtk_path_bar_scroll_down (GtkPathBar *path_bar)
 
   gtk_widget_queue_resize (GTK_WIDGET (path_bar));
 
-  border_width = GTK_CONTAINER (path_bar)->border_width;
-  direction = gtk_widget_get_direction (GTK_WIDGET (path_bar));
-
   /* We find the button at the 'down' end that we have to make
    * visible */
   for (list = path_bar->button_list; list; list = list->next)
@@ -808,37 +818,24 @@ gtk_path_bar_scroll_down (GtkPathBar *path_bar)
 	  break;
 	}
     }
-  
-  /* Find the last visible button on the 'up' end
-   */
-  for (list = g_list_last (path_bar->button_list); list; list = list->prev)
-    {
-      if (gtk_widget_get_child_visible (BUTTON_DATA (list->data)->button))
-	{
-	  up_button = list;
-	  break;
-	}
-    }
 
-  /* We check if down_button might be NULL in cases where the pathbar's horizontal size is smaller
-   * than the button and it doesn't get displayed. e.g., on Windows it might be "My Documents and Settings"
+  space_available = (GTK_WIDGET (path_bar)->allocation.width
+		     - 2 * GTK_CONTAINER (path_bar)->border_width
+		     - 2 * path_bar->spacing - 2 * path_bar->slider_width
+		     - BUTTON_DATA (down_button->data)->button->allocation.width);
+  path_bar->first_scrolled_button = down_button;
+  
+  /* We have space_available free space that's not being used.  
+   * So we walk down from the end, adding buttons until we use all free space.
    */
-  space_needed = down_button ? BUTTON_DATA (down_button->data)->button->allocation.width : 0 + path_bar->spacing;
-  if (direction == GTK_TEXT_DIR_RTL)
-    space_available = path_bar->down_slider_button->allocation.x - GTK_WIDGET (path_bar)->allocation.x;
-  else
-    space_available = (GTK_WIDGET (path_bar)->allocation.x + GTK_WIDGET (path_bar)->allocation.width - border_width) -
-      (path_bar->down_slider_button->allocation.x + path_bar->down_slider_button->allocation.width);
-
-  /* We have space_available extra space that's not being used.  We
-   * need space_needed space to make the button fit.  So we walk down
-   * from the end, removing buttons until we get all the space we
-   * need. */
-  while (space_available < space_needed)
+  while (space_available > 0)
     {
-      space_available += BUTTON_DATA (up_button->data)->button->allocation.width + path_bar->spacing;
-      up_button = up_button->prev;
-      path_bar->first_scrolled_button = up_button;
+      path_bar->first_scrolled_button = down_button;
+      down_button = down_button->next;
+      if (!down_button)
+	break;
+      space_available -= (BUTTON_DATA (down_button->data)->button->allocation.width
+			  + path_bar->spacing);
     }
 }
 
@@ -1484,6 +1481,7 @@ make_directory_button (GtkPathBar  *path_bar,
     case NORMAL_BUTTON:
     default:
       button_data->label = gtk_label_new (NULL);
+      gtk_label_set_ellipsize (GTK_LABEL (button_data->label), PANGO_ELLIPSIZE_END);
       label_alignment = gtk_alignment_new (0.5, 0.5, 1.0, 1.0);
       gtk_container_add (GTK_CONTAINER (label_alignment), button_data->label);
       child = label_alignment;



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