[gtksourceview/wip/loader-saver] gtk_source_encoding_foreach() instead of get_from_index()
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtksourceview/wip/loader-saver] gtk_source_encoding_foreach() instead of get_from_index()
- Date: Mon, 7 Jul 2014 17:23:54 +0000 (UTC)
commit 1314b4a443152880e0d75b0928bca184e2d6d3f4
Author: Sébastien Wilmet <swilmet gnome org>
Date: Mon Jul 7 19:23:10 2014 +0200
gtk_source_encoding_foreach() instead of get_from_index()
docs/reference/gtksourceview-3.0-sections.txt | 3 +-
gtksourceview/gtksourceencoding.c | 26 +++++++++++-------------
gtksourceview/gtksourceencoding.h | 18 ++++++++++++++++-
3 files changed, 31 insertions(+), 16 deletions(-)
---
diff --git a/docs/reference/gtksourceview-3.0-sections.txt b/docs/reference/gtksourceview-3.0-sections.txt
index c016477..d188cd6 100644
--- a/docs/reference/gtksourceview-3.0-sections.txt
+++ b/docs/reference/gtksourceview-3.0-sections.txt
@@ -213,14 +213,15 @@ gtk_source_completion_words_get_type
<FILE>encoding</FILE>
<TITLE>GtkSourceEncoding</TITLE>
GtkSourceEncoding
+GtkSourceEncodingForeachFunc
<SUBSECTION>
gtk_source_encoding_get_utf8
gtk_source_encoding_get_current
gtk_source_encoding_get_from_charset
-gtk_source_encoding_get_from_index
gtk_source_encoding_to_string
gtk_source_encoding_get_name
gtk_source_encoding_get_charset
+gtk_source_encoding_foreach
gtk_source_encoding_copy
gtk_source_encoding_free
<SUBSECTION Standard>
diff --git a/gtksourceview/gtksourceencoding.c b/gtksourceview/gtksourceencoding.c
index c84c81a..27d4fe0 100644
--- a/gtksourceview/gtksourceencoding.c
+++ b/gtksourceview/gtksourceencoding.c
@@ -30,8 +30,8 @@
* @See_also: #GtkSourceFileSaver, #GtkSourceFileLoader
*
* The #GtkSourceEncoding boxed type represents a character encoding. It is used
- * for example by the #GtkSourceFileSaver and #GtkSourceFileLoader. Note that
- * the text in GTK+ widgets is always encoded in UTF-8.
+ * for example by #GtkSourceFile. Note that the text in GTK+ widgets is always
+ * encoded in UTF-8.
*/
struct _GtkSourceEncoding
@@ -340,26 +340,24 @@ gtk_source_encoding_get_from_charset (const gchar *charset)
}
/**
- * gtk_source_encoding_get_from_index:
- * @index: the index.
+ * gtk_source_encoding_foreach:
+ * @func: (scope call): the function to call for each encoding
+ * @user_data: user data to pass to the function
*
- * Gets the #GtkSourceEncoding located at @index. The first valid index is 0.
- * This function can be used in a loop that stops when %NULL is returned.
+ * Calls a function for each encoding.
*
- * Returns: the #GtkSourceEncoding at @index, or %NULL.
* Since: 3.14
*/
-const GtkSourceEncoding *
-gtk_source_encoding_get_from_index (gint index)
+void
+gtk_source_encoding_foreach (GtkSourceEncodingForeachFunc func,
+ gpointer user_data)
{
- g_return_val_if_fail (index >= 0, NULL);
+ gint i;
- if (index >= GTK_SOURCE_ENCODING_LAST)
+ for (i = 0; i < GTK_SOURCE_ENCODING_LAST; i++)
{
- return NULL;
+ func (&encodings[i], user_data);
}
-
- return &encodings[index];
}
/**
diff --git a/gtksourceview/gtksourceencoding.h b/gtksourceview/gtksourceencoding.h
index 545806b..260dfbb 100644
--- a/gtksourceview/gtksourceencoding.h
+++ b/gtksourceview/gtksourceencoding.h
@@ -31,10 +31,23 @@ 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);
-const GtkSourceEncoding *gtk_source_encoding_get_from_index (gint index);
gchar *gtk_source_encoding_to_string (const GtkSourceEncoding *enc);
@@ -44,6 +57,9 @@ 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);
+
/* These should not be used, they are just to make python bindings happy */
GtkSourceEncoding *gtk_source_encoding_copy (const GtkSourceEncoding *enc);
void gtk_source_encoding_free (GtkSourceEncoding *enc);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]