shortcut: Add gtk_shortcut_set_mnemonic_activate()

Makes the shortcut call gtk_widget_mnemonic_activate() upon activation.
This commit is contained in:
Benjamin Otte 2018-08-16 05:18:01 +02:00 committed by Matthias Clasen
parent ef40f22632
commit ab681b0e05
2 changed files with 86 additions and 0 deletions

View File

@ -60,6 +60,8 @@ struct _GtkShortcut
gpointer user_data;
GDestroyNotify destroy_notify;
GVariant *args;
guint mnemonic_activate : 1;
};
enum
@ -67,6 +69,7 @@ enum
PROP_0,
PROP_ARGUMENTS,
PROP_CALLBACK,
PROP_MNEMONIC_ACTIVATE,
PROP_SIGNAL,
PROP_ACTION,
PROP_TRIGGER,
@ -118,6 +121,10 @@ gtk_shortcut_get_property (GObject *object,
g_value_set_boolean (value, self->callback != NULL);
break;
case PROP_MNEMONIC_ACTIVATE:
g_value_set_boolean (value, self->mnemonic_activate);
break;
case PROP_SIGNAL:
g_value_set_string (value, self->signal);
break;
@ -150,6 +157,10 @@ gtk_shortcut_set_property (GObject *object,
gtk_shortcut_set_arguments (self, g_value_get_variant (value));
break;
case PROP_MNEMONIC_ACTIVATE:
gtk_shortcut_set_mnemonic_activate (self, g_value_get_boolean (value));
break;
case PROP_SIGNAL:
gtk_shortcut_set_signal (self, g_value_get_string (value));
break;
@ -202,6 +213,18 @@ gtk_shortcut_class_init (GtkShortcutClass *klass)
FALSE,
G_PARAM_READABLE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS);
/**
* GtkShortcut:mnemonic-activate:
*
* %TRUE if this shortcut should call gtk_widget_mnemonic_activate().
*/
properties[PROP_MNEMONIC_ACTIVATE] =
g_param_spec_boolean ("mnemonic-activate",
P_("Mnemonic activate"),
P_("Call gtk_widget_mnemonic_activate()"),
FALSE,
G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS);
/**
* GtkShortcut:signal:
*
@ -558,6 +581,10 @@ gtk_shortcut_activate (GtkShortcut *self,
return handled;
}
else if (self->mnemonic_activate)
{
return gtk_widget_mnemonic_activate (widget, FALSE);
}
else
{
/* shortcut is a dud */
@ -660,6 +687,12 @@ gtk_shortcut_clear_activation (GtkShortcut *self)
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_CALLBACK]);
}
if (self->mnemonic_activate)
{
self->mnemonic_activate = FALSE;
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_MNEMONIC_ACTIVATE]);
}
}
const char *
@ -745,3 +778,51 @@ gtk_shortcut_set_callback (GtkShortcut *self,
g_object_thaw_notify (G_OBJECT (self));
}
/**
* gtk_shortcut_get_mnemonic_activate:
* @self: a #GtkShortcut
*
* Checks if this shortcut calls gtk_widget_mnemonic_activate() upon
* activation.
*
* Returns: %TRUE if it does.
**/
gboolean
gtk_shortcut_get_mnemonic_activate (GtkShortcut *self)
{
g_return_val_if_fail (GTK_IS_SHORTCUT (self), FALSE);
return self->mnemonic_activate;
}
/**
* gtk_shortcut_set_mnemonic_activate:
* @self: a #GtkShortcut
* @mnemonic_activate: %TRUE to call gtk_widget_mnemonic_activate()
* upon activation
*
* If @mnemonic_activate is %TRUE, this shortcut will call
* gtk_widget_mnemonic_activate() whenever it is activated. All
* previous activations will be unset.
*
* If @mnemonic_activate is %FALSE, it will stop this shortcut from
* calling gtk_widget_mnemonic_activate() if it did so before.
**/
void
gtk_shortcut_set_mnemonic_activate (GtkShortcut *self,
gboolean mnemonic_activate)
{
g_return_if_fail (GTK_IS_SHORTCUT (self));
if (self->mnemonic_activate == mnemonic_activate)
return;
g_object_freeze_notify (G_OBJECT (self));
gtk_shortcut_clear_activation (self);
self->mnemonic_activate = mnemonic_activate;
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_MNEMONIC_ACTIVATE]);
g_object_thaw_notify (G_OBJECT (self));
}

View File

@ -69,6 +69,11 @@ gboolean gtk_shortcut_has_action (GtkShortcut
GDK_AVAILABLE_IN_ALL
void gtk_shortcut_set_action (GtkShortcut *self,
const char *action);
GDK_AVAILABLE_IN_ALL
gboolean gtk_shortcut_get_mnemonic_activate (GtkShortcut *self);
GDK_AVAILABLE_IN_ALL
void gtk_shortcut_set_mnemonic_activate (GtkShortcut *self,
gboolean mnemonic_activate);
G_END_DECLS