[pan2] added support for gtkspell3 (yclept nemo)
- From: Heinrich Müller <henmull src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pan2] added support for gtkspell3 (yclept nemo)
- Date: Thu, 2 May 2013 09:07:16 +0000 (UTC)
commit b00f96e10cc054b5428cf47320e1c12106efe369
Author: Heinrich Müller <henmull src gnome org>
Date: Thu May 2 11:05:30 2013 +0200
added support for gtkspell3 (yclept nemo)
configure.in | 4 ++-
pan/gui/group-prefs-dialog.cc | 1 -
pan/gui/post-ui.cc | 63 +++++++++++++++++++++++++++++++++--------
3 files changed, 54 insertions(+), 14 deletions(-)
---
diff --git a/configure.in b/configure.in
index e917432..6b038f0 100644
--- a/configure.in
+++ b/configure.in
@@ -131,10 +131,11 @@ if test "x$want_gtk3" = "xyes" ; then
AC_DEFINE(HAVE_GTK,[1],[GTK+ 3 support])]
)
if test "x$want_gtkspell" = "xyes" ; then
- PKG_CHECK_MODULES([GTKSPELL], [gtkspell-3.0 >= $GTKSPELL3_REQUIRED enchant >= $ENCHANT_REQUIRED],
+ PKG_CHECK_MODULES([GTKSPELL], [gtkspell3-3.0 >= $GTKSPELL3_REQUIRED enchant >= $ENCHANT_REQUIRED],
[
gtkspell_msg=yes
AC_DEFINE(HAVE_GTKSPELL,[1],[GtkSpell support for spellchecking])
+ AC_DEFINE(GTKSPELL_VERSION,[3],[GtkSpell API version])
],
[
gtkspell_msg=no
@@ -148,6 +149,7 @@ else
[
gtkspell_msg=yes
AC_DEFINE(HAVE_GTKSPELL,[1],[GtkSpell support for spellchecking])
+ AC_DEFINE(GTKSPELL_VERSION,[2],[GtkSpell API version])
],
[
gtkspell_msg=no
diff --git a/pan/gui/group-prefs-dialog.cc b/pan/gui/group-prefs-dialog.cc
index 3b98f53..df0aa32 100644
--- a/pan/gui/group-prefs-dialog.cc
+++ b/pan/gui/group-prefs-dialog.cc
@@ -23,7 +23,6 @@ extern "C" {
#include <glib.h>
#include "gtk-compat.h"
#ifdef HAVE_GTKSPELL
- #include <gtkspell/gtkspell.h>
#include <enchant/enchant.h>
#endif
}
diff --git a/pan/gui/post-ui.cc b/pan/gui/post-ui.cc
index c0f5c1c..e372502 100644
--- a/pan/gui/post-ui.cc
+++ b/pan/gui/post-ui.cc
@@ -255,30 +255,63 @@ PostUI :: set_spellcheck_enabled (bool enabled)
GtkTextView * view = GTK_TEXT_VIEW(_body_view);
GError * err (0);
- // set the language
- if(!_spellcheck_language.empty()) // some language was set
- {
- gtkspell_new_attach (view, _spellcheck_language.c_str(), &err); // sets custom spell checker
+#if GTKSPELL_VERSION == 3
+ gboolean spell_attach = TRUE;
+ GtkSpellChecker* spell = gtk_spell_checker_new ();
+
+ // a language has been selected
+ if(!_spellcheck_language.empty()) {
+ // attempt to set the selected language
+ if (!gtk_spell_checker_set_language (spell, _spellcheck_language.c_str(), &err)) {
+ Log::add_err_va (_("Error setting custom spellchecker: %s"), err->message);
+ g_clear_error (&err);
+ // selected language failed, fall back upon the default system locale
+ if (!gtk_spell_checker_set_language (spell, NULL, &err)) {
+ Log::add_err_va (_("Error setting spellchecker: %s"), err->message);
+ g_clear_error (&err);
+ spell_attach = FALSE;
+ }
+ }
+ }
+ else {
+ if (!gtk_spell_checker_set_language (spell, NULL, &err)) {
+ Log::add_err_va (_("Error setting spellchecker: %s"), err->message);
+ g_clear_error (&err);
+ spell_attach = FALSE;
+ }
+ }
+
+ if (spell_attach) {
+ // sink the floating reference
+ gtk_spell_checker_attach (spell, view);
+ }
+ else {
+ // destroy the floating reference
+ g_object_ref_sink (spell);
+ g_object_unref (spell);
+ }
+#else // GTKSPELL_VERSION
+ if(!_spellcheck_language.empty()) {
+ gtkspell_new_attach (view, _spellcheck_language.c_str(), &err);
if (err) {
Log::add_err_va (_("Error setting custom spellchecker: %s"), err->message);
g_clear_error (&err);
- // custom spellchecker failed. defaults to env spellchecker
- gtkspell_new_attach (view, NULL, &err); // tries default env language
+ gtkspell_new_attach (view, NULL, &err);
if (err) {
Log::add_err_va (_("Error setting spellchecker: %s"), err->message);
g_clear_error (&err);
}
}
}
- else
- {
- gtkspell_new_attach (view, NULL, &err); // tries default env language
+ else {
+ gtkspell_new_attach (view, NULL, &err);
if (err) {
Log::add_err_va (_("Error setting spellchecker: %s"), err->message);
g_clear_error (&err);
}
}
-#else
+#endif // GTKSPELL_VERSION
+#else // HAVE_GTKSPELL
// disable this for now, it is annoying
// GtkWidget * w = gtk_message_dialog_new_with_markup (
// GTK_WINDOW(_root),
@@ -288,7 +321,7 @@ PostUI :: set_spellcheck_enabled (bool enabled)
// _("<b>Spellchecker not found!</b>\n \nWas this copy of Pan compiled with GtkSpell enabled?"));
// g_signal_connect_swapped (w, "response", G_CALLBACK (gtk_widget_destroy), w);
// gtk_widget_show_all (w);
-#endif
+#endif // HAVE_GTKSPELL
}
else // disable
{
@@ -296,11 +329,17 @@ PostUI :: set_spellcheck_enabled (bool enabled)
GtkTextView * view = GTK_TEXT_VIEW(_body_view);
if (view)
{
+#if GTKSPELL_VERSION == 3
+ GtkSpellChecker * spell = gtk_spell_checker_get_from_text_view (view);
+ if (spell)
+ gtk_spell_checker_detach (spell);
+#else // GTKSPELL_VERSION
GtkSpell * spell = gtkspell_get_from_text_view (view);
if (spell)
gtkspell_detach (spell);
+#endif // GTKSPELL_VERSION
}
-#endif
+#endif // HAVE_GTKSPELL
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]