placesview: vertically align path labels

The current situation is somewhat sad, with the path
label totally misaligned throughout the rows.

This is fixed by using a size group for the path labels,
so they all have the same allocated size (with the max
of 15 chars). Also, instead of hiding the eject button,
set it child-invisible, so it is hidden and yet it's size
is allocated by GtkBox.

https://bugzilla.gnome.org/show_bug.cgi?id=757303
This commit is contained in:
Georges Basile Stavracas Neto 2015-10-29 10:14:57 -02:00
parent 84380b345d
commit 50c6a11b05
4 changed files with 29 additions and 3 deletions

View File

@ -72,6 +72,8 @@ struct _GtkPlacesViewPrivate
GtkWidget *network_placeholder;
GtkWidget *network_placeholder_label;
GtkSizeGroup *path_size_group;
GtkEntryCompletion *address_entry_completion;
GtkListStore *completion_store;
@ -406,6 +408,7 @@ gtk_places_view_finalize (GObject *object)
g_clear_object (&priv->volume_monitor);
g_clear_object (&priv->cancellable);
g_clear_object (&priv->networks_fetching_cancellable);
g_clear_object (&priv->path_size_group);
G_OBJECT_CLASS (gtk_places_view_parent_class)->finalize (object);
}
@ -674,6 +677,8 @@ insert_row (GtkPlacesView *view,
G_CALLBACK (on_eject_button_clicked),
row);
gtk_places_view_row_set_path_size_group (GTK_PLACES_VIEW_ROW (row), priv->path_size_group);
gtk_container_add (GTK_CONTAINER (priv->listbox), row);
}
@ -2254,6 +2259,7 @@ gtk_places_view_init (GtkPlacesView *self)
priv->volume_monitor = g_volume_monitor_get ();
priv->open_flags = GTK_PLACES_OPEN_NORMAL;
priv->path_size_group = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL);
gtk_widget_init_template (GTK_WIDGET (self));
}

View File

@ -150,7 +150,15 @@ gtk_places_view_row_set_property (GObject *object,
case PROP_MOUNT:
g_set_object (&self->mount, g_value_get_object (value));
gtk_widget_set_visible (GTK_WIDGET (self->eject_button), self->mount != NULL);
/*
* When we hide the eject button, no size is allocated for it. Since
* we want to have alignment between rows, it needs an empty space
* when the eject button is not available. So, call then
* gtk_widget_set_child_visible(), which makes the button allocate the
* size but it stays hidden when needed.
*/
gtk_widget_set_child_visible (GTK_WIDGET (self->eject_button), self->mount != NULL);
break;
case PROP_FILE:
@ -323,3 +331,11 @@ gtk_places_view_row_set_is_network (GtkPlacesViewRow *row,
gtk_widget_set_tooltip_text (GTK_WIDGET (row->eject_button), is_network ? _("Disconnect") : _("Unmount"));
}
}
void
gtk_places_view_row_set_path_size_group (GtkPlacesViewRow *row,
GtkSizeGroup *group)
{
if (group)
gtk_size_group_add_widget (group, GTK_WIDGET (row->path_label));
}

View File

@ -24,6 +24,7 @@
#endif
#include "gtkwidget.h"
#include "gtksizegroup.h"
#include "gtklistbox.h"
G_BEGIN_DECLS
@ -53,6 +54,9 @@ gboolean gtk_places_view_row_get_is_network (GtkPlacesViewR
void gtk_places_view_row_set_is_network (GtkPlacesViewRow *row,
gboolean is_network);
void gtk_places_view_row_set_path_size_group (GtkPlacesViewRow *row,
GtkSizeGroup *group);
G_END_DECLS
#endif /* GTK_PLACES_VIEW_ROW_H */

View File

@ -40,8 +40,7 @@
<property name="visible">1</property>
<property name="justify">right</property>
<property name="ellipsize">middle</property>
<property name="xalign">1</property>
<property name="width_chars">15</property>
<property name="xalign">0</property>
<property name="max_width_chars">15</property>
<style>
<class name="dim-label"/>
@ -53,6 +52,7 @@
</child>
<child>
<object class="GtkButton" id="eject_button">
<property name="visible">True</property>
<property name="halign">end</property>
<property name="valign">center</property>
<property name="tooltip-text" translatable="yes">Unmount</property>