[Xfce4-commits] <thunar:jannis/new-shortcuts-pane> Properly align ThunarShortcut contents with group titles.

Jannis Pohlmann noreply at xfce.org
Thu Nov 17 17:02:01 CET 2011


Updating branch refs/heads/jannis/new-shortcuts-pane
         to 37bc2b962d2dc834e8ad34853f7a0ba7d15adb49 (commit)
       from 1c82b51da2829aaba70f6bf289d77a12c11401e3 (commit)

commit 37bc2b962d2dc834e8ad34853f7a0ba7d15adb49
Author: Jannis Pohlmann <jannis at xfce.org>
Date:   Thu Nov 17 15:59:44 2011 +0000

    Properly align ThunarShortcut contents with group titles.

 thunar/thunar-shortcut-group.c |   58 ++++++++++++++++++++++++++++++++++++++++
 thunar/thunar-shortcut.c       |   22 ++++++++++-----
 thunar/thunar-shortcut.h       |    1 +
 3 files changed, 74 insertions(+), 7 deletions(-)

diff --git a/thunar/thunar-shortcut-group.c b/thunar/thunar-shortcut-group.c
index 9b23619..ee8e16b 100644
--- a/thunar/thunar-shortcut-group.c
+++ b/thunar/thunar-shortcut-group.c
@@ -61,6 +61,11 @@ static void     thunar_shortcut_group_set_property      (GObject
                                                          GParamSpec             *pspec);
 static void     thunar_shortcut_group_attract_attention (ThunarShortcutGroup    *group);
 static gboolean thunar_shortcut_group_flash_expander    (gpointer                user_data);
+static void     thunar_shortcut_group_expand_style_set  (ThunarShortcutGroup    *group,
+                                                         GtkStyle               *style,
+                                                         GtkWidget              *expander);
+static void     thunar_shortcut_group_apply_indentation (ThunarShortcutGroup    *group,
+                                                         ThunarShortcut         *shortcut);
 
 
 
@@ -138,6 +143,10 @@ thunar_shortcut_group_init (ThunarShortcutGroup *group)
   gtk_container_add (GTK_CONTAINER (group), group->expander);
   gtk_widget_show (group->expander);
 
+  g_signal_connect_swapped (group->expander, "style-set",
+                            G_CALLBACK (thunar_shortcut_group_expand_style_set),
+                            group);
+
   /* add a box for the individual shortcuts */
   group->shortcuts = gtk_vbox_new (TRUE, 0);
   gtk_container_add (GTK_CONTAINER (group->expander), group->shortcuts);
@@ -309,6 +318,52 @@ thunar_shortcut_group_flash_expander (gpointer user_data)
 
 
 
+static void
+thunar_shortcut_group_expand_style_set (ThunarShortcutGroup *group,
+                                        GtkStyle            *style,
+                                        GtkWidget           *expander)
+{
+  GList *children;
+  GList *iter;
+
+  _thunar_return_if_fail (THUNAR_IS_SHORTCUT_GROUP (group));
+  _thunar_return_if_fail (GTK_IS_EXPANDER (expander));
+  _thunar_return_if_fail (expander == group->expander);
+  
+  children = gtk_container_get_children (GTK_CONTAINER (group->shortcuts));
+
+  for (iter = children; iter != NULL; iter = iter->next)
+    thunar_shortcut_group_apply_indentation (group, THUNAR_SHORTCUT (iter->data));
+
+  g_list_free (children);
+}
+
+
+
+static void
+thunar_shortcut_group_apply_indentation (ThunarShortcutGroup *group,
+                                         ThunarShortcut      *shortcut)
+{
+  GtkWidget *alignment;
+  gint       expander_size;
+  gint       expander_spacing;
+
+  _thunar_return_if_fail (THUNAR_IS_SHORTCUT_GROUP (group));
+  _thunar_return_if_fail (THUNAR_IS_SHORTCUT (shortcut));
+
+  /* get information about the expander arrow size */
+  gtk_widget_style_get (group->expander,
+                        "expander-size", &expander_size,
+                        "expander-spacing", &expander_spacing,
+                        NULL);
+
+  /* apply the indentation to the shortcut alignment */
+  alignment = thunar_shortcut_get_alignment (shortcut);
+  g_object_set (alignment, "left-padding", expander_size + expander_spacing * 2 + 1, NULL);
+}
+
+
+
 GtkWidget *
 thunar_shortcut_group_new (const gchar       *label,
                            ThunarShortcutType accepted_types)
