[gspell/wip/basic-setup-func] text-view: add basic_setup() function



commit 8b9d1a3ad3f896024f87a1661d4b95cb3a064e02
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Mon Aug 8 13:49:38 2016 +0200

    text-view: add basic_setup() function
    
    To be able to enable spell checking in two lines, for simple use cases.

 docs/reference/gspell-1.0-sections.txt |    1 +
 gspell/gspell-text-view.c              |   62 ++++++++++++++++++++++++++++++++
 gspell/gspell-text-view.h              |    2 +
 3 files changed, 65 insertions(+), 0 deletions(-)
---
diff --git a/docs/reference/gspell-1.0-sections.txt b/docs/reference/gspell-1.0-sections.txt
index 431ea46..e21091d 100644
--- a/docs/reference/gspell-1.0-sections.txt
+++ b/docs/reference/gspell-1.0-sections.txt
@@ -57,6 +57,7 @@ GSPELL_TYPE_TEXT_BUFFER
 <TITLE>GspellTextView</TITLE>
 GspellTextView
 gspell_text_view_get_from_gtk_text_view
+gspell_text_view_basic_setup
 gspell_text_view_get_view
 gspell_text_view_get_inline_spell_checking
 gspell_text_view_set_inline_spell_checking
diff --git a/gspell/gspell-text-view.c b/gspell/gspell-text-view.c
index 4f45cea..3488c5e 100644
--- a/gspell/gspell-text-view.c
+++ b/gspell/gspell-text-view.c
@@ -476,6 +476,68 @@ gspell_text_view_get_from_gtk_text_view (GtkTextView *gtk_view)
 }
 
 /**
+ * gspell_text_view_basic_setup:
+ * @gspell_view: a #GspellTextView.
+ *
+ * This function is a convenience function that does the following:
+ * - Set a spell checker. The language chosen is the one returned by
+ *   gspell_language_get_default().
+ * - Set the #GspellTextView:inline-spell-checking property to %TRUE.
+ * - Set the #GspellTextView:enable-language-menu property to %TRUE.
+ *
+ * Example:
+ * |[
+ * GtkTextView *gtk_view;
+ * GspellTextView *gspell_view;
+ *
+ * gspell_view = gspell_text_view_get_from_gtk_text_view (gtk_view);
+ * gspell_text_view_basic_setup (gspell_view);
+ * ]|
+ *
+ * This is equivalent to:
+ * |[
+ * GtkTextView *gtk_view;
+ * GspellTextView *gspell_view;
+ * GspellChecker *checker;
+ * GtkTextBuffer *gtk_buffer;
+ * GspellTextBuffer *gspell_buffer;
+ *
+ * checker = gspell_checker_new (NULL);
+ * gtk_buffer = gtk_text_view_get_buffer (gtk_view);
+ * gspell_buffer = gspell_text_buffer_get_from_gtk_text_buffer (gtk_buffer);
+ * gspell_text_buffer_set_spell_checker (gspell_buffer, checker);
+ * g_object_unref (checker);
+ *
+ * gspell_view = gspell_text_view_get_from_gtk_text_view (gtk_view);
+ * gspell_text_view_set_inline_spell_checking (gspell_view, TRUE);
+ * gspell_text_view_set_enable_language_menu (gspell_view, TRUE);
+ * ]|
+ *
+ * Since: 1.2
+ */
+void
+gspell_text_view_basic_setup (GspellTextView *gspell_view)
+{
+       GspellTextViewPrivate *priv;
+       GspellChecker *checker;
+       GtkTextBuffer *gtk_buffer;
+       GspellTextBuffer *gspell_buffer;
+
+       g_return_if_fail (GSPELL_IS_TEXT_VIEW (gspell_view));
+
+       priv = gspell_text_view_get_instance_private (gspell_view);
+
+       checker = gspell_checker_new (NULL);
+       gtk_buffer = gtk_text_view_get_buffer (priv->view);
+       gspell_buffer = gspell_text_buffer_get_from_gtk_text_buffer (gtk_buffer);
+       gspell_text_buffer_set_spell_checker (gspell_buffer, checker);
+       g_object_unref (checker);
+
+       gspell_text_view_set_inline_spell_checking (gspell_view, TRUE);
+       gspell_text_view_set_enable_language_menu (gspell_view, TRUE);
+}
+
+/**
  * gspell_text_view_get_view:
  * @gspell_view: a #GspellTextView.
  *
diff --git a/gspell/gspell-text-view.h b/gspell/gspell-text-view.h
index be764f6..320aec0 100644
--- a/gspell/gspell-text-view.h
+++ b/gspell/gspell-text-view.h
@@ -43,6 +43,8 @@ struct _GspellTextViewClass
 
 GspellTextView *       gspell_text_view_get_from_gtk_text_view         (GtkTextView *gtk_view);
 
+void                   gspell_text_view_basic_setup                    (GspellTextView *gspell_view);
+
 GtkTextView *          gspell_text_view_get_view                       (GspellTextView *gspell_view);
 
 gboolean               gspell_text_view_get_inline_spell_checking      (GspellTextView *gspell_view);


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