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 #include "GSpellchecker.h"
14 #include "controllers/ControlSpellchecker.h"
18 #include "support/tostr.h"
25 GSpellchecker::GSpellchecker(Dialog & parent)
26 : GViewCB<ControlSpellchecker, GViewGladeB>
27 (parent, _("Spell-check document"), false)
31 void GSpellchecker::doBuild()
33 string const gladeName = findGladeFile("spellcheck");
34 xml_ = Gnome::Glade::Xml::create(gladeName);
37 xml_->get_widget("Close", button);
40 xml_->get_widget("Suggestions", suggestionsview_);
41 xml_->get_widget("Unknown", unknownentry_);
42 xml_->get_widget("Replacement", replacemententry_);
43 xml_->get_widget("Progress", progress_);
45 listCols_.add(listCol_);
46 suggestionsstore_ = Gtk::ListStore::create(listCols_);
47 suggestionsview_->set_model(suggestionsstore_);
48 suggestionsview_->append_column("Suggestion", listCol_);
49 suggestionssel_ = suggestionsview_->get_selection();
51 // Single click in suggestion list
52 suggestionssel_->signal_changed().connect(
53 sigc::mem_fun(*this, &GSpellchecker::onSuggestionSelection));
55 // Double click in suggestion list
56 suggestionsview_->signal_row_activated().connect(
57 sigc::mem_fun(*this, &GSpellchecker::onSuggestionActivate));
59 // Because it's like a Replace button when double clicked
60 bcview().addReadOnly(suggestionsview_);
62 xml_->get_widget("Replace", button);
63 bcview().addReadOnly(button);
64 button->signal_clicked().connect(
66 sigc::mem_fun(*this, &GSpellchecker::onReplace), false));
68 xml_->get_widget("ReplaceAll", button);
69 bcview().addReadOnly(button);
70 button->signal_clicked().connect(
72 sigc::mem_fun(*this, &GSpellchecker::onReplace), true));
74 xml_->get_widget("Ignore", ignorebutton_);
75 ignorebutton_->signal_clicked().connect(
76 sigc::mem_fun(*this, &GSpellchecker::onIgnore));
78 xml_->get_widget("IgnoreAll", button);
79 button->signal_clicked().connect(
80 sigc::mem_fun(*this, &GSpellchecker::onIgnoreAll));
82 xml_->get_widget("Add", button);
83 button->signal_clicked().connect(
84 sigc::mem_fun(*this, &GSpellchecker::onAdd));
88 void GSpellchecker::show()
93 bcview().refreshReadOnly();
95 if (!controller().getWord().empty())
99 void GSpellchecker::partialUpdate(int s)
101 ControlSpellchecker::State const state =
102 static_cast<ControlSpellchecker::State>(s);
104 if (state == ControlSpellchecker::SPELL_FOUND_WORD) {
105 string word = controller().getWord();
106 Glib::ustring utfword = Glib::locale_to_utf8(word);
107 unknownentry_->set_text(utfword);
108 replacemententry_->set_text(utfword);
110 // Get the list of suggestions
111 suggestionsstore_->clear();
112 while (!(word = controller().getSuggestion()).empty()) {
113 utfword = Glib::locale_to_utf8(word);
114 (*suggestionsstore_->append())[listCol_] = utfword;
118 // In readonly docs the user must just be browsing through
119 ignorebutton_->grab_focus();
121 // In general we expect the user to type their replacement
122 replacemententry_->grab_focus();
125 int const progress = controller().getProgress();
127 progress_->set_fraction(float(progress)/100.0f);
128 progress_->set_text(tostr(progress) + "% " + _("checked"));
133 void GSpellchecker::onSuggestionActivate(
134 Gtk::TreeModel::Path const & path,
135 Gtk::TreeViewColumn * col)
137 Glib::ustring const suggestion =
138 (*suggestionsstore_->get_iter(path))[listCol_];
140 if (!suggestion.empty())
141 controller().replace(suggestion);
145 void GSpellchecker::onSuggestionSelection()
147 Glib::ustring const suggestion =
148 (*suggestionssel_->get_selected())[listCol_];
150 if (!suggestion.empty())
151 replacemententry_->set_text(suggestion);
155 void GSpellchecker::onIgnore()
157 controller().check();
161 void GSpellchecker::onIgnoreAll()
163 controller().ignoreAll();
167 void GSpellchecker::onAdd()
169 controller().insert();
173 void GSpellchecker::onReplace(bool const all)
175 Glib::ustring const replacement = replacemententry_->get_text();
177 controller().replaceAll(replacement);
179 controller().replace(replacement);
183 } // namespace frontend