@@ -341,6 +396,9 @@ thunar_shortcut_group_try_add_shortcut (ThunarShortcutGroup *group,
 
   /* TODO find the sorting, remembered or user-defined position for the shortcut */
 
+  /* properly align the shortcut contents with the group title */
+  thunar_shortcut_group_apply_indentation (group, shortcut);
+
   gtk_box_pack_start (GTK_BOX (group->shortcuts), GTK_WIDGET (shortcut), FALSE, TRUE, 0);
   gtk_widget_show (GTK_WIDGET (shortcut));
 
diff --git a/thunar/thunar-shortcut.c b/thunar/thunar-shortcut.c
index c13e51c..66fa959 100644
--- a/thunar/thunar-shortcut.c
+++ b/thunar/thunar-shortcut.c
@@ -191,6 +191,7 @@ struct _ThunarShortcut
   guint               persistent : 1;
   guint               constructed : 1;
 
+  GtkWidget          *alignment;
   GtkWidget          *label_widget;
   GtkWidget          *icon_image;
   GtkWidget          *action_button;
@@ -391,7 +392,6 @@ thunar_shortcut_class_init (ThunarShortcutClass *klass)
 static void
 thunar_shortcut_init (ThunarShortcut *shortcut)
 {
-  GtkWidget *alignment;
   GtkWidget *box;
 
   /* create a cancellable for aborting mount/unmount operations */
@@ -405,15 +405,14 @@ thunar_shortcut_init (ThunarShortcut *shortcut)
   gtk_widget_set_sensitive (GTK_WIDGET (shortcut), TRUE);
 
   /* create the alignment for left and right padding */
-  alignment = gtk_alignment_new (0.0f, 0.0f, 1.0f, 1.0f);
-  /* TODO use expander arrow width instead of 16 here */
-  gtk_alignment_set_padding (GTK_ALIGNMENT (alignment), 0, 0, 16, 4);
-  gtk_container_add (GTK_CONTAINER (shortcut), alignment);
-  gtk_widget_show (alignment);
+  shortcut->alignment = gtk_alignment_new (0.0f, 0.0f, 1.0f, 1.0f);
+  gtk_alignment_set_padding (GTK_ALIGNMENT (shortcut->alignment), 0, 0, 0, 4);
+  gtk_container_add (GTK_CONTAINER (shortcut), shortcut->alignment);
+  gtk_widget_show (shortcut->alignment);
 
   /* create a box for the different sub-widgets */
   box = gtk_hbox_new (FALSE, 4);
-  gtk_container_add (GTK_CONTAINER (alignment), box);
+  gtk_container_add (GTK_CONTAINER (shortcut->alignment), box);
   gtk_widget_show (box);
 
   /* create the icon widget */
@@ -1999,6 +1998,15 @@ thunar_shortcut_set_persistent (ThunarShortcut *shortcut,
 
 
 
+GtkWidget *
+thunar_shortcut_get_alignment (ThunarShortcut *shortcut)
+{
+  _thunar_return_val_if_fail (THUNAR_IS_SHORTCUT (shortcut), NULL);
+  return shortcut->alignment;
+}
+
+
+
 void
 thunar_shortcut_resolve_and_activate (ThunarShortcut *shortcut,
                                       gboolean        open_in_new_window)
diff --git a/thunar/thunar-shortcut.h b/thunar/thunar-shortcut.h
index 59395f1..4cd0bc2 100644
--- a/thunar/thunar-shortcut.h
+++ b/thunar/thunar-shortcut.h
@@ -81,6 +81,7 @@ void               thunar_shortcut_set_mutable          (ThunarShortcut    *shor
 gboolean           thunar_shortcut_get_persistent       (ThunarShortcut    *shortcut);
 void               thunar_shortcut_set_persistent       (ThunarShortcut    *shortcut,
                                                          gboolean           persistent);
+GtkWidget         *thunar_shortcut_get_alignment        (ThunarShortcut    *shortcut);
 void               thunar_shortcut_resolve_and_activate (ThunarShortcut    *shortcut,
                                                          gboolean           open_in_new_window);
 void               thunar_shortcut_cancel_activation    (ThunarShortcut    *shortcut);


More information about the Xfce4-commits mailing list