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 _GLIBCPP_CONCEPT_CHECKS
15 #undef _GLIBCPP_CONCEPT_CHECKS
18 #include "GSpellchecker.h"
19 #include "controllers/ControlSpellchecker.h"
23 #include "support/tostr.h"
30 GSpellchecker::GSpellchecker(Dialog & parent)
31 : GViewCB<ControlSpellchecker, GViewGladeB>
32 (parent, _("Spell-check document"), false)
36 void GSpellchecker::doBuild()
38 string const gladeName = findGladeFile("spellcheck");
39 xml_ = Gnome::Glade::Xml::create(gladeName);
42 xml_->get_widget("Close", button);
45 xml_->get_widget("Suggestions", suggestionsview_);
46 xml_->get_widget("Unknown", unknownentry_);
47 xml_->get_widget("Replacement", replacemententry_);
48 xml_->get_widget("Progress", progress_);
50 listCols_.add(listCol_);
51 suggestionsstore_ = Gtk::ListStore::create(listCols_);
52 suggestionsview_->set_model(suggestionsstore_);
53 suggestionsview_->append_column("Suggestion", listCol_);
54 suggestionssel_ = suggestionsview_->get_selection();
56 // Single click in suggestion list
57 suggestionssel_->signal_changed().connect(
58 sigc::mem_fun(*this, &GSpellchecker::onSuggestionSelection));
60 // Double click in suggestion list
61 suggestionsview_->signal_row_activated().connect(
62 sigc::mem_fun(*this, &GSpellchecker::onSuggestionActivate));
64 // Because it's like a Replace button when double clicked
65 bcview().addReadOnly(suggestionsview_);
67 xml_->get_widget("Replace", button);
68 bcview().addReadOnly(button);
69 button->signal_clicked().connect(
71 sigc::mem_fun(*this, &GSpellchecker::onReplace), false));
73 xml_->get_widget("ReplaceAll", button);
74 bcview().addReadOnly(button);
75 button->signal_clicked().connect(
77 sigc::mem_fun(*this, &GSpellchecker::onReplace), true));
79 xml_->get_widget("Ignore", ignorebutton_);
80 ignorebutton_->signal_clicked().connect(
81 sigc::mem_fun(*this, &GSpellchecker::onIgnore));
83 xml_->get_widget("IgnoreAll", button);
84 button->signal_clicked().connect(
85 sigc::mem_fun(*this, &GSpellchecker::onIgnoreAll));
87 xml_->get_widget("Add", button);
88 button->signal_clicked().connect(
89 sigc::mem_fun(*this, &GSpellchecker::onAdd));
93 void GSpellchecker::show()
98 bcview().refreshReadOnly();
100 if (!controller().getWord().empty())
104 void GSpellchecker::partialUpdate(int s)
106 ControlSpellchecker::State const state =
107 static_cast<ControlSpellchecker::State>(s);
109 if (state == ControlSpellchecker::SPELL_FOUND_WORD) {
110 string word = controller().getWord();
111 Glib::ustring utfword = Glib::locale_to_utf8(word);
112 unknownentry_->set_text(utfword);
113 replacemententry_->set_text(utfword);
115 // Get the list of suggestions
116 suggestionsstore_->clear();
117 while (!(word = controller().getSuggestion()).empty()) {
118 utfword = Glib::locale_to_utf8(word);
119 (*suggestionsstore_->append())[listCol_] = utfword;
123 // In readonly docs the user must just be browsing through
124 ignorebutton_->grab_focus();
126 // In general we expect the user to type their replacement
127 replacemententry_->grab_focus();
130 int const progress = controller().getProgress();
132 progress_->set_fraction(float(progress)/100.0f);
133 progress_->set_text(tostr(progress) + "% " + _("checked"));
138 void GSpellchecker::onSuggestionActivate(
139 Gtk::TreeModel::Path const & path,
140 Gtk::TreeViewColumn * /*col*/)
142 Glib::ustring const suggestion =
143 (*suggestionsstore_->get_iter(path))[listCol_];
145 if (!suggestion.empty())
146 controller().replace(suggestion);
150 void GSpellchecker::onSuggestionSelection()
152 Glib::ustring const suggestion =
153 (*suggestionssel_->get_selected())[listCol_];
155 if (!suggestion.empty())
156 replacemententry_->set_text(suggestion);
160 void GSpellchecker::onIgnore()
162 controller().check();
166 void GSpellchecker::onIgnoreAll()
168 controller().ignoreAll();
172 void GSpellchecker::onAdd()
174 controller().insert();
178 void GSpellchecker::onReplace(bool const all)
180 Glib::ustring const replacement = replacemententry_->get_text();
182 controller().replaceAll(replacement);
184 controller().replace(replacement);
188 } // namespace frontend