Merge branch 'shortcut-action-parse' into 'master'

Shortcut action parse

See merge request GNOME/gtk!1625
This commit is contained in:
Matthias Clasen 2020-04-04 03:12:10 +00:00
commit 842af79e97
3 changed files with 51 additions and 3 deletions

View File

@ -44,6 +44,10 @@
* - #GtkNamedAction: a shortcut action that calls gtk_widget_activate_action()
* - #GtkGActionAction: a shortcut action that activates a given #GAction
* - #GtkNothingAction: a shortcut action that does nothing
*
* # GtkShortcutAction as GtkBuildable
*
* GtkShortcut
*/
#include "config.h"
@ -180,9 +184,7 @@ string_is_function (const char *string,
}
GtkShortcutAction *
gtk_shortcut_action_parse_builder (GtkBuilder *builder,
const char *string,
GError **error)
gtk_shortcut_action_parse_string (const char *string)
{
GtkShortcutAction *result;
char *arg;
@ -204,6 +206,22 @@ gtk_shortcut_action_parse_builder (GtkBuilder *builder,
result = gtk_signal_action_new (arg);
g_free (arg);
}
else
return NULL;
return result;
}
GtkShortcutAction *
gtk_shortcut_action_parse_builder (GtkBuilder *builder,
const char *string,
GError **error)
{
GtkShortcutAction *result;
result = gtk_shortcut_action_parse_string (string);
if (!result)
{
g_set_error (error,
GTK_BUILDER_ERROR, GTK_BUILDER_ERROR_INVALID_VALUE,

View File

@ -60,6 +60,9 @@ GDK_DECLARE_INTERNAL_TYPE (GtkShortcutAction, gtk_shortcut_action, GTK, SHORTCUT
GDK_AVAILABLE_IN_ALL
char * gtk_shortcut_action_to_string (GtkShortcutAction *self);
GDK_AVAILABLE_IN_ALL
GtkShortcutAction * gtk_shortcut_action_parse_string (const char * string);
GDK_AVAILABLE_IN_ALL
void gtk_shortcut_action_print (GtkShortcutAction *self,
GString *string);

View File

@ -441,6 +441,32 @@ test_action_activate (void)
g_object_unref (widget);
}
static void
test_action_parse (void)
{
GtkShortcutAction *action;
action = gtk_shortcut_action_parse_string ("nothing");
g_assert_true (GTK_IS_NOTHING_ACTION (action));
g_object_unref (action);
action = gtk_shortcut_action_parse_string ("activate");
g_assert_true (GTK_IS_ACTIVATE_ACTION (action));
g_object_unref (action);
action = gtk_shortcut_action_parse_string ("mnemonic-activate");
g_assert_true (GTK_IS_MNEMONIC_ACTION (action));
g_object_unref (action);
action = gtk_shortcut_action_parse_string ("action(win.dark)");
g_assert_true (GTK_IS_NAMED_ACTION (action));
g_object_unref (action);
action = gtk_shortcut_action_parse_string ("signal(frob)");
g_assert_true (GTK_IS_SIGNAL_ACTION (action));
g_object_unref (action);
}
int
main (int argc, char *argv[])
{
@ -456,6 +482,7 @@ main (int argc, char *argv[])
g_test_add_func ("/shortcuts/trigger/trigger", test_trigger_trigger);
g_test_add_func ("/shortcuts/action/basic", test_action_basic);
g_test_add_func ("/shortcuts/action/activate", test_action_activate);
g_test_add_func ("/shortcuts/action/parse", test_action_parse);
return g_test_run ();
}