Implement reverse ordering for use in Trash and RecentlyVisited actions

This commit is contained in:
Christian Dywan 2009-12-05 21:33:19 +01:00
parent 1c45254f23
commit 1fa2c95bf4
2 changed files with 45 additions and 7 deletions

View file

@ -30,6 +30,7 @@ struct _KatzeArrayAction
KatzeArray* array; KatzeArray* array;
KatzeNet* net; KatzeNet* net;
gboolean reversed;
}; };
struct _KatzeArrayActionClass struct _KatzeArrayActionClass
@ -43,7 +44,8 @@ enum
{ {
PROP_0, PROP_0,
PROP_ARRAY PROP_ARRAY,
PROP_REVERSED
}; };
enum enum
@ -158,6 +160,22 @@ katze_array_action_class_init (KatzeArrayActionClass* class)
"The array the action represents", "The array the action represents",
KATZE_TYPE_ARRAY, KATZE_TYPE_ARRAY,
G_PARAM_READWRITE)); G_PARAM_READWRITE));
/**
* KatzeArrayAction:reversed:
*
* Whether the array should be walked backwards when building menus.
*
* Since: 0.2.2
**/
g_object_class_install_property (gobject_class,
PROP_REVERSED,
g_param_spec_boolean (
"reversed",
"Reversed",
"Whether the array should be walked backwards when building menus",
FALSE,
G_PARAM_READWRITE));
} }
static void static void
@ -165,6 +183,7 @@ katze_array_action_init (KatzeArrayAction* array_action)
{ {
array_action->array = NULL; array_action->array = NULL;
array_action->net = katze_net_new (); array_action->net = katze_net_new ();
array_action->reversed = FALSE;
} }
static void static void
@ -191,6 +210,9 @@ katze_array_action_set_property (GObject* object,
case PROP_ARRAY: case PROP_ARRAY:
katze_array_action_set_array (array_action, g_value_get_object (value)); katze_array_action_set_array (array_action, g_value_get_object (value));
break; break;
case PROP_REVERSED:
array_action->reversed = g_value_get_boolean (value);
break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break; break;
@ -210,6 +232,9 @@ katze_array_action_get_property (GObject* object,
case PROP_ARRAY: case PROP_ARRAY:
g_value_set_object (value, array_action->array); g_value_set_object (value, array_action->array);
break; break;
case PROP_REVERSED:
g_value_set_boolean (value, array_action->reversed);
break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break; break;
@ -277,6 +302,7 @@ katze_array_action_generate_menu (KatzeArrayAction* array_action,
GtkWidget* proxy) GtkWidget* proxy)
{ {
guint i; guint i;
guint summand;
KatzeItem* item; KatzeItem* item;
GtkWidget* menuitem; GtkWidget* menuitem;
const gchar* icon_name; const gchar* icon_name;
@ -284,8 +310,17 @@ katze_array_action_generate_menu (KatzeArrayAction* array_action,
GtkWidget* image; GtkWidget* image;
GtkWidget* submenu; GtkWidget* submenu;
i = 0; if (array_action->reversed)
while ((item = katze_array_get_nth_item (array, i++))) {
i = katze_array_get_length (array);
summand = -1;
}
else
{
i = -1;
summand = +1;
}
while ((item = katze_array_get_nth_item (array, i += summand)))
{ {
/* FIXME: The menu item should reflect changes to the item */ /* FIXME: The menu item should reflect changes to the item */
if (!KATZE_IS_ARRAY (item) && !katze_item_get_uri (item)) if (!KATZE_IS_ARRAY (item) && !katze_item_get_uri (item))

View file

@ -5431,10 +5431,12 @@ midori_browser_set_history (MidoriBrowser* browser,
if (history && ((recently_visited = katze_array_get_nth_item (history, if (history && ((recently_visited = katze_array_get_nth_item (history,
katze_array_get_length (KATZE_ARRAY (history)) - 1)))) katze_array_get_length (KATZE_ARRAY (history)) - 1))))
g_object_set (_action_by_name (browser, "RecentlyVisited"), g_object_set (_action_by_name (browser, "RecentlyVisited"),
"array", recently_visited, NULL); "array", recently_visited, "reversed", TRUE,
NULL);
else else
g_object_set (_action_by_name (browser, "RecentlyVisited"), g_object_set (_action_by_name (browser, "RecentlyVisited"),
"array", NULL, NULL); "array", NULL, "reversed", FALSE,
NULL);
if (!history) if (!history)
return; return;
@ -6616,8 +6618,9 @@ midori_browser_set_property (GObject* object,
case PROP_TRASH: case PROP_TRASH:
/* FIXME: Disconnect handlers */ /* FIXME: Disconnect handlers */
katze_object_assign (browser->trash, g_value_dup_object (value)); katze_object_assign (browser->trash, g_value_dup_object (value));
g_object_set (_action_by_name (browser, "Trash"), "array", g_object_set (_action_by_name (browser, "Trash"),
browser->trash, NULL); "array", browser->trash, "reversed", TRUE,
NULL);
/* FIXME: Connect to updates */ /* FIXME: Connect to updates */
_midori_browser_update_actions (browser); _midori_browser_update_actions (browser);
break; break;