[gtk+/wip/csoriano/bookmarks: 50/50] use ui for the row and adapt margins
- From: Carlos Soriano Sánchez <csoriano src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/wip/csoriano/bookmarks: 50/50] use ui for the row and adapt margins
- Date: Mon, 11 May 2015 17:44:18 +0000 (UTC)
commit dfe7a45665cf397012d29129f3a6632bde9f6159
Author: Carlos Soriano <csoriano gnome org>
Date: Sat May 9 18:32:11 2015 +0200
use ui for the row and adapt margins
gtk/Makefile.am | 3 +-
gtk/gtkplacessidebar.c | 78 +++++++++++++++++++++++------------------------
2 files changed, 40 insertions(+), 41 deletions(-)
---
diff --git a/gtk/Makefile.am b/gtk/Makefile.am
index 9e8b2a8..5cb6858 100644
--- a/gtk/Makefile.am
+++ b/gtk/Makefile.am
@@ -1085,7 +1085,8 @@ templates = \
ui/gtksearchbar.ui \
ui/gtkscalebutton.ui \
ui/gtkstatusbar.ui \
- ui/gtkvolumebutton.ui
+ ui/gtkvolumebutton.ui \
+ ui/sidebarrow.ui
#
# rules to generate built sources
diff --git a/gtk/gtkplacessidebar.c b/gtk/gtkplacessidebar.c
index 18ed32c..cdc0ffb 100644
--- a/gtk/gtkplacessidebar.c
+++ b/gtk/gtkplacessidebar.c
@@ -597,33 +597,15 @@ sidebar_row_set_property (GObject *object,
static void
sidebar_row_init (SidebarRow *self)
{
- GtkWidget *hbox;
- SidebarRowPrivate *priv = sidebar_row_get_instance_private (self);
- GtkStyleContext *css_context;
-
- hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
- priv->icon_widget = gtk_image_new ();
- gtk_widget_set_margin_start (priv->icon_widget, 10);
- gtk_container_add (GTK_CONTAINER (hbox), priv->icon_widget);
- priv->label_widget = gtk_label_new (NULL);
- gtk_widget_set_margin_start (priv->label_widget, 10);
- gtk_container_add (GTK_CONTAINER (hbox), priv->label_widget);
- priv->eject_button = gtk_button_new_from_icon_name ("media-eject-symbolic", GTK_ICON_SIZE_MENU);
- css_context = gtk_widget_get_style_context (priv->eject_button);
- gtk_style_context_add_class (css_context, "flat");
- gtk_widget_set_margin_start (priv->eject_button, 15);
- gtk_widget_set_hexpand (priv->eject_button, TRUE);
- gtk_widget_set_halign (priv->eject_button, GTK_ALIGN_END);
- gtk_widget_set_valign (priv->eject_button, GTK_ALIGN_CENTER);
- gtk_container_add (GTK_CONTAINER (hbox), priv->eject_button);
-
- gtk_container_add (GTK_CONTAINER (self), hbox);
+ gtk_widget_init_template (GTK_WIDGET (self));
}
static void
sidebar_row_class_init (SidebarRowClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
+
object_class->get_property = sidebar_row_get_property;
object_class->set_property = sidebar_row_set_property;
@@ -689,16 +671,16 @@ sidebar_row_class_init (SidebarRowClass *klass)
g_object_class_install_property (object_class, PROP_PLACE_TYPE,
gParamSpecs [PROP_PLACE_TYPE]);
- gParamSpecs [PROP_URI] =
- g_param_spec_string ("uri",
- "Uri",
- "Uri",
- NULL,
- (G_PARAM_READWRITE |
- G_PARAM_CONSTRUCT_ONLY |
- G_PARAM_STATIC_STRINGS));
- g_object_class_install_property (object_class, PROP_URI,
- gParamSpecs [PROP_URI]);
+ gParamSpecs [PROP_URI] =
+ g_param_spec_string ("uri",
+ "Uri",
+ "Uri",
+ NULL,
+ (G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT_ONLY |
+ G_PARAM_STATIC_STRINGS));
+ g_object_class_install_property (object_class, PROP_URI,
+ gParamSpecs [PROP_URI]);
gParamSpecs [PROP_DRIVE] =
g_param_spec_object ("drive",
"Drive",
@@ -731,6 +713,14 @@ sidebar_row_class_init (SidebarRowClass *klass)
G_PARAM_STATIC_STRINGS));
g_object_class_install_property (object_class, PROP_MOUNT,
gParamSpecs [PROP_MOUNT]);
+
+ gtk_widget_class_set_template_from_resource (widget_class,
+ "/org/gtk/libgtk/ui/sidebarrow.ui");
+
+ gtk_widget_class_bind_template_child_private (widget_class, SidebarRow, icon_widget);
+ gtk_widget_class_bind_template_child_private (widget_class, SidebarRow, label_widget);
+ gtk_widget_class_bind_template_child_private (widget_class, SidebarRow, eject_button);
+
}
static void
@@ -844,13 +834,14 @@ add_heading (GtkPlacesSidebar *sidebar,
static void
add_separator (GtkListBoxRow *row,
- GtkListBoxRow *before,
+ GtkListBoxRow *before,
gpointer user_data)
{
SectionType row_section_type;
SectionType before_section_type;
gchar *name, *name2 = NULL;
GtkPlacesSidebar *sidebar = GTK_PLACES_SIDEBAR (user_data);
+ GtkWidget *separator;
g_object_get (row, "section-type", &row_section_type, "label", &name, NULL);
if (before)
@@ -863,7 +854,10 @@ add_separator (GtkListBoxRow *row,
case SECTION_DEVICES:
if (!sidebar->devices_header_added && before && before_section_type != row_section_type)
{
- gtk_list_box_row_set_header (row, gtk_separator_new (GTK_ORIENTATION_HORIZONTAL));
+ separator = gtk_separator_new (GTK_ORIENTATION_HORIZONTAL);
+ gtk_widget_set_margin_top (separator, 4);
+ gtk_widget_set_margin_bottom (separator, 4);
+ gtk_list_box_row_set_header (row, separator);
sidebar->devices_header_added = TRUE;
}
break;
@@ -871,11 +865,20 @@ add_separator (GtkListBoxRow *row,
case SECTION_BOOKMARKS:
if (!sidebar->bookmarks_header_added && before && before_section_type != row_section_type)
{
- gtk_list_box_row_set_header (row, gtk_separator_new (GTK_ORIENTATION_HORIZONTAL));
+ separator = gtk_separator_new (GTK_ORIENTATION_HORIZONTAL);
+ gtk_widget_set_margin_top (separator, 4);
+ gtk_widget_set_margin_bottom (separator, 4);
+ gtk_list_box_row_set_header (row, separator);
sidebar->bookmarks_header_added = TRUE;
}
break;
+ case SECTION_0:
+ {
+ if (before == NULL)
+ gtk_widget_set_margin_top (GTK_WIDGET (row), 4);
+ }
+
default:
break;
}
@@ -922,11 +925,6 @@ add_place (GtkPlacesSidebar *sidebar,
"mount", mount,
NULL);
- if (g_list_length (gtk_container_get_children (GTK_CONTAINER (sidebar->list_box))) == 0)
- gtk_widget_set_margin_top (GTK_WIDGET (row), 4);
- else
- gtk_widget_set_margin_top (GTK_WIDGET (row), 2);
-
gtk_container_add (GTK_CONTAINER (sidebar->list_box), GTK_WIDGET (row));
gtk_widget_show_all (GTK_WIDGET (row));
}
@@ -4675,7 +4673,7 @@ gtk_places_sidebar_init (GtkPlacesSidebar *sidebar)
add_separator, sidebar, NULL);
gtk_list_box_set_selection_mode (GTK_LIST_BOX (sidebar->list_box),
GTK_SELECTION_BROWSE);
- gtk_list_box_set_activate_on_single_click (GTK_LIST_BOX (sidebar),
+ gtk_list_box_set_activate_on_single_click (GTK_LIST_BOX (sidebar->list_box),
TRUE);
g_signal_connect (sidebar->list_box,
"row-activated",
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]