diff options
author | Cosimo Cecchi <cosimoc@gnome.org> | 2012-08-31 15:14:35 -0400 |
---|---|---|
committer | Cosimo Cecchi <cosimoc@gnome.org> | 2012-08-31 15:20:51 -0400 |
commit | c68a487c8faaad3afede2b6454f0c1f5a006de0a (patch) | |
tree | 36866a90b4e737a563f7501adc2cfc4539d026c5 /src/nautilus-floating-bar.c | |
parent | 9082b6b5788a77ade30882e309358e395de7580a (diff) | |
download | nautilus-c68a487c8faaad3afede2b6454f0c1f5a006de0a.tar.gz |
floating-bar: ellipsize the filename separately from the details
This patch does three things:
- It adds API to the floating bar to have primary and details labels
instead of a single label. The primary label is ellipsized separately
from the details, so it makes a good fit for a filename.
- Modifies the code setting status messages in NautilusView to split
them into two separate strings
- Removes obsolete code in NautilusView and NautilusWindowSlot that was
setting long statuses for the old non-floating statusbar
https://bugzilla.gnome.org/show_bug.cgi?id=660695
Diffstat (limited to 'src/nautilus-floating-bar.c')
-rw-r--r-- | src/nautilus-floating-bar.c | 126 |
1 files changed, 96 insertions, 30 deletions
diff --git a/src/nautilus-floating-bar.c b/src/nautilus-floating-bar.c index 4298dca3a..c90fdc35f 100644 --- a/src/nautilus-floating-bar.c +++ b/src/nautilus-floating-bar.c @@ -25,19 +25,24 @@ #include <config.h> +#include <string.h> + #include "nautilus-floating-bar.h" struct _NautilusFloatingBarDetails { - gchar *label; + gchar *primary_label; + gchar *details_label; - GtkWidget *label_widget; + GtkWidget *primary_label_widget; + GtkWidget *details_label_widget; GtkWidget *spinner; gboolean show_spinner; gboolean is_interactive; }; enum { - PROP_LABEL = 1, + PROP_PRIMARY_LABEL = 1, + PROP_DETAILS_LABEL, PROP_SHOW_SPINNER, NUM_PROPERTIES }; @@ -70,7 +75,8 @@ nautilus_floating_bar_finalize (GObject *obj) { NautilusFloatingBar *self = NAUTILUS_FLOATING_BAR (obj); - g_free (self->priv->label); + g_free (self->priv->primary_label); + g_free (self->priv->details_label); G_OBJECT_CLASS (nautilus_floating_bar_parent_class)->finalize (obj); } @@ -84,8 +90,11 @@ nautilus_floating_bar_get_property (GObject *object, NautilusFloatingBar *self = NAUTILUS_FLOATING_BAR (object); switch (property_id) { - case PROP_LABEL: - g_value_set_string (value, self->priv->label); + case PROP_PRIMARY_LABEL: + g_value_set_string (value, self->priv->primary_label); + break; + case PROP_DETAILS_LABEL: + g_value_set_string (value, self->priv->details_label); break; case PROP_SHOW_SPINNER: g_value_set_boolean (value, self->priv->show_spinner); @@ -105,8 +114,11 @@ nautilus_floating_bar_set_property (GObject *object, NautilusFloatingBar *self = NAUTILUS_FLOATING_BAR (object); switch (property_id) { - case PROP_LABEL: - nautilus_floating_bar_set_label (self, g_value_get_string (value)); + case PROP_PRIMARY_LABEL: + nautilus_floating_bar_set_primary_label (self, g_value_get_string (value)); + break; + case PROP_DETAILS_LABEL: + nautilus_floating_bar_set_details_label (self, g_value_get_string (value)); break; case PROP_SHOW_SPINNER: nautilus_floating_bar_set_show_spinner (self, g_value_get_boolean (value)); @@ -118,9 +130,22 @@ nautilus_floating_bar_set_property (GObject *object, } static void -update_label (NautilusFloatingBar *self) +update_labels (NautilusFloatingBar *self) { - gtk_label_set_text (GTK_LABEL (self->priv->label_widget), self->priv->label); + gboolean primary_visible, details_visible; + + primary_visible = (self->priv->primary_label != NULL) && + (strlen (self->priv->primary_label) > 0); + details_visible = (self->priv->details_label != NULL) && + (strlen (self->priv->details_label) > 0); + + gtk_label_set_text (GTK_LABEL (self->priv->primary_label_widget), + self->priv->primary_label); + gtk_widget_set_visible (self->priv->primary_label_widget, primary_visible); + + gtk_label_set_text (GTK_LABEL (self->priv->details_label_widget), + self->priv->details_label); + gtk_widget_set_visible (self->priv->details_label_widget, details_visible); } static gboolean @@ -218,7 +243,7 @@ static void nautilus_floating_bar_constructed (GObject *obj) { NautilusFloatingBar *self = NAUTILUS_FLOATING_BAR (obj); - GtkWidget *w, *box; + GtkWidget *w, *box, *labels_box; G_OBJECT_CLASS (nautilus_floating_bar_parent_class)->constructed (obj); @@ -232,17 +257,27 @@ nautilus_floating_bar_constructed (GObject *obj) gtk_widget_set_size_request (w, 16, 16); gtk_widget_set_margin_left (w, 8); - w = gtk_label_new (NULL); - gtk_label_set_ellipsize (GTK_LABEL (w), PANGO_ELLIPSIZE_END); - gtk_label_set_single_line_mode (GTK_LABEL (w), TRUE); - gtk_box_pack_start (GTK_BOX (box), w, FALSE, FALSE, 0); - g_object_set (w, + labels_box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6); + gtk_box_pack_start (GTK_BOX (box), labels_box, TRUE, TRUE, 0); + g_object_set (labels_box, "margin-top", 2, "margin-bottom", 2, "margin-left", 12, "margin-right", 12, NULL); - self->priv->label_widget = w; + gtk_widget_show (labels_box); + + w = gtk_label_new (NULL); + gtk_label_set_ellipsize (GTK_LABEL (w), PANGO_ELLIPSIZE_MIDDLE); + gtk_label_set_single_line_mode (GTK_LABEL (w), TRUE); + gtk_container_add (GTK_CONTAINER (labels_box), w); + self->priv->primary_label_widget = w; + gtk_widget_show (w); + + w = gtk_label_new (NULL); + gtk_label_set_single_line_mode (GTK_LABEL (w), TRUE); + gtk_container_add (GTK_CONTAINER (labels_box), w); + self->priv->details_label_widget = w; gtk_widget_show (w); } @@ -274,10 +309,16 @@ nautilus_floating_bar_class_init (NautilusFloatingBarClass *klass) wclass->hide = nautilus_floating_bar_hide; wclass->parent_set = nautilus_floating_bar_parent_set; - properties[PROP_LABEL] = - g_param_spec_string ("label", - "Bar's label", - "Label displayed by the bar", + properties[PROP_PRIMARY_LABEL] = + g_param_spec_string ("primary-label", + "Bar's primary label", + "Primary label displayed by the bar", + NULL, + G_PARAM_WRITABLE | G_PARAM_STATIC_STRINGS); + properties[PROP_DETAILS_LABEL] = + g_param_spec_string ("details-label", + "Bar's details label", + "Details label displayed by the bar", NULL, G_PARAM_WRITABLE | G_PARAM_STATIC_STRINGS); properties[PROP_SHOW_SPINNER] = @@ -301,20 +342,43 @@ nautilus_floating_bar_class_init (NautilusFloatingBarClass *klass) } void -nautilus_floating_bar_set_label (NautilusFloatingBar *self, - const gchar *label) +nautilus_floating_bar_set_primary_label (NautilusFloatingBar *self, + const gchar *label) +{ + if (g_strcmp0 (self->priv->primary_label, label) != 0) { + g_free (self->priv->primary_label); + self->priv->primary_label = g_strdup (label); + + g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_PRIMARY_LABEL]); + + update_labels (self); + } +} + +void +nautilus_floating_bar_set_details_label (NautilusFloatingBar *self, + const gchar *label) { - if (g_strcmp0 (self->priv->label, label) != 0) { - g_free (self->priv->label); - self->priv->label = g_strdup (label); + if (g_strcmp0 (self->priv->details_label, label) != 0) { + g_free (self->priv->details_label); + self->priv->details_label = g_strdup (label); - g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_LABEL]); + g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_DETAILS_LABEL]); - update_label (self); + update_labels (self); } } void +nautilus_floating_bar_set_labels (NautilusFloatingBar *self, + const gchar *primary_label, + const gchar *details_label) +{ + nautilus_floating_bar_set_primary_label (self, primary_label); + nautilus_floating_bar_set_details_label (self, details_label); +} + +void nautilus_floating_bar_set_show_spinner (NautilusFloatingBar *self, gboolean show_spinner) { @@ -328,11 +392,13 @@ nautilus_floating_bar_set_show_spinner (NautilusFloatingBar *self, } GtkWidget * -nautilus_floating_bar_new (const gchar *label, +nautilus_floating_bar_new (const gchar *primary_label, + const gchar *details_label, gboolean show_spinner) { return g_object_new (NAUTILUS_TYPE_FLOATING_BAR, - "label", label, + "primary-label", primary_label, + "details-label", details_label, "show-spinner", show_spinner, "orientation", GTK_ORIENTATION_HORIZONTAL, "spacing", 8, |