[gtk/shortcuts-rebased-again: 75/171] shortcut: Add gtk_shortcut_set_mnemonic_activate()
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/shortcuts-rebased-again: 75/171] shortcut: Add gtk_shortcut_set_mnemonic_activate()
- Date: Mon, 24 Jun 2019 23:10:48 +0000 (UTC)
commit 635299fff12114482086c93d42e83c80b396c52d
Author: Benjamin Otte <otte redhat com>
Date: Thu Aug 16 05:18:01 2018 +0200
shortcut: Add gtk_shortcut_set_mnemonic_activate()
Makes the shortcut call gtk_widget_mnemonic_activate() upon activation.
gtk/gtkshortcut.c | 81 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
gtk/gtkshortcut.h | 5 ++++
2 files changed, 86 insertions(+)
---
diff --git a/gtk/gtkshortcut.c b/gtk/gtkshortcut.c
index d06966c694..c1224fa43d 100644
--- a/gtk/gtkshortcut.c
+++ b/gtk/gtkshortcut.c
@@ -59,6 +59,8 @@ struct _GtkShortcut
gpointer user_data;
GDestroyNotify destroy_notify;
GVariant *args;
+
+ guint mnemonic_activate : 1;
};
enum
@@ -66,6 +68,7 @@ enum
PROP_0,
PROP_ARGUMENTS,
PROP_CALLBACK,
+ PROP_MNEMONIC_ACTIVATE,
PROP_SIGNAL,
PROP_TRIGGER,
@@ -115,6 +118,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;
@@ -143,6 +150,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;
@@ -191,6 +202,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:
*
@@ -484,6 +507,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 */
@@ -580,6 +607,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 *
@@ -638,3 +671,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));
+}
+
diff --git a/gtk/gtkshortcut.h b/gtk/gtkshortcut.h
index 96bba17d78..09e8a82cef 100644
--- a/gtk/gtkshortcut.h
+++ b/gtk/gtkshortcut.h
@@ -64,6 +64,11 @@ void gtk_shortcut_set_callback (GtkShortcut
GtkShortcutFunc callback,
gpointer data,
GDestroyNotify destroy);
+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
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]