[gnote] Remember spell-check language per note
- From: Aurimas Černius <aurimasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnote] Remember spell-check language per note
- Date: Sun, 20 Oct 2013 14:40:13 +0000 (UTC)
commit 646ef1e098bd96e5dd7e510e8e8e520d95ec0198
Author: Aurimas Černius <aurisc4 gmail com>
Date: Sun Oct 20 17:37:34 2013 +0300
Remember spell-check language per note
Fixes Bug 586350.
src/watchers.cpp | 43 +++++++++++++++++++++++++++++++++++++++++++
src/watchers.hpp | 4 ++++
2 files changed, 47 insertions(+), 0 deletions(-)
---
diff --git a/src/watchers.cpp b/src/watchers.cpp
index 69b209f..198abfe 100644
--- a/src/watchers.cpp
+++ b/src/watchers.cpp
@@ -282,6 +282,8 @@ namespace gnote {
#if FIXED_GTKSPELL
+ const char *NoteSpellChecker::LANG_PREFIX = "spellchecklang:";
+
void NoteSpellChecker::shutdown ()
{
detach();
@@ -314,6 +316,11 @@ namespace gnote {
if (!m_obj_ptr) {
m_obj_ptr = gtk_spell_checker_new();
+ Tag::Ptr tag = get_language_tag();
+ if(tag) {
+ gtk_spell_checker_set_language(m_obj_ptr, sharp::string_replace_first(tag->name(), LANG_PREFIX,
"").c_str(), NULL);
+ }
+ g_signal_connect(G_OBJECT(m_obj_ptr), "language-changed", G_CALLBACK(language_changed), this);
gtk_spell_checker_attach(m_obj_ptr, get_window()->editor()->gobj());
}
}
@@ -377,6 +384,42 @@ namespace gnote {
start_char, end_char);
}
}
+
+ void NoteSpellChecker::language_changed(GtkSpellChecker*, gchar *lang, NoteSpellChecker *checker)
+ {
+ try {
+ checker->on_language_changed(lang);
+ }
+ catch(...) {
+ }
+ }
+
+ void NoteSpellChecker::on_language_changed(const gchar *lang)
+ {
+ std::string tag_name = LANG_PREFIX;
+ tag_name += lang;
+ Tag::Ptr tag = get_language_tag();
+ if(tag && tag->name() != tag_name) {
+ get_note()->remove_tag(tag);
+ }
+ tag = ITagManager::obj().get_or_create_tag(tag_name);
+ get_note()->add_tag(tag);
+ DBG_OUT("Added language tag %s", tag_name.c_str());
+ }
+
+ Tag::Ptr NoteSpellChecker::get_language_tag()
+ {
+ Tag::Ptr lang_tag;
+ std::list<Tag::Ptr> tags;
+ get_note()->get_tags(tags);
+ FOREACH(Tag::Ptr tag, tags) {
+ if(sharp::string_index_of(tag->name(), LANG_PREFIX) == 0) {
+ lang_tag = tag;
+ break;
+ }
+ }
+ return lang_tag;
+ }
#endif
////////////////////////////////////////////////////////////////////////
diff --git a/src/watchers.hpp b/src/watchers.hpp
index 09b153a..a60eae0 100644
--- a/src/watchers.hpp
+++ b/src/watchers.hpp
@@ -101,11 +101,15 @@ namespace gnote {
: m_obj_ptr(NULL)
{}
private:
+ static const char *LANG_PREFIX;
+ static void language_changed(GtkSpellChecker*, gchar *lang, NoteSpellChecker *checker);
void attach();
void detach();
void on_enable_spellcheck_changed(const Glib::ustring & key);
void tag_applied(const Glib::RefPtr<const Gtk::TextTag> &,
const Gtk::TextIter &, const Gtk::TextIter &);
+ void on_language_changed(const gchar *lang);
+ Tag::Ptr get_language_tag();
GtkSpellChecker *m_obj_ptr;
sigc::connection m_tag_applied_cid;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]