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.
This commit is contained in:
Christian Dywan 2012-02-21 22:24:42 +01:00
parent 5c0255f7cb
commit 90ee1384a7
3 changed files with 55 additions and 14 deletions

View file

@ -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

View file

@ -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);
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);
}
}

View file

@ -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");
}