[gspell/wip/buffer: 1/3] Add gspell_text_buffer_set/get_spell_checker() functions



commit 8273f30b24826fc723c39db3a6e04b62160d056a
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Mon Dec 28 18:01:40 2015 +0100

    Add gspell_text_buffer_set/get_spell_checker() functions

 docs/reference/gspell-1.0-sections.txt |    7 +++
 docs/reference/gspell-docs.xml         |    5 ++
 gspell/Makefile.am                     |    6 ++-
 gspell/gspell-text-buffer.c            |   86 ++++++++++++++++++++++++++++++++
 gspell/gspell-text-buffer.h            |   37 ++++++++++++++
 gspell/gspell.h                        |    1 +
 po/POTFILES.in                         |    1 +
 7 files changed, 141 insertions(+), 2 deletions(-)
---
diff --git a/docs/reference/gspell-1.0-sections.txt b/docs/reference/gspell-1.0-sections.txt
index 102f85a..78fc938 100644
--- a/docs/reference/gspell-1.0-sections.txt
+++ b/docs/reference/gspell-1.0-sections.txt
@@ -108,3 +108,10 @@ gspell_navigator_gtv_new
 GSPELL_TYPE_NAVIGATOR_GTV
 GspellNavigatorGtvClass
 </SECTION>
+
+<SECTION>
+<FILE>text-buffer</FILE>
+<TITLE>GtkTextBuffer support</TITLE>
+gspell_text_buffer_set_spell_checker
+gspell_text_buffer_get_spell_checker
+</SECTION>
diff --git a/docs/reference/gspell-docs.xml b/docs/reference/gspell-docs.xml
index ab3d5f6..09d5d24 100644
--- a/docs/reference/gspell-docs.xml
+++ b/docs/reference/gspell-docs.xml
@@ -22,6 +22,11 @@
     </chapter>
 
     <chapter>
+      <title>Buffer Support</title>
+      <xi:include href="xml/text-buffer.xml"/>
+    </chapter>
+
+    <chapter>
       <title>Inline Checkers</title>
       <xi:include href="xml/inline-checker-gtv.xml"/>
     </chapter>
diff --git a/gspell/Makefile.am b/gspell/Makefile.am
index 0a4dd27..b7b9ba6 100644
--- a/gspell/Makefile.am
+++ b/gspell/Makefile.am
@@ -25,7 +25,8 @@ gspell_public_headers =                               \
        gspell-language-chooser-button.h        \
        gspell-language-chooser-dialog.h        \
        gspell-navigator.h                      \
-       gspell-navigator-gtv.h
+       gspell-navigator-gtv.h                  \
+       gspell-text-buffer.h
 
 gspell_public_c_files =                                \
        gspell-checker.c                        \
@@ -36,7 +37,8 @@ gspell_public_c_files =                               \
        gspell-language-chooser-button.c        \
        gspell-language-chooser-dialog.c        \
        gspell-navigator.c                      \
-       gspell-navigator-gtv.c
+       gspell-navigator-gtv.c                  \
+       gspell-text-buffer.c
 
 gspell_private_headers =       \
        gconstructor.h          \
