3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Bernhard Reiter
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 "GThesaurus.h"
22 #include "ControlThesaurus.h"
25 #include "support/lstrings.h"
27 #include <libglademm.h>
34 class synModelColumns : public Gtk::TreeModel::ColumnRecord
38 synModelColumns() { add(name); }
40 Gtk::TreeModelColumn<Glib::ustring> name;
43 synModelColumns synColumns;
46 GThesaurus::GThesaurus(Dialog & parent)
47 : GViewCB<ControlThesaurus, GViewGladeB>(parent, _("Thesaurus"), false)
51 void GThesaurus::doBuild()
53 string const gladeName = findGladeFile("thesaurus");
54 xml_ = Gnome::Glade::Xml::create(gladeName);
56 xml_->get_widget("Cancel", cancelbutton_);
57 setCancel(cancelbutton_);
58 xml_->get_widget("Apply", applybutton_);
59 setApply(applybutton_);
60 xml_->get_widget("OK", okbutton_);
63 xml_->get_widget("Keyword", keywordentry_);
64 xml_->get_widget("Meanings", meaningsview_);
66 meaningsview_->append_column(_("Synonym"), synColumns.name);
69 // Keyword entry changed
70 keywordentry_->signal_changed().connect(
71 sigc::mem_fun(*this, >hesaurus::update_lists));
73 // Single click in meanings (synonyms) list
74 meaningsview_->signal_cursor_changed().connect(
75 sigc::mem_fun(*this, >hesaurus::selection_changed));
77 // Double click in meanings (synonyms) list
78 meaningsview_->signal_row_activated().connect(
79 sigc::mem_fun(*this, >hesaurus::meaningsview_activated));
83 void GThesaurus::update()
85 string const contents = support::trim(controller().text());
86 if (contents.empty()) {
91 keywordentry_->set_text(Glib::locale_to_utf8(contents));
94 keywordentry_->grab_focus();
100 void GThesaurus::selection_changed()
102 Gtk::TreeModel::iterator iter = meaningsview_->get_selection()->get_selected();
104 if (!applylock_) bc().valid(true);
110 void GThesaurus::meaningsview_activated(const Gtk::TreeModel::Path&, Gtk::TreeViewColumn*)
112 Gtk::TreeModel::iterator iter = meaningsview_->get_selection()->get_selected();
114 Gtk::TreeModel::Row row = *iter;
115 keywordentry_->set_text(row[synColumns.name]);
119 if (!applylock_) bc().valid(true);
123 void GThesaurus::apply()
125 Gtk::TreeModel::iterator iter = meaningsview_->get_selection()->get_selected();
127 controller().replace(Glib::locale_from_utf8((*iter)[synColumns.name]));
128 } else if (keywordentry_->get_text_length()) {
129 controller().replace(Glib::locale_from_utf8(keywordentry_->get_text()));
135 void GThesaurus::update_lists()
137 Thesaurus::Meanings meanings = controller().getMeanings(keywordentry_->get_text());
138 synTreeStore_ = Gtk::TreeStore::create(synColumns);
140 if (!meanings.empty()) {
141 for (Thesaurus::Meanings::const_iterator cit = meanings.begin();
142 cit != meanings.end(); ++cit) {
144 Gtk::TreeModel::Row row = *(synTreeStore_->append());
145 row[synColumns.name] = cit->first;
147 for (std::vector<string>::const_iterator cit2 = cit->second.begin();
148 cit2 != cit->second.end(); ++cit2) {
149 Gtk::TreeModel::Row childrow = *(synTreeStore_->append(row.children()));
150 childrow[synColumns.name] = *cit2;
153 meaningsview_->set_sensitive(true);
155 Gtk::TreeModel::Row row = *(synTreeStore_->append());
156 row[synColumns.name] = _("No synonyms found");
157 meaningsview_->set_sensitive(false);
159 meaningsview_->set_model(synTreeStore_);
161 if (keywordentry_->get_text_length()) {
162 if (!applylock_) bc().valid(true);
169 } // namespace frontend