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>(parent, lyx::to_utf8(_("Spellchecker")), false)
38 void GSpellchecker::doBuild()
40 string const gladeName = findGladeFile("spellcheck");
41 xml_ = Gnome::Glade::Xml::create(gladeName);
44 xml_->get_widget("Close", button);
47 xml_->get_widget("Suggestions", suggestionsview_);
48 xml_->get_widget("Unknown", unknownentry_);
49 xml_->get_widget("Replacement", replacemententry_);
50 xml_->get_widget("Progress", progress_);
52 listCols_.add(listCol_);
53 suggestionsstore_ = Gtk::ListStore::create(listCols_);
54 suggestionsview_->set_model(suggestionsstore_);
55 suggestionsview_->append_column("Suggestion", listCol_);
56 suggestionssel_ = suggestionsview_->get_selection();
58 // Single click in suggestion list
59 suggestionssel_->signal_changed().connect(
60 sigc::mem_fun(*this, &GSpellchecker::onSuggestionSelection));
62 // Double click in suggestion list
63 suggestionsview_->signal_row_activated().connect(
64 sigc::mem_fun(*this, &GSpellchecker::onSuggestionActivate));
66 // Because it's like a Replace button when double clicked
67 bcview().addReadOnly(suggestionsview_);
69 xml_->get_widget("Replace", button);
70 bcview().addReadOnly(button);
71 button->signal_clicked().connect(
73 sigc::mem_fun(*this, &GSpellchecker::onReplace), false));
75 xml_->get_widget("ReplaceAll", button);
76 bcview().addReadOnly(button);
77 button->signal_clicked().connect(
79 sigc::mem_fun(*this, &GSpellchecker::onReplace), true));
81 xml_->get_widget("Ignore", ignorebutton_);
82 ignorebutton_->signal_clicked().connect(
83 sigc::mem_fun(*this, &GSpellchecker::onIgnore));
85 xml_->get_widget("IgnoreAll", button);
86 button->signal_clicked().connect(
87 sigc::mem_fun(*this, &GSpellchecker::onIgnoreAll));
89 xml_->get_widget("Add", button);
90 button->signal_clicked().connect(
91 sigc::mem_fun(*this, &GSpellchecker::onAdd));
95 void GSpellchecker::show()
100 bcview().refreshReadOnly();
101 controller().check();
102 if (!controller().getWord().empty())
106 void GSpellchecker::partialUpdate(int s)
108 ControlSpellchecker::State const state =
109 static_cast<ControlSpellchecker::State>(s);
111 if (state == ControlSpellchecker::SPELL_FOUND_WORD) {
112 string word = controller().getWord();
113 Glib::ustring utfword = Glib::locale_to_utf8(word);
114 unknownentry_->set_text(utfword);
115 replacemententry_->set_text(utfword);
117 // Get the list of suggestions
118 suggestionsstore_->clear();
119 while (!(word = controller().getSuggestion()).empty()) {
120 utfword = Glib::locale_to_utf8(word);
121 (*suggestionsstore_->append())[listCol_] = utfword;
125 // In readonly docs the user must just be browsing through
126 ignorebutton_->grab_focus();
128 // In general we expect the user to type their replacement
129 replacemententry_->grab_focus();
132 int const progress = controller().getProgress();
134 progress_->set_fraction(float(progress)/100.0f);
135 progress_->set_text(convert<string>(progress) + "% " + lyx::to_utf8(_("checked")));
140 void GSpellchecker::onSuggestionActivate(
141 Gtk::TreeModel::Path const & path,
142 Gtk::TreeViewColumn * /*col*/)
144 Glib::ustring const suggestion =
145 (*suggestionsstore_->get_iter(path))[listCol_];
147 if (!suggestion.empty())
148 controller().replace(suggestion);
152 void GSpellchecker::onSuggestionSelection()
154 Glib::ustring const suggestion =
155 (*suggestionssel_->get_selected())[listCol_];
157 if (!suggestion.empty())
158 replacemententry_->set_text(suggestion);
162 void GSpellchecker::onIgnore()
164 controller().check();
168 void GSpellchecker::onIgnoreAll()
170 controller().ignoreAll();
174 void GSpellchecker::onAdd()
176 controller().insert();
180 void GSpellchecker::onReplace(bool const all)
182 Glib::ustring const replacement = replacemententry_->get_text();
184 controller().replaceAll(replacement);
186 controller().replace(replacement);
190 } // namespace frontend