[gtksourceview/wip/encoding-get-all] Replace gtk_source_encoding_foreach() by get_all()
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtksourceview/wip/encoding-get-all] Replace gtk_source_encoding_foreach() by get_all()
- Date: Fri, 15 Aug 2014 15:34:03 +0000 (UTC)
commit fcb893cf097c9659a23a183933a9574a804680d5
Author: Sébastien Wilmet <swilmet gnome org>
Date: Fri Aug 15 17:26:38 2014 +0200
Replace gtk_source_encoding_foreach() by get_all()
The API is smaller, GtkSourceEncodingForeachFunc is not needed, and
having a GSList is more convenient in C than defining a callback. The
callback takes a user_data argument, so the needed local variables must
be packed in a struct, which is less convenient if those variables are
not already in the Private struct.
A GSList has been chosen, because
gtk_source_file_loader_set_candidate_encodings() takes also a GSList.
docs/reference/gtksourceview-3.0-sections.txt | 2 +-
gtksourceview/gtksourceencoding.c | 24 +++++++++++++-----------
gtksourceview/gtksourceencoding.h | 17 +----------------
3 files changed, 15 insertions(+), 28 deletions(-)
---
diff --git a/docs/reference/gtksourceview-3.0-sections.txt b/docs/reference/gtksourceview-3.0-sections.txt
index fe3c0b4..20c9bc2 100644
--- a/docs/reference/gtksourceview-3.0-sections.txt
+++ b/docs/reference/gtksourceview-3.0-sections.txt
@@ -221,7 +221,7 @@ gtk_source_encoding_get_from_charset
gtk_source_encoding_to_string
gtk_source_encoding_get_name
gtk_source_encoding_get_charset
-gtk_source_encoding_foreach
+gtk_source_encoding_get_all
gtk_source_encoding_copy
gtk_source_encoding_free
<SUBSECTION Standard>
diff --git a/gtksourceview/gtksourceencoding.c b/gtksourceview/gtksourceencoding.c
index ab4b15b..05227ad 100644
--- a/gtksourceview/gtksourceencoding.c
+++ b/gtksourceview/gtksourceencoding.c
@@ -342,26 +342,28 @@ gtk_source_encoding_get_from_charset (const gchar *charset)
}
/**
- * gtk_source_encoding_foreach:
- * @func: (scope call): the function to call for each encoding
- * @user_data: user data to pass to the function
+ * gtk_source_encoding_get_all:
*
- * Calls a function for each encoding.
+ * Gets all encodings.
*
+ * Returns: (transfer container) (element-type GtkSource.Encoding): a list of
+ * all #GtkSourceEncoding's. Free with g_slist_free().
* Since: 3.14
*/
-void
-gtk_source_encoding_foreach (GtkSourceEncodingForeachFunc func,
- gpointer user_data)
+GSList *
+gtk_source_encoding_get_all (void)
{
+ GSList *all = NULL;
gint i;
- func (&utf8_encoding, user_data);
-
- for (i = 0; i < GTK_SOURCE_ENCODING_LAST; i++)
+ for (i = GTK_SOURCE_ENCODING_LAST - 1; i >= 0; i--)
{
- func (&encodings[i], user_data);
+ all = g_slist_prepend (all, (gpointer) &encodings[i]);
}
+
+ all = g_slist_prepend (all, (gpointer) &utf8_encoding);
+
+ return all;
}
/**
diff --git a/gtksourceview/gtksourceencoding.h b/gtksourceview/gtksourceencoding.h
index fdd773a..19db205 100644
--- a/gtksourceview/gtksourceencoding.h
+++ b/gtksourceview/gtksourceencoding.h
@@ -31,20 +31,6 @@ G_BEGIN_DECLS
#define GTK_SOURCE_TYPE_ENCODING (gtk_source_encoding_get_type ())
-/**
- * GtkSourceEncodingForeachFunc:
- * @encoding: a #GtkSourceEncoding.
- * @userdata: user data.
- *
- * Specifies the type of function passed to gtk_source_encoding_foreach(). The
- * function is called with each encoding, together with the user data passed
- * to gtk_source_encoding_foreach().
- *
- * Since: 3.14
- */
-typedef void (*GtkSourceEncodingForeachFunc) (const GtkSourceEncoding *encoding,
- gpointer userdata);
-
GType gtk_source_encoding_get_type (void) G_GNUC_CONST;
const GtkSourceEncoding *gtk_source_encoding_get_from_charset (const gchar *charset);
@@ -57,8 +43,7 @@ const gchar *gtk_source_encoding_get_charset (const GtkSourceEncoding
*enc);
const GtkSourceEncoding *gtk_source_encoding_get_utf8 (void);
const GtkSourceEncoding *gtk_source_encoding_get_current (void);
-void gtk_source_encoding_foreach (GtkSourceEncodingForeachFunc func,
- gpointer user_data);
+GSList *gtk_source_encoding_get_all (void);
/* These should not be used, they are just to make python bindings happy */
GtkSourceEncoding *gtk_source_encoding_copy (const GtkSourceEncoding *enc);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]