2 * \file GSpellchecker.C
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
8 * Full author contact details are available in file CREDITS.
13 // Too hard to make concept checks work with this file
14 #ifdef _GLIBCXX_CONCEPT_CHECKS
15 #undef _GLIBCXX_CONCEPT_CHECKS
17 #ifdef _GLIBCPP_CONCEPT_CHECKS
18 #undef _GLIBCPP_CONCEPT_CHECKS
21 #include "GSpellchecker.h"
22 #include "controllers/ControlSpellchecker.h"
26 #include "support/convert.h"
33 GSpellchecker::GSpellchecker(Dialog & parent)
34 : GViewCB<ControlSpellchecker, GViewGladeB>
35 (parent, _("Spellchecker"), false)
39 void GSpellchecker::doBuild()
41 string const gladeName = findGladeFile("spellcheck");
42 xml_ = Gnome::Glade::Xml::create(gladeName);
45 xml_->get_widget("Close", button);
48 xml_->get_widget("Suggestions", suggestionsview_);
49 xml_->get_widget("Unknown", unknownentry_);
50 xml_->get_widget("Replacement", replacemententry_);
51 xml_->get_widget("Progress", progress_);
53 listCols_.add(listCol_);
54 suggestionsstore_ = Gtk::ListStore::create(listCols_);
55 suggestionsview_->set_model(suggestionsstore_);
56 suggestionsview_->append_column("Suggestion", listCol_);
57 suggestionssel_ = suggestionsview_->get_selection();
59 // Single click in suggestion list
60 suggestionssel_->signal_changed().connect(
61 sigc::mem_fun(*this, &GSpellchecker::onSuggestionSelection));
63 // Double click in suggestion list
64 suggestionsview_->signal_row_activated().connect(
65 sigc::mem_fun(*this, &GSpellchecker::onSuggestionActivate));
67 // Because it's like a Replace button when double clicked
68 bcview().addReadOnly(suggestionsview_);
70 xml_->get_widget("Replace", button);
71 bcview().addReadOnly(button);
72 button->signal_clicked().connect(
74 sigc::mem_fun(*this, &GSpellchecker::onReplace), false));
76 xml_->get_widget("ReplaceAll", button);
77 bcview().addReadOnly(button);
78 button->signal_clicked().connect(
80 sigc::mem_fun(*this, &GSpellchecker::onReplace), true));
82 xml_->get_widget("Ignore", ignorebutton_);
83 ignorebutton_->signal_clicked().connect(
84 sigc::mem_fun(*this, &GSpellchecker::onIgnore));
86 xml_->get_widget("IgnoreAll", button);
87 button->signal_clicked().connect(
88 sigc::mem_fun(*this, &GSpellchecker::onIgnoreAll));
90 xml_->get_widget("Add", button);
91 button->signal_clicked().connect(
92 sigc::mem_fun(*this, &GSpellchecker::onAdd));
96 void GSpellchecker::show()
101 bcview().refreshReadOnly();
102 controller().check();
103 if (!controller().getWord().empty())
107 void GSpellchecker::partialUpdate(int s)
109 ControlSpellchecker::State const state =
110 static_cast<ControlSpellchecker::State>(s);
112 if (state == ControlSpellchecker::SPELL_FOUND_WORD) {
113 string word = controller().getWord();
114 Glib::ustring utfword = Glib::locale_to_utf8(word);
115 unknownentry_->set_text(utfword);
116 replacemententry_->set_text(utfword);
118 // Get the list of suggestions
119 suggestionsstore_->clear();
120 while (!(word = controller().getSuggestion()).empty()) {
121 utfword = Glib::locale_to_utf8(word);
122 (*suggestionsstore_->append())[listCol_] = utfword;
126 // In readonly docs the user must just be browsing through
127 ignorebutton_->grab_focus();
129 // In general we expect the user to type their replacement
130 replacemententry_->grab_focus();
133 int const progress = controller().getProgress();
135 progress_->set_fraction(float(progress)/100.0f);
136 progress_->set_text(convert<string>(progress) + "% " + _("checked"));
141 void GSpellchecker::onSuggestionActivate(
142 Gtk::TreeModel::Path const & path,
143 Gtk::TreeViewColumn * /*col*/)
145 Glib::ustring const suggestion =
146 (*suggestionsstore_->get_iter(path))[listCol_];
148 if (!suggestion.empty())
149 controller().replace(suggestion);
153 void GSpellchecker::onSuggestionSelection()
155 Glib::ustring const suggestion =
156 (*suggestionssel_->get_selected())[listCol_];
158 if (!suggestion.empty())
159 replacemententry_->set_text(suggestion);
163 void GSpellchecker::onIgnore()
165 controller().check();
169 void GSpellchecker::onIgnoreAll()
171 controller().ignoreAll();
175 void GSpellchecker::onAdd()
177 controller().insert();
181 void GSpellchecker::onReplace(bool const all)
183 Glib::ustring const replacement = replacemententry_->get_text();
185 controller().replaceAll(replacement);
187 controller().replace(replacement);
191 } // namespace frontend