[gnote] Add ability to disable spell check per note
- From: Aurimas Černius <aurimasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnote] Add ability to disable spell check per note
- Date: Sun, 20 Oct 2013 18:21:16 +0000 (UTC)
commit 1c70aa4bce7b81b8dde1f2ba7544e06a385e0257
Author: Aurimas Černius <aurisc4 gmail com>
Date: Sun Oct 20 21:19:36 2013 +0300
Add ability to disable spell check per note
Fixes Bug 703258.
src/watchers.cpp | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++---
src/watchers.hpp | 6 +++++
2 files changed, 62 insertions(+), 4 deletions(-)
---
diff --git a/src/watchers.cpp b/src/watchers.cpp
index 198abfe..406aaf9 100644
--- a/src/watchers.cpp
+++ b/src/watchers.cpp
@@ -283,6 +283,7 @@ namespace gnote {
#if FIXED_GTKSPELL
const char *NoteSpellChecker::LANG_PREFIX = "spellchecklang:";
+ const char *NoteSpellChecker::LANG_DISABLED = "disabled";
void NoteSpellChecker::shutdown ()
{
@@ -302,6 +303,20 @@ namespace gnote {
void NoteSpellChecker::attach ()
{
+ attach_checker();
+
+ m_enable_action = utils::CheckAction::create("EnableSpellCheck");
+ m_enable_action->set_label(_("Check spelling"));
+ m_enable_action->set_tooltip(_("Check spelling in this note"));
+ m_enable_action->checked(get_language() != LANG_DISABLED);
+ m_enable_action->signal_activate()
+ .connect(sigc::mem_fun(*this, &NoteSpellChecker::on_spell_check_enable_action));
+ add_note_action(m_enable_action, 800);
+ }
+
+
+ void NoteSpellChecker::attach_checker()
+ {
// Make sure we add this tag before attaching, so
// gtkspell will use our version.
if (!get_note()->get_tag_table()->lookup ("gtkspell-misspelled")) {
@@ -314,11 +329,12 @@ namespace gnote {
m_tag_applied_cid = get_buffer()->signal_apply_tag().connect(
sigc::mem_fun(*this, &NoteSpellChecker::tag_applied), false); // connect before
- if (!m_obj_ptr) {
+ std::string lang = get_language();
+
+ if (!m_obj_ptr && lang != LANG_DISABLED) {
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);
+ if(lang != "") {
+ gtk_spell_checker_set_language(m_obj_ptr, lang.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());
@@ -328,6 +344,14 @@ namespace gnote {
void NoteSpellChecker::detach ()
{
+ detach_checker();
+ get_window()->remove_widget_action("EnableSpellCheck");
+ m_enable_action.reset();
+ }
+
+
+ void NoteSpellChecker::detach_checker()
+ {
m_tag_applied_cid.disconnect();
if(m_obj_ptr) {
@@ -420,6 +444,34 @@ namespace gnote {
}
return lang_tag;
}
+
+ std::string NoteSpellChecker::get_language()
+ {
+ Tag::Ptr tag = get_language_tag();
+ std::string lang;
+ if(tag) {
+ lang = sharp::string_replace_first(tag->name(), LANG_PREFIX, "");
+ }
+ return lang;
+ }
+
+ void NoteSpellChecker::on_spell_check_enable_action()
+ {
+ Tag::Ptr tag = get_language_tag();
+ if(tag) {
+ get_note()->remove_tag(tag);
+ }
+ if(m_enable_action->checked()) {
+ attach_checker();
+ }
+ else {
+ std::string tag_name = LANG_PREFIX;
+ tag_name += LANG_DISABLED;
+ tag = ITagManager::obj().get_or_create_tag(tag_name);
+ get_note()->add_tag(tag);
+ detach_checker();
+ }
+ }
#endif
////////////////////////////////////////////////////////////////////////
diff --git a/src/watchers.hpp b/src/watchers.hpp
index a60eae0..24676c2 100644
--- a/src/watchers.hpp
+++ b/src/watchers.hpp
@@ -102,17 +102,23 @@ namespace gnote {
{}
private:
static const char *LANG_PREFIX;
+ static const char *LANG_DISABLED;
static void language_changed(GtkSpellChecker*, gchar *lang, NoteSpellChecker *checker);
void attach();
+ void attach_checker();
void detach();
+ void detach_checker();
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();
+ std::string get_language();
+ void on_spell_check_enable_action();
GtkSpellChecker *m_obj_ptr;
sigc::connection m_tag_applied_cid;
+ utils::CheckAction::Ptr m_enable_action;
};
#else
class NoteSpellChecker
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]