diff --git a/configure.ac.in b/configure.ac.in index efdef10..a4a8d95 100644 --- a/configure.ac.in +++ b/configure.ac.in @@ -144,6 +144,23 @@ AS_IF([test "x$enable_dbus" = "xyes"], AC_DEFINE([HAVE_DBUS], [1], [Define if DBUS support is enabled]) ]) +dnl ************************ +dnl *** Check for gspell *** +dnl ************************ +AC_ARG_ENABLE([gspell], + [AS_HELP_STRING([--enable-gspell], + [Enable gspell support])], + [enable_gspell=$enableval], + [enable_gspell="no"]) + +AM_CONDITIONAL([HAVE_GSPELL], [test "x$enable_gspell" = "xyes"]) + +AS_IF([test "x$enable_gspell" = "xyes"], +[ + XDT_CHECK_PACKAGE([GSPELL], [gspell-1], [1.8.0]) + AC_DEFINE([HAVE_GSPELL], [1], [Define if gspell support is enabled]) +]) + dnl *********************************** dnl *** Check for debugging support *** dnl *********************************** @@ -180,6 +197,7 @@ echo echo "Build Configuration:" echo echo "* D-BUS support: $enable_dbus" +echo "* gspell support: $enable_gspell" echo "* Debug Support: $enable_debug" echo "* Use keyfile backend: $enable_keyfile_settings" echo "* Build with GTK+ 3: $enable_gtk3" diff --git a/mousepad/Makefile.am b/mousepad/Makefile.am index 81260c4..7d1640d 100644 --- a/mousepad/Makefile.am +++ b/mousepad/Makefile.am @@ -71,6 +71,7 @@ mousepad_CFLAGS = \ $(GTK_CFLAGS) \ $(GTHREAD_CFLAGS) \ $(GTKSOURCEVIEW_CFLAGS) \ + $(GSPELL_CFLAGS) \ $(PLATFORM_CFLAGS) \ $(XFCONF_CFLAGS) \ -DMOUSEPAD_GSETTINGS_SCHEMA_DIR=\""$(datadir)/glib-2.0/schemas"\" @@ -84,6 +85,7 @@ mousepad_LDADD = \ $(GTK_LIBS) \ $(GTHREAD_LIBS) \ $(GTKSOURCEVIEW_LIBS) \ + $(GSPELL_LIBS) \ $(XFCONF_LIBS) if HAVE_DBUS diff --git a/mousepad/mousepad-document.c b/mousepad/mousepad-document.c index 7a3c5fa..a1c6a74 100644 --- a/mousepad/mousepad-document.c +++ b/mousepad/mousepad-document.c @@ -199,6 +199,8 @@ mousepad_document_init (MousepadDocument *document) gtk_container_add (GTK_CONTAINER (document), GTK_WIDGET (document->textview)); gtk_widget_show (GTK_WIDGET (document->textview)); + mousepad_view_set_spell_check (document->textview, TRUE); + /* also allow dropping of uris and tabs in the textview */ target_list = gtk_drag_dest_get_target_list (GTK_WIDGET (document->textview)); gtk_target_list_add_table (target_list, drop_targets, G_N_ELEMENTS (drop_targets)); diff --git a/mousepad/mousepad-view.c b/mousepad/mousepad-view.c index 802f116..98adef9 100644 --- a/mousepad/mousepad-view.c +++ b/mousepad/mousepad-view.c @@ -29,6 +29,10 @@ #include #endif +#if HAVE_GSPELL +#include +#endif + #include /* GTK+ 3 removed textview->im_context which is used for multi-selection and @@ -150,6 +154,12 @@ struct _MousepadView gchar *color_scheme; gboolean match_braces; + +#if HAVE_GSPELL + GspellTextView *gspell_view; + GspellChecker *gspell_checker; + GspellTextBuffer *gspell_buffer; +#endif }; @@ -373,6 +383,11 @@ mousepad_view_finalize (GObject *object) /* cleanup color scheme name */ g_free (view->color_scheme); +#if HAVE_GSPELL + if (G_LIKELY (view->gspell_checker != NULL)) + g_object_unref (view->gspell_checker); +#endif + (*G_OBJECT_CLASS (mousepad_view_parent_class)->finalize) (object); } @@ -2860,3 +2875,32 @@ mousepad_view_get_match_braces (MousepadView *view) return view->match_braces; } + + + +void +mousepad_view_set_spell_check (MousepadView *view, + gboolean enabled) +{ + g_return_if_fail (MOUSEPAD_IS_VIEW (view)); + +#if HAVE_GSPELL + if (view->gspell_view == NULL) + { + view->gspell_view = gspell_text_view_get_from_gtk_text_view (GTK_TEXT_VIEW (view)); + view->gspell_checker = gspell_checker_new (NULL); + view->gspell_buffer = gspell_text_buffer_get_from_gtk_text_buffer ( + gtk_text_view_get_buffer (GTK_TEXT_VIEW (view))); + } + + gspell_text_buffer_set_spell_checker (view->gspell_buffer, enabled ? view->gspell_checker : NULL); + gspell_text_view_set_inline_spell_checking (view->gspell_view, enabled); + + /* FIXME: gspell adds menu items upon "populate-popup" signal, but mousepad + * clears all menu items at mousepad_window_menu_textview_shown to add its own + * custom items. Unfortunately gspell doesn't expose the functions used at + * gspell-text-view.c:populate_popup_cb to build those menu items, we would + * have to copy them. */ + /*gspell_text_view_set_enable_language_menu (view->gspell_view, enabled);*/ +#endif +} diff --git a/mousepad/mousepad-view.h b/mousepad/mousepad-view.h index 14c5fce..e7c79f6 100644 --- a/mousepad/mousepad-view.h +++ b/mousepad/mousepad-view.h @@ -124,6 +124,9 @@ void mousepad_view_set_match_braces (MousepadView *view gboolean mousepad_view_get_match_braces (MousepadView *view); +void mousepad_view_set_spell_check (MousepadView *view, + gboolean enabled); + G_END_DECLS #endif /* !__MOUSEPAD_VIEW_H__ */