summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2020-03-31 00:39:37 +0000
committerMatthias Clasen <mclasen@redhat.com>2020-03-31 00:39:37 +0000
commitf3e826f4d6812e74766fcd3bea62103e11d8996b (patch)
tree1d2a5a6d5b0d6f21fe9d461ac6f00084303f0c30
parent5bf030413b3eed95508b482599948314a27287d9 (diff)
parent15eb3bbbf12d94d107483eb71acbf67352317c11 (diff)
downloadgtk+-f3e826f4d6812e74766fcd3bea62103e11d8996b.tar.gz
Merge branch 'matthiasc/for-master' into 'master'
Matthiasc/for master See merge request GNOME/gtk!1589
-rw-r--r--gtk/gtkbuilder.c48
-rw-r--r--gtk/gtkshortcutcontroller.c24
-rw-r--r--testsuite/gtk/builder.c30
3 files changed, 78 insertions, 24 deletions
diff --git a/gtk/gtkbuilder.c b/gtk/gtkbuilder.c
index c444e15036..a4351bade1 100644
--- a/gtk/gtkbuilder.c
+++ b/gtk/gtkbuilder.c
@@ -531,6 +531,8 @@ gtk_builder_get_parameters (GtkBuilder *builder,
(G_PARAM_SPEC_VALUE_TYPE (prop->pspec) != GDK_TYPE_PIXBUF) &&
(G_PARAM_SPEC_VALUE_TYPE (prop->pspec) != GDK_TYPE_TEXTURE) &&
(G_PARAM_SPEC_VALUE_TYPE (prop->pspec) != GDK_TYPE_PAINTABLE) &&
+ (G_PARAM_SPEC_VALUE_TYPE (prop->pspec) != GTK_TYPE_SHORTCUT_TRIGGER) &&
+ (G_PARAM_SPEC_VALUE_TYPE (prop->pspec) != GTK_TYPE_SHORTCUT_ACTION) &&
(G_PARAM_SPEC_VALUE_TYPE (prop->pspec) != G_TYPE_FILE))
{
GObject *object = g_hash_table_lookup (priv->objects,
@@ -2097,29 +2099,6 @@ gtk_builder_value_from_string_type (GtkBuilder *builder,
ret = FALSE;
}
}
- else if (G_VALUE_HOLDS (value, GTK_TYPE_SHORTCUT_TRIGGER))
- {
- GtkShortcutTrigger *trigger = gtk_shortcut_trigger_parse_string (string);
-
- if (trigger)
- g_value_take_object (value, trigger);
- else
- {
- g_set_error (error,
- GTK_BUILDER_ERROR,
- GTK_BUILDER_ERROR_INVALID_VALUE,
- "Could not parse shortcut trigger '%s'",
- string);
- ret = FALSE;
- }
- }
- else if (G_VALUE_HOLDS (value, GTK_TYPE_SHORTCUT_ACTION))
- {
- GtkShortcutAction *action = gtk_shortcut_action_parse_builder (builder, string, error);
-
- /* Works for success and failure (NULL) case */
- g_value_take_object (value, action);
- }
else if (G_VALUE_HOLDS (value, G_TYPE_STRV))
{
gchar **vector = g_strsplit (string, "\n", 0);
@@ -2237,6 +2216,29 @@ gtk_builder_value_from_string_type (GtkBuilder *builder,
ret = TRUE;
}
+ else if (G_VALUE_HOLDS (value, GTK_TYPE_SHORTCUT_TRIGGER))
+ {
+ GtkShortcutTrigger *trigger = gtk_shortcut_trigger_parse_string (string);
+
+ if (trigger)
+ g_value_take_object (value, trigger);
+ else
+ {
+ g_set_error (error,
+ GTK_BUILDER_ERROR,
+ GTK_BUILDER_ERROR_INVALID_VALUE,
+ "Could not parse shortcut trigger '%s'",
+ string);
+ ret = FALSE;
+ }
+ }
+ else if (G_VALUE_HOLDS (value, GTK_TYPE_SHORTCUT_ACTION))
+ {
+ GtkShortcutAction *action = gtk_shortcut_action_parse_builder (builder, string, error);
+
+ /* Works for success and failure (NULL) case */
+ g_value_take_object (value, action);
+ }
else
{
GObject *object = g_hash_table_lookup (priv->objects, string);
diff --git a/gtk/gtkshortcutcontroller.c b/gtk/gtkshortcutcontroller.c
index 8123d796e6..d7534001fe 100644
--- a/gtk/gtkshortcutcontroller.c
+++ b/gtk/gtkshortcutcontroller.c
@@ -36,6 +36,28 @@
*
* #GtkShortcutController implements #GListModel for querying the shortcuts that
* have been added to it.
+ *
+ * # GtkShortcutController as a GtkBuildable
+ *
+ * GtkShortcutControllers can be creates in ui files to set up shortcuts
+ * in the same place as the widgets.
+ *
+ * An example of a UI definition fragment with GtkShortcutController:
+ * |[
+ * <object class='GtkButton'>
+ * <child>
+ * <object class='GtkShortcutController'>
+ * <property name='scope'>managed</property>
+ * <child>
+ * <object class='GtkShortcut'>
+ * <property name='trigger'>&lt;Control&gt;k</property>
+ * <property name='action'>activate</property>
+ * </object>
+ * </child>
+ * </object>
+ * </child>
+ * </object>
+ * ]|
**/
#include "config.h"
@@ -127,7 +149,7 @@ gtk_shortcut_controller_buildable_add_child (GtkBuildable *buildable,
}
if (GTK_IS_SHORTCUT (child))
{
- gtk_shortcut_controller_add_shortcut (GTK_SHORTCUT_CONTROLLER (buildable), GTK_SHORTCUT (child));
+ gtk_shortcut_controller_add_shortcut (GTK_SHORTCUT_CONTROLLER (buildable), g_object_ref (GTK_SHORTCUT (child)));
}
else
{
diff --git a/testsuite/gtk/builder.c b/testsuite/gtk/builder.c
index c7178d476d..e2c2fcf992 100644
--- a/testsuite/gtk/builder.c
+++ b/testsuite/gtk/builder.c
@@ -2418,6 +2418,35 @@ test_file_filter (void)
g_object_unref (builder);
}
+static void
+test_shortcuts (void)
+{
+ GtkBuilder *builder;
+ GObject *obj;
+
+ const char buffer[] =
+ "<interface>"
+ " <object class='GtkBox' id='box'>"
+ " <child>"
+ " <object class='GtkShortcutController' id='controller'>"
+ " <property name='scope'>managed</property>"
+ " <child>"
+ " <object class='GtkShortcut'>"
+ " <property name='trigger'>&lt;Control&gt;k</property>"
+ " <property name='action'>activate</property>"
+ " </object>"
+ " </child>"
+ " </object>"
+ " </child>"
+ " </object>"
+ "</interface>";
+
+ builder = builder_new_from_string (buffer, -1, NULL);
+ obj = gtk_builder_get_object (builder, "controller");
+ g_assert (GTK_IS_SHORTCUT_CONTROLLER (obj));
+ g_object_unref (builder);
+}
+
int
main (int argc, char **argv)
{
@@ -2462,6 +2491,7 @@ main (int argc, char **argv)
g_test_add_func ("/Builder/Property Bindings", test_property_bindings);
g_test_add_func ("/Builder/anaconda-signal", test_anaconda_signal);
g_test_add_func ("/Builder/FileFilter", test_file_filter);
+ g_test_add_func ("/Builder/Shortcuts", test_shortcuts);
return g_test_run();
}