static void
activate_action (GtkWidget   *widget,
                 const gchar *prefix,
                 const gchar *action_name,
                 GVariant    *parameter)
{
    GApplication *app;
    GtkWidget *toplevel;
    GActionGroup *group = NULL;

    g_return_if_fail (GTK_IS_WIDGET (widget));
    g_return_if_fail (prefix);
    g_return_if_fail (action_name);

    g_print ("activate!\n");

    app = g_application_get_default ();
    toplevel = gtk_widget_get_toplevel (widget);

    while ((group == NULL) && (widget != NULL))
    {
        group = gtk_widget_get_action_group (widget, prefix);
        widget = gtk_widget_get_parent (widget);
    }

    if (!group && g_str_equal (prefix, "win") && G_IS_ACTION_GROUP (toplevel))
        group = G_ACTION_GROUP (toplevel);

    if (!group && g_str_equal (prefix, "app") && G_IS_ACTION_GROUP (app))
        group = G_ACTION_GROUP (app);

    if (group)
    {
        if (g_action_group_has_action (group, action_name))
        {
            g_print ("Activating %s.%s\n", prefix, action_name);
            g_action_group_activate_action (group, action_name, parameter);
            return;
        }
    }

    if (parameter && g_variant_is_floating (parameter))
    {
        parameter = g_variant_ref_sink (parameter);
        g_variant_unref (parameter);
    }

    g_warning ("Failed to resolve action %s.%s", prefix, action_name);
}
Example #2
0
static void
ide_editor_frame_add_search_actions (IdeEditorFrame *self,
                                     GActionGroup   *group)
{
  GPropertyAction *prop_action;
  GtkSourceSearchContext *search_context;
  GtkSourceSearchSettings *search_settings;

  g_assert (IDE_IS_EDITOR_FRAME (self));
  g_assert (G_IS_ACTION_GROUP (group));

  search_context = ide_source_view_get_search_context (self->source_view);
  search_settings = gtk_source_search_context_get_settings (search_context);

  prop_action = g_property_action_new ("change-case-sensitive", search_settings, "case-sensitive");
  g_action_map_add_action (G_ACTION_MAP (group), G_ACTION (prop_action));
  g_object_unref (prop_action);

  prop_action = g_property_action_new ("change-word-boundaries", search_settings, "at-word-boundaries");
  g_action_map_add_action (G_ACTION_MAP (group), G_ACTION (prop_action));
  g_object_unref (prop_action);

  prop_action = g_property_action_new ("change-regex-enabled", search_settings, "regex-enabled");
  g_action_map_add_action (G_ACTION_MAP (group), G_ACTION (prop_action));
  g_object_unref (prop_action);

  prop_action = g_property_action_new ("change-wrap-around", search_settings, "wrap-around");
  g_action_map_add_action (G_ACTION_MAP (group), G_ACTION (prop_action));
  g_object_unref (prop_action);
}
static gboolean
egg_empty_state_action (GtkWidget   *widget,
                        const gchar *prefix,
                        const gchar *action_name,
                        GVariant    *parameter)
{
  GtkWidget *toplevel;
  GApplication *app;
  GActionGroup *group = NULL;

  g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE);
  g_return_val_if_fail (prefix, FALSE);
  g_return_val_if_fail (action_name, FALSE);

  app = g_application_get_default ();
  toplevel = gtk_widget_get_toplevel (widget);

  while ((group == NULL) && (widget != NULL))
    {
      group = gtk_widget_get_action_group (widget, prefix);
      widget = gtk_widget_get_parent (widget);
    }

  if (!group && g_str_equal (prefix, "win") && G_IS_ACTION_GROUP (toplevel))
    group = G_ACTION_GROUP (toplevel);

  if (!group && g_str_equal (prefix, "app") && G_IS_ACTION_GROUP (app))
    group = G_ACTION_GROUP (app);

  if (group && g_action_group_has_action (group, action_name))
    {
      g_action_group_activate_action (group, action_name, parameter);
      return TRUE;
    }

  if (parameter && g_variant_is_floating (parameter))
    {
      parameter = g_variant_ref_sink (parameter);
      g_variant_unref (parameter);
    }

  g_warning ("Failed to locate action %s.%s", prefix, action_name);

  return FALSE;
}
static void
action_set_enabled (GActionGroup *group, const gchar *action_name, bool value)
{
    g_assert (G_IS_ACTION_GROUP (group));
    g_assert (G_IS_ACTION_MAP (group));

    GAction *action = g_action_map_lookup_action (G_ACTION_MAP (group), action_name);

    if (action) {
        g_simple_action_set_enabled (G_SIMPLE_ACTION (action), value);
    }
}
static void
action_set_active_bool (GActionGroup *group, const gchar *action_name, bool value)
{
    g_assert (G_IS_ACTION_GROUP (group));
    g_assert (G_IS_ACTION_MAP (group));

    GAction *action = g_action_map_lookup_action (G_ACTION_MAP (group), action_name);

    if (action) {
        g_simple_action_set_state (G_SIMPLE_ACTION (action), g_variant_new_boolean (value));
    }
}
Example #6
0
static gboolean
ide_run_manager_has_action (GActionGroup *group,
                            const gchar  *action_name)
{
  g_assert (G_IS_ACTION_GROUP (group));
  g_assert (action_name != NULL);

  for (guint i = 0; action_names[i]; i++)
    {
      if (g_strcmp0 (action_names[i], action_name) == 0)
        return TRUE;
    }

  return FALSE;
}
static void
action_set (GActionGroup *group,
            const gchar  *action_name,
            const gchar  *first_param,
            ...)
{
  GAction *action;
  va_list args;

  g_assert (G_IS_ACTION_GROUP (group));
  g_assert (G_IS_ACTION_MAP (group));

  action = g_action_map_lookup_action (G_ACTION_MAP (group), action_name);
  g_assert (G_IS_SIMPLE_ACTION (action));

  va_start (args, first_param);
  g_object_set_valist (G_OBJECT (action), first_param, args);
  va_end (args);
}