Spell Checking for the Masses
Recently I needed spell checking support for some cairo (and Pango) based canvas widget. Should be easy to pick, considering there are several aproaches to implement spell checking for GTK+ widgets, like gtkspell or libsexy. Unfortunatly those pretty libraries have the fault of focusing on one single widget only. So equiped with the power of Vala I wrote some small generic spell checking library for GTK+. Instead of directly attaching to some widget this library uses a simple interface for adding spellcheck support:
using GLib;
namespace Gtk {
public interface SpellCheckClient {
public abstract List<SpellCheckCluster> get_clusters ();
public abstract void reset_highlighting ();
public abstract void highlight_word (SpellCheckCluster! word,
int start, int end);
public abstract void replace_word (SpellCheckCluster! word,
string! replacement);
public signal void changed ();
public signal void populate_popup (SpellCheckCluster word,
Menu! menu);
}
}
As the result the library supports spell checking for several GTK+ classes now: GtkTextView, GtkLabel, GtkEntry, GtkTreeModel and PangoLayout.
Spell checking itself is provided by Enchant.
Update: Forgot to demonstrate the multi-lingual mode. Updated the screen cast. It works similiar to Evolution and gtkspell3: A word only fails if it isn't found in any dictionary and some of the menu entries are modified to contain - in violation to the HIG, but in lack of a better idea - submenus. Also forgot to mention future plans: For text views it should be possible to selectivly disable spell checking for read-only or code sections. Also it should be possible to retreive a section's language by inspecting Pango attributes of the text. Well, and finally I have to properly package the beast.
See the discussion we had on http://bugzilla.gnome.org/show_bug.cg...
GTK spell check has been a a pet peeve of mine for some time. Primarily because spelling suggestion is not in the first tree view, rather you have to RMC--> Spelling suggestions --> Pick the word. Even as I type this comment in Firefox, spelling suggestions are handled quite nicely. This one of those issues the GTK API programmers need to take a long hard look at in order to do right. Great work though, however, count the clicks....you just added one more!
Jim: The git repository contains a flattened popup menu now.
This library would be great for gTranslator.
Would be possible to have a mode on this spell checking?
I mean the filter mode (e.g.: TeX filter for aspell) so it can skip the TeX reseved word.
What do you think?
mattions: The interfaces are designed to support that. SpellCheckClients return SpellCheckSections instead of just an character array for that reason. Well, but to really implement this, I need bug 472660 (http://bugzilla.gnome.org/show_bug.cg...) fixed: Don't want to write yet another text tokenizer, when gtksourceview already has one.