diff --git a/katze/katze-array.c b/katze/katze-array.c index baebfeac..ae451ab7 100644 --- a/katze/katze-array.c +++ b/katze/katze-array.c @@ -12,6 +12,7 @@ #include "katze-array.h" #include "katze-utils.h" +#include "marshal.h" #include #include @@ -44,6 +45,10 @@ struct _KatzeArrayClass (*remove_item) (KatzeArray* array, gpointer item); void + (*move_item) (KatzeArray* array, + gpointer item, + gint index); + void (*clear) (KatzeArray* array); }; @@ -52,6 +57,7 @@ G_DEFINE_TYPE (KatzeArray, katze_array, KATZE_TYPE_ITEM); enum { ADD_ITEM, REMOVE_ITEM, + MOVE_ITEM, CLEAR, LAST_SIGNAL @@ -93,6 +99,15 @@ _katze_array_remove_item (KatzeArray* array, } } +static void +_katze_array_move_item (KatzeArray* array, + gpointer item, + gint position) +{ + array->items = g_list_remove (array->items, item); + array->items = g_list_insert (array->items, item, position); +} + static void _katze_array_clear (KatzeArray* array) { @@ -140,6 +155,28 @@ katze_array_class_init (KatzeArrayClass* class) G_TYPE_NONE, 1, G_TYPE_POINTER); + /** + * KatzeArray::move-item: + * @array: the object on which the signal is emitted + * @item: the item being moved + * @position: the new position of the item + * + * An item is moved to a new position. + * + * Since: 0.1.6 + **/ + signals[MOVE_ITEM] = g_signal_new ( + "move-item", + G_TYPE_FROM_CLASS (class), + (GSignalFlags)(G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION), + G_STRUCT_OFFSET (KatzeArrayClass, move_item), + 0, + NULL, + katze_cclosure_marshal_VOID__POINTER_INT, + G_TYPE_NONE, 2, + G_TYPE_POINTER, + G_TYPE_INT); + signals[CLEAR] = g_signal_new ( "clear", G_TYPE_FROM_CLASS (class), @@ -155,6 +192,7 @@ katze_array_class_init (KatzeArrayClass* class) class->add_item = _katze_array_add_item; class->remove_item = _katze_array_remove_item; + class->move_item = _katze_array_move_item; class->clear = _katze_array_clear; } @@ -371,6 +409,26 @@ katze_array_get_length (KatzeArray* array) return g_list_length (array->items); } +/** + * katze_array_move_item: + * @array: a #KatzeArray + * @item: the item being moved + * @position: the new position of the item + * + * Moves @item to the position @position. + * + * Since: 0.1.6 + **/ +void +katze_array_move_item (KatzeArray* array, + gpointer item, + gint position) +{ + g_return_if_fail (KATZE_IS_ARRAY (array)); + + g_signal_emit (array, signals[MOVE_ITEM], 0, item, position); +} + /** * katze_array_clear: * @array: a #KatzeArray diff --git a/katze/katze-array.h b/katze/katze-array.h index c99867d1..89bfea9c 100644 --- a/katze/katze-array.h +++ b/katze/katze-array.h @@ -68,6 +68,11 @@ katze_array_find_token (KatzeArray* array, guint katze_array_get_length (KatzeArray* array); +void +katze_array_move_item (KatzeArray* array, + gpointer item, + gint position); + void katze_array_clear (KatzeArray* array); diff --git a/katze/marshal.list b/katze/marshal.list new file mode 100644 index 00000000..ce752891 --- /dev/null +++ b/katze/marshal.list @@ -0,0 +1 @@ +VOID:POINTER,INT diff --git a/katze/wscript_build b/katze/wscript_build index b52eb015..27a24fc2 100644 --- a/katze/wscript_build +++ b/katze/wscript_build @@ -9,6 +9,7 @@ obj.name = 'katze' obj.target = 'katze' obj.includes = '. ../.' obj.find_sources_in_dirs ('.') +obj.add_marshal_file ('marshal.list', 'katze_cclosure_marshal') obj.uselib = 'M GMODULE LIBSOUP GTK LIBXML' obj.install_path = None