[Xfce4-commits] <midori:master> Keep a timestamp of KatzeArray changes around

Christian Dywan noreply at xfce.org
Tue Feb 21 22:28:01 CET 2012


Updating branch refs/heads/master
         to 90ee1384a708436aee4b4884d8c4461ea7761ddf (commit)
       from 5c0255f7cb472fdfeb1b2d12a6dce759ec3dbbcc (commit)

commit 90ee1384a708436aee4b4884d8c4461ea7761ddf
Author: Christian Dywan <christian at twotoasts.de>
Date:   Tue Feb 21 22:24:42 2012 +0100

    Keep a timestamp of KatzeArray changes around
    
    To avoid re-populating array actions when unneeded.
    
    This also increases compatibility with global menubar
    support which otherwise flickers.

 katze/katze-array.c       |   18 ++++++++++++++++-
 katze/katze-arrayaction.c |   47 ++++++++++++++++++++++++++++++++------------
 katze/katze-item.c        |    4 +++
 3 files changed, 55 insertions(+), 14 deletions(-)

diff --git a/katze/katze-array.c b/katze/katze-array.c
index 210a97f..7e2e2e1 100644
--- a/katze/katze-array.c
+++ b/katze/katze-array.c
@@ -84,6 +84,8 @@ _katze_array_add_item (KatzeArray* array,
         katze_item_set_parent (item, array);
 
     array->items = g_list_append (array->items, item);
+    g_object_set_data (G_OBJECT (array), "last-update",
+                       GINT_TO_POINTER (time (NULL)));
 }
 
 static void
@@ -95,6 +97,8 @@ _katze_array_remove_item (KatzeArray* array,
     if (KATZE_IS_ITEM (item))
         katze_item_set_parent (item, NULL);
     g_object_unref (item);
+    g_object_set_data (G_OBJECT (array), "last-update",
+                       GINT_TO_POINTER (time (NULL)));
 }
 
 static void
@@ -104,6 +108,8 @@ _katze_array_move_item (KatzeArray* array,
 {
     array->items = g_list_remove (array->items, item);
     array->items = g_list_insert (array->items, item, position);
+    g_object_set_data (G_OBJECT (array), "last-update",
+                       GINT_TO_POINTER (time (NULL)));
 }
 
 static void
@@ -115,6 +121,15 @@ _katze_array_clear (KatzeArray* array)
         g_signal_emit (array, signals[REMOVE_ITEM], 0, item);
     g_list_free (array->items);
     array->items = NULL;
+    g_object_set_data (G_OBJECT (array), "last-update",
+                       GINT_TO_POINTER (time (NULL)));
+}
+
+static void
+_katze_array_update (KatzeArray* array)
+{
+    g_object_set_data (G_OBJECT (array), "last-update",
+                       GINT_TO_POINTER (time (NULL)));
 }
 
 static void
@@ -192,7 +207,7 @@ katze_array_class_init (KatzeArrayClass* class)
         "update",
         G_TYPE_FROM_CLASS (class),
         (GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION),
-        0,
+        G_STRUCT_OFFSET (KatzeArrayClass, update),
         0,
         NULL,
         g_cclosure_marshal_VOID__VOID,
@@ -205,6 +220,7 @@ katze_array_class_init (KatzeArrayClass* class)
     class->remove_item = _katze_array_remove_item;
     class->move_item = _katze_array_move_item;
     class->clear = _katze_array_clear;
+    class->update = _katze_array_update;
 }
 
 static void
diff --git a/katze/katze-arrayaction.c b/katze/katze-arrayaction.c
index e69e1e7..1256dbd 100644
--- a/katze/katze-arrayaction.c
+++ b/katze/katze-arrayaction.c
@@ -408,21 +408,39 @@ katze_array_action_generate_menu (KatzeArrayAction* array_action,
     }
 }
 
