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