[Xfce4-commits] <xfce4-indicator-plugin:andrzejr/tmp3> Sort indicator entries by location.

Andrzej noreply at xfce.org
Tue Mar 12 23:54:01 CET 2013


Updating branch refs/heads/andrzejr/tmp3
         to 33d3eb312c04fb7ae12e2a316e52a838267e5e0a (commit)
       from 290c5f4596900e67f3c2e87f730812e8e48a9333 (commit)

commit 33d3eb312c04fb7ae12e2a316e52a838267e5e0a
Author: Andrzej <ndrwrdck at gmail.com>
Date:   Tue Mar 12 22:53:25 2013 +0000

    Sort indicator entries by location.
    
    (or by name_hint, or don't sort at all)

 panel-plugin/indicator-box.c    |   32 +++++++++++++++++++++++++++++++-
 panel-plugin/indicator-button.c |   14 ++++++++++++++
 panel-plugin/indicator-button.h |    2 ++
 3 files changed, 47 insertions(+), 1 deletions(-)

diff --git a/panel-plugin/indicator-box.c b/panel-plugin/indicator-box.c
index 3b820a9..c39435e 100644
--- a/panel-plugin/indicator-box.c
+++ b/panel-plugin/indicator-box.c
@@ -163,6 +163,32 @@ xfce_indicator_box_list_changed (XfceIndicatorBox *box,
 
 
 
+static gint
+xfce_indicator_box_sort_buttons (gconstpointer a,
+                                 gconstpointer b)
+{
+  XfceIndicatorButton *a0 = XFCE_INDICATOR_BUTTON (a);
+  XfceIndicatorButton *b0 = XFCE_INDICATOR_BUTTON (b);
+  guint                a1, b1;
+
+  a1 = xfce_indicator_button_get_pos (a0);
+  b1 = xfce_indicator_button_get_pos (b0);
+
+  /* group all entries with location==0 at the beginning of the list
+   * but don't sort them (they may depend on insertion order) */
+
+  /* if there are two entries with the same non-zero location
+   * try to resolve their order by their name_hint */
+  if (a1 != 0 && a1 == b1)
+    return -g_strcmp0 (xfce_indicator_button_get_entry(a0)->name_hint,
+                       xfce_indicator_button_get_entry(b0)->name_hint);
+
+  /* else, use the location field */
+  return (a1-b1);
+}
+
+
+
 static void
 xfce_indicator_box_add (GtkContainer *container,
                         GtkWidget    *child)
@@ -178,7 +204,11 @@ xfce_indicator_box_add (GtkContainer *container,
 
   io_name = xfce_indicator_button_get_io_name (button);
   li = g_hash_table_lookup (box->children, io_name);
-  li = g_list_append (li, button);
+  if (xfce_indicator_button_get_pos (button) == 0)
+    li = g_list_append (li, button);
+  else
+    li = g_list_insert_sorted (li, button, xfce_indicator_box_sort_buttons);
+
   g_hash_table_replace (box->children, g_strdup (io_name), li);
 
   gtk_widget_set_parent (child, GTK_WIDGET (box));
diff --git a/panel-plugin/indicator-button.c b/panel-plugin/indicator-button.c
index f01db2f..98f547d 100644
--- a/panel-plugin/indicator-button.c
+++ b/panel-plugin/indicator-button.c
@@ -434,6 +434,20 @@ xfce_indicator_button_get_io_name (XfceIndicatorButton *button)
 
 
 
+guint
+xfce_indicator_button_get_pos (XfceIndicatorButton *button)
+{
+  g_return_val_if_fail (XFCE_IS_INDICATOR_BUTTON (button), 0);
+
+  return indicator_object_get_location (button->io, button->entry);
+}
+
+
+
+
+
+
+
 GtkMenu *
 xfce_indicator_button_get_menu (XfceIndicatorButton *button)
 {
diff --git a/panel-plugin/indicator-button.h b/panel-plugin/indicator-button.h
index 5eb1dc1..b25efa6 100644
--- a/panel-plugin/indicator-button.h
+++ b/panel-plugin/indicator-button.h
@@ -59,6 +59,8 @@ IndicatorObject        *xfce_indicator_button_get_io      (XfceIndicatorButton
 
 const gchar            *xfce_indicator_button_get_io_name (XfceIndicatorButton        *button);
 
+guint                   xfce_indicator_button_get_pos     (XfceIndicatorButton        *button);
+
 GtkMenu                *xfce_indicator_button_get_menu    (XfceIndicatorButton        *button);
 
 GtkWidget              *xfce_indicator_button_new         (IndicatorObject            *io,


More information about the Xfce4-commits mailing list