state: automatically remove unused states

When there is no further keys with a state as the target state, remove
the state (and all transitions that used this state as a target)
This commit is contained in:
Øyvind Kolås 2010-07-06 13:34:22 +01:00
parent 140f76abf4
commit 6d1f697bc4
2 changed files with 36 additions and 10 deletions

View File

@ -276,22 +276,27 @@ clutter_state_remove_key_internal (ClutterState *this,
if (target_state)
{
GList *k;
for (k = target_state->keys; k != NULL; k = k?k->next:NULL)
again:
for (k = target_state->keys; k != NULL; k = k->next)
{
ClutterStateKey *key = k->data;
if ((object == NULL || (object == key->object)) &&
(source_state == NULL ||
(source_state == key->source_state)) &&
(property_name == NULL ||
((property_name == key->property_name))))
if ( (object == NULL || (object == key->object))
&& (source_state == NULL || (source_state == key->source_state))
&& (property_name == NULL || ((property_name == key->property_name))))
{
k = target_state->keys =
g_list_remove (target_state->keys, key);
target_state->keys = g_list_remove (target_state->keys, key);
if (target_state->keys == NULL)
{
/* no more keys, so remove this state */
clutter_state_remove_key (this, s->data, NULL, NULL, NULL);
g_hash_table_remove (this->priv->states, s->data);
}
key->is_inert = is_inert;
clutter_state_key_free (key);
goto again;
}
}
}
@ -911,7 +916,6 @@ GList *
clutter_state_get_states (ClutterState *state)
{
g_return_val_if_fail (CLUTTER_IS_STATE (state), NULL);
return g_hash_table_get_keys (state->priv->states);
}

View File

@ -60,5 +60,27 @@ test_state_base (TestConformSimpleFixture *fixture G_GNUC_UNUSED,
g_list_free (keys);
clutter_state_set (CLUTTER_STATE (state), "base", "clicked", state, "state", CLUTTER_LINEAR, "foo", NULL);
keys = clutter_state_get_keys (CLUTTER_STATE (state), "base", "clicked",
NULL, NULL);
g_assert (keys != NULL);
g_assert_cmpint (g_list_length (keys), ==, 2);
g_list_free (keys);
keys = clutter_state_get_keys (CLUTTER_STATE (state), NULL, NULL,
NULL, NULL);
states = clutter_state_get_states (CLUTTER_STATE (state));
g_assert_cmpint (g_list_length (states), ==, 2);
g_list_free (states);
clutter_state_remove_key (CLUTTER_STATE (state), NULL, "clicked", NULL, NULL);
states = clutter_state_get_states (CLUTTER_STATE (state));
g_assert_cmpint (g_list_length (states), ==, 1);
g_list_free (states);
g_object_unref (script);
}