- g_signal_emit (simple, g_simple_action_signals[SIGNAL_ACTIVATE], 0, parameter);
+ {
+ /* If the user connected a signal handler then they are responsible
+ * for handling activation.
+ */
+ if (g_signal_has_handler_pending (action, g_simple_action_signals[SIGNAL_ACTIVATE], 0, TRUE))
+ g_signal_emit (action, g_simple_action_signals[SIGNAL_CHANGE_STATE], 0, parameter);
+
+ /* If not, do some reasonable defaults for stateful actions. */
+ else if (simple->state)
+ {
+ /* If we have no parameter and this is a boolean action, toggle. */
+ if (parameter == NULL && g_variant_is_of_type (simple->state, G_VARIANT_TYPE_BOOLEAN))
+ {
+ gboolean was_enabled = g_variant_get_boolean (simple->state);
+ g_simple_action_change_state (action, g_variant_new_boolean (!was_enabled));
+ }
+
+ /* else, if the parameter and state type are the same, do a change-state */
+ else if (g_variant_is_of_type (simple->state, g_variant_get_type (parameter)))
+ g_simple_action_change_state (action, parameter);
+ }
+ }