-static void
-katze_array_action_menu_item_select_cb (GtkWidget*        proxy,
-                                        KatzeArrayAction* array_action)
+static gboolean
+katze_array_action_menu_item_need_update (KatzeArrayAction* array_action,
+                                          GtkWidget*        proxy)
 {
     GtkWidget* menu;
     KatzeArray* array;
+    gint last_array_update, last_proxy_update;
     gboolean handled;
 
+    array = g_object_get_data (G_OBJECT (proxy), "KatzeItem");
+    /* last-update is set on all arrays; consider public API */
+    last_array_update = GPOINTER_TO_INT (
+        g_object_get_data (G_OBJECT (array), "last-update"));
+    last_proxy_update = GPOINTER_TO_INT (
+        g_object_get_data (G_OBJECT (proxy), "last-update"));
+    if (last_proxy_update >= last_array_update)
+        return FALSE;
+
     menu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (proxy));
     gtk_container_foreach (GTK_CONTAINER (menu),
         (GtkCallback)(gtk_widget_destroy), NULL);
-
-    array = g_object_get_data (G_OBJECT (proxy), "KatzeItem");
     katze_array_action_generate_menu (array_action, array, GTK_MENU_SHELL (menu), proxy);
     g_signal_emit (array_action, signals[POPULATE_FOLDER], 0, menu, array, &handled);
+    g_object_set_data (G_OBJECT (proxy), "last-update",
+                       GINT_TO_POINTER (time (NULL)));
+    return TRUE;
+}
+
+static void
+katze_array_action_menu_item_select_cb (GtkWidget*        proxy,
+                                        KatzeArrayAction* array_action)
+{
+    katze_array_action_menu_item_need_update (array_action, proxy);
 }
 
 static void
@@ -448,13 +466,15 @@ katze_array_action_proxy_clicked_cb (GtkWidget*        proxy,
     if (GTK_IS_MENU_ITEM (proxy))
     {
         g_object_set_data (G_OBJECT (proxy), "KatzeItem", array_action->array);
-        katze_array_action_menu_item_select_cb (proxy, array_action);
-        g_signal_emit (array_action, signals[POPULATE_FOLDER], 0,
-                       gtk_menu_item_get_submenu (GTK_MENU_ITEM (proxy)),
-                       array_action->array, &handled);
-        if (!handled)
-            g_signal_emit (array_action, signals[POPULATE_POPUP], 0,
-                gtk_menu_item_get_submenu (GTK_MENU_ITEM (proxy)));
+        if (katze_array_action_menu_item_need_update (array_action, proxy))
+        {
+            g_signal_emit (array_action, signals[POPULATE_FOLDER], 0,
+                           gtk_menu_item_get_submenu (GTK_MENU_ITEM (proxy)),
+                           array_action->array, &handled);
+            if (!handled)
+                g_signal_emit (array_action, signals[POPULATE_POPUP], 0,
+                    gtk_menu_item_get_submenu (GTK_MENU_ITEM (proxy)));
+        }
         return;
     }
 
@@ -711,9 +731,10 @@ katze_array_action_connect_proxy (GtkAction* action,
     else if (GTK_IS_MENU_ITEM (proxy))
     {
         gtk_menu_item_set_submenu (GTK_MENU_ITEM (proxy), gtk_menu_new ());
-        /* FIXME: 'select' doesn't cover all ways of selection */
         g_signal_connect (proxy, "select",
             G_CALLBACK (katze_array_action_proxy_clicked_cb), action);
+        g_signal_connect (proxy, "activate",
+            G_CALLBACK (katze_array_action_proxy_clicked_cb), action);
     }
 }
 
diff --git a/katze/katze-item.c b/katze/katze-item.c
index b9ca060..7df2ea0 100644
--- a/katze/katze-item.c
+++ b/katze/katze-item.c
@@ -315,6 +315,8 @@ katze_item_set_name (KatzeItem*   item,
     g_return_if_fail (KATZE_IS_ITEM (item));
 
     katze_assign (item->name, g_strdup (name));
+    if (item->parent)
+        katze_array_update ((KatzeArray*)item->parent);
     g_object_notify (G_OBJECT (item), "name");
 }
 
@@ -414,6 +416,8 @@ katze_item_set_icon (KatzeItem*   item,
     g_return_if_fail (KATZE_IS_ITEM (item));
 
     katze_item_set_meta_string (item, "icon", icon);
+    if (item->parent)
+        katze_array_update ((KatzeArray*)item->parent);
     g_object_notify (G_OBJECT (item), "icon");
 }
 


More information about the Xfce4-commits mailing list