diff --git a/gspell/gspell-text-buffer.c b/gspell/gspell-text-buffer.c
new file mode 100644
index 0000000..afe9412
--- /dev/null
+++ b/gspell/gspell-text-buffer.c
@@ -0,0 +1,86 @@
+/*
+ * This file is part of gspell, a spell-checking library.
+ *
+ * Copyright 2015 - Sébastien Wilmet
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "gspell-text-buffer.h"
+
+/**
+ * SECTION:text-buffer
+ * @Title: GtkTextBuffer support
+ * @See_also: #GspellChecker
+ *
+ * Spell checking support to a #GtkTextBuffer.
+ */
+
+#define SPELL_CHECKER_KEY "gspell-text-buffer-spell-checker-key"
+
+/**
+ * gspell_text_buffer_set_spell_checker:
+ * @buffer: a #GtkTextBuffer.
+ * @checker: (nullable): a #GspellChecker, or %NULL to unset the spell checker.
+ *
+ * Associates a spell checker to a #GtkTextBuffer.
+ */
+void
+gspell_text_buffer_set_spell_checker (GtkTextBuffer *buffer,
+                                     GspellChecker *checker)
+{
+       g_return_if_fail (GTK_IS_TEXT_BUFFER (buffer));
+       g_return_if_fail (checker == NULL || GSPELL_IS_CHECKER (checker));
+
+       if (checker != NULL)
+       {
+               g_object_set_data_full (G_OBJECT (buffer),
+                                       SPELL_CHECKER_KEY,
+                                       g_object_ref (checker),
+                                       g_object_unref);
+       }
+       else
+       {
+               g_object_set_data (G_OBJECT (buffer),
+                                  SPELL_CHECKER_KEY,
+                                  NULL);
+       }
+}
+
+/**
+ * gspell_text_buffer_get_spell_checker:
+ * @buffer: a #GtkTextBuffer.
+ *
+ * Returns: (nullable) (transfer none): the associated #GspellChecker if one has
+ * been set, or %NULL.
+ */
+GspellChecker *
+gspell_text_buffer_get_spell_checker (GtkTextBuffer *buffer)
+{
+       gpointer data;
+
+       g_return_val_if_fail (GTK_IS_TEXT_BUFFER (buffer), NULL);
+
+       data = g_object_get_data (G_OBJECT (buffer), SPELL_CHECKER_KEY);
+
+       if (data == NULL)
+       {
+               return NULL;
+       }
+
+       g_return_val_if_fail (GSPELL_IS_CHECKER (data), NULL);
+       return data;
+}
+
+/* ex:set ts=8 noet: */
diff --git a/gspell/gspell-text-buffer.h b/gspell/gspell-text-buffer.h
new file mode 100644
index 0000000..7d72ad8
--- /dev/null
+++ b/gspell/gspell-text-buffer.h
@@ -0,0 +1,37 @@
+/*
+ * This file is part of gspell, a spell-checking library.
+ *
+ * Copyright 2015 - Sébastien Wilmet
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this library; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __GSPELL_TEXT_BUFFER_H__
+#define __GSPELL_TEXT_BUFFER_H__
+
+#if !defined (__GSPELL_H_INSIDE__) && !defined (GSPELL_COMPILATION)
+#error "Only <gspell/gspell.h> can be included directly."
+#endif
+
+#include <gspell/gspell-checker.h>
+#include <gtk/gtk.h>
+
+void           gspell_text_buffer_set_spell_checker    (GtkTextBuffer *buffer,
+                                                        GspellChecker *checker);
+
+GspellChecker *        gspell_text_buffer_get_spell_checker    (GtkTextBuffer *buffer);
+
+#endif /* __GSPELL_TEXT_BUFFER_H__ */
+
+/* ex:set ts=8 noet: */
diff --git a/gspell/gspell.h b/gspell/gspell.h
index dd78ad0..b77a7ee 100644
--- a/gspell/gspell.h
+++ b/gspell/gspell.h
@@ -31,6 +31,7 @@
 #include <gspell/gspell-language-chooser-dialog.h>
 #include <gspell/gspell-navigator.h>
 #include <gspell/gspell-navigator-gtv.h>
+#include <gspell/gspell-text-buffer.h>
 
 #undef __GSPELL_H_INSIDE__
 
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 63dc096..8b89470 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -9,6 +9,7 @@ gspell/gspell-language-chooser-dialog.c
 gspell/gspell-navigator.c
 gspell/gspell-navigator-gtv.c
 gspell/gspell-osx.c
+gspell/gspell-text-buffer.c
 gspell/gspell-utils.c
 gspell/resources/checker-dialog.ui
 gspell/resources/language-dialog.ui


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]