[gspell/wip/basic-setup-func] text-view: add basic_setup() function
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gspell/wip/basic-setup-func] text-view: add basic_setup() function
- Date: Mon, 8 Aug 2016 12:45:29 +0000 (UTC)
commit 094782d96d7ed4865317e74b32b54169797efd7c
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 | 74 ++++++++++++++++++++++++++++++--
gspell/gspell-text-view.h | 2 +
3 files changed, 73 insertions(+), 4 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..2eb05d7 100644
--- a/gspell/gspell-text-view.c
+++ b/gspell/gspell-text-view.c
@@ -37,15 +37,19 @@
* to add the misspelled word to the session dictionary. And an “Add” item to
* add the word to the personal dictionary.
*
+ * For a basic use-case, there is the gspell_text_view_basic_setup() convenience
+ * function.
+ *
* The spell is checked only on the visible region of the #GtkTextView. Note
* that if a same #GtkTextBuffer is used for several views, the misspelled words
* are visible in all views, because the highlighting is achieved with a
* #GtkTextTag added to the buffer.
*
- * You need to call gspell_text_buffer_set_spell_checker() to associate a
- * #GspellChecker to the #GtkTextBuffer. #GspellTextView handles automatically
- * changes to the following properties: #GtkTextView:buffer,
- * #GspellTextBuffer:spell-checker and #GspellChecker:language.
+ * If you don't use the gspell_text_view_basic_setup() function, you need to
+ * call gspell_text_buffer_set_spell_checker() to associate a #GspellChecker to
+ * the #GtkTextBuffer. #GspellTextView handles automatically changes to the
+ * following properties: #GtkTextView:buffer, #GspellTextBuffer:spell-checker
+ * and #GspellChecker:language.
*
* Note that #GspellTextView extends the #GtkTextView class but without
* subclassing it, because the GtkSourceView library has already a #GtkTextView
@@ -476,6 +480,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]