[nautilus] pathbar: set a maximum label width for pathbar buttons



commit 79157f5617886401379a724f8c526c430c4876a6
Author: Cosimo Cecchi <cosimoc gnome org>
Date:   Mon Jun 4 15:44:04 2012 -0400

    pathbar: set a maximum label width for pathbar buttons
    
    Set a maximum allowed width of 250px for pathbar button requisitions,
    and ellipsize after that. This fixes buttons disappearing completely
    from the pathbar in case there was not enough space to show the complete
    folder name,
    
    I am not sure I completely like this approach in all the situations,
    since there might be some value in showing more of a very long folder
    name if there's space available on screen, but unfortunately, it's not
    really possible without restructuring completely the way NautilusPathBar
    allocates children.
    
    Adapted for master, and slightly modified from an initial patch by
    Ted M Lin <tedmlin gmail com>
    
    https://bugzilla.gnome.org/show_bug.cgi?id=313854

 src/nautilus-pathbar.c |   23 ++++++++++++++++++-----
 1 files changed, 18 insertions(+), 5 deletions(-)
---
diff --git a/src/nautilus-pathbar.c b/src/nautilus-pathbar.c
index 892d054..11b5db8 100644
--- a/src/nautilus-pathbar.c
+++ b/src/nautilus-pathbar.c
@@ -58,6 +58,7 @@ typedef enum {
 static guint path_bar_signals [LAST_SIGNAL] = { 0 };
 
 #define NAUTILUS_PATH_BAR_ICON_SIZE 16
+#define NAUTILUS_PATH_BAR_BUTTON_MAX_WIDTH 250
 
 typedef struct {
         GtkWidget *button;
@@ -447,6 +448,7 @@ nautilus_path_bar_size_allocate (GtkWidget     *widget,
         GtkAllocation child_allocation;
         GList *list, *first_button;
         gint width;
+        gint largest_width;
         gboolean need_sliders;
         gint up_slider_offset;
         gint down_slider_offset;
@@ -554,11 +556,17 @@ nautilus_path_bar_size_allocate (GtkWidget     *widget,
 		}
         }
 
+        /* Determine the largest possible allocation size */
+        largest_width = allocation->width;
+        if (need_sliders) {
+		largest_width -= (path_bar->priv->spacing + path_bar->priv->slider_width) * 2;
+        }
+
         for (list = first_button; list; list = list->prev) {
                 child = BUTTON_DATA (list->data)->button;
 		gtk_widget_get_preferred_size (child, &child_requisition, NULL);
 
-                child_allocation.width = child_requisition.width;
+                child_allocation.width = MIN (child_requisition.width, largest_width);
                 if (direction == GTK_TEXT_DIR_RTL) {
 			child_allocation.x -= child_allocation.width;
 		}
@@ -1248,10 +1256,11 @@ set_label_size_request (ButtonData *button_data)
 
         pango_layout_get_pixel_size (layout, &bold_width, &bold_height);
 
-	gtk_widget_set_size_request (button_data->alignment,
-				     MAX (width, bold_width),
-				     MAX (height, bold_height));
-	
+	width = MAX (width, bold_width);
+	width = MIN (width, NAUTILUS_PATH_BAR_BUTTON_MAX_WIDTH);
+	height = MAX (height, bold_height);
+
+	gtk_widget_set_size_request (button_data->alignment, width, height);
         g_object_unref (layout);
 }
 
@@ -1623,6 +1632,10 @@ make_button_data (NautilusPathBar  *path_bar,
 			gtk_box_pack_start (GTK_BOX (child), button_data->alignment, FALSE, FALSE, 0);
         }
 
+	if (button_data->label != NULL) {
+		gtk_label_set_ellipsize (GTK_LABEL (button_data->label), PANGO_ELLIPSIZE_MIDDLE);
+	}
+
 	if (button_data->path == NULL) {
         	button_data->path = g_object_ref (path);
 	}



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