2 * \file GuiThesaurus.cpp
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 "GuiThesaurus.h"
15 #include "qt_helpers.h"
17 #include "FuncRequest.h"
20 #include "support/debug.h"
21 #include "support/gettext.h"
23 #include <QHeaderView>
25 #include <QPushButton>
26 #include <QTreeWidget>
27 #include <QTreeWidgetItem>
35 GuiThesaurus::GuiThesaurus(GuiView & lv)
36 : GuiDialog(lv, "thesaurus", qt_("Thesaurus"))
40 meaningsTV->setColumnCount(1);
41 meaningsTV->header()->hide();
43 connect(closePB, SIGNAL(clicked()),
44 this, SLOT(slotClose()));
45 connect(replaceED, SIGNAL(returnPressed()),
46 this, SLOT(replaceClicked()));
47 connect(replaceED, SIGNAL(textChanged(QString)),
48 this, SLOT(change_adaptor()));
49 connect(entryED, SIGNAL(returnPressed()),
50 this, SLOT(entryChanged()));
51 connect(replacePB, SIGNAL(clicked()),
52 this, SLOT(replaceClicked()));
53 connect(meaningsTV, SIGNAL(itemClicked(QTreeWidgetItem *, int)),
54 this, SLOT(itemClicked(QTreeWidgetItem *, int)));
55 connect(meaningsTV, SIGNAL(itemSelectionChanged()),
56 this, SLOT(selectionChanged()));
57 connect(meaningsTV, SIGNAL(itemActivated(QTreeWidgetItem *, int)),
58 this, SLOT(selectionClicked(QTreeWidgetItem *, int)));
60 bc().setCancel(closePB);
61 bc().setApply(replacePB);
62 bc().addReadOnly(replaceED);
63 bc().addReadOnly(replacePB);
64 bc().setPolicy(ButtonPolicy::OkApplyCancelReadOnlyPolicy);
68 void GuiThesaurus::change_adaptor()
74 void GuiThesaurus::entryChanged()
80 void GuiThesaurus::selectionChanged()
82 int const col = meaningsTV->currentColumn();
83 if (col < 0 || isBufferReadonly())
86 replaceED->setText(meaningsTV->currentItem()->text(col));
87 replacePB->setEnabled(true);
92 void GuiThesaurus::itemClicked(QTreeWidgetItem * /*item*/, int /*col*/)
98 void GuiThesaurus::selectionClicked(QTreeWidgetItem * item, int col)
100 entryED->setText(item->text(col));
106 void GuiThesaurus::updateLists()
109 meaningsTV->setUpdatesEnabled(false);
111 Thesaurus::Meanings meanings = getMeanings(qstring_to_ucs4(entryED->text()));
113 for (Thesaurus::Meanings::const_iterator cit = meanings.begin();
114 cit != meanings.end(); ++cit) {
115 QTreeWidgetItem * i = new QTreeWidgetItem(meaningsTV);
116 i->setText(0, toqstr(cit->first));
117 meaningsTV->expandItem(i);
118 for (vector<docstring>::const_iterator cit2 = cit->second.begin();
119 cit2 != cit->second.end(); ++cit2) {
120 QTreeWidgetItem * i2 = new QTreeWidgetItem(i);
121 i2->setText(0, toqstr(*cit2));
125 meaningsTV->setUpdatesEnabled(true);
126 meaningsTV->update();
130 void GuiThesaurus::updateContents()
132 entryED->setText(toqstr(text_));
133 replaceED->setText("");
138 void GuiThesaurus::replaceClicked()
140 replace(qstring_to_ucs4(replaceED->text()));
144 bool GuiThesaurus::initialiseParams(string const & data)
146 text_ = from_utf8(data);
151 void GuiThesaurus::clearParams()
157 void GuiThesaurus::replace(docstring const & newstr)
159 /* FIXME: this is not suitable ! We need to have a "lock"
160 * on a particular charpos in a paragraph that is broken on
163 docstring const data =
164 replace2string(text_, newstr,
165 true, // case sensitive
169 dispatch(FuncRequest(LFUN_WORD_REPLACE, data));
173 Thesaurus::Meanings const & GuiThesaurus::getMeanings(docstring const & str)
176 meanings_ = thesaurus.lookup(str);
181 Dialog * createGuiThesaurus(GuiView & lv) { return new GuiThesaurus(lv); }
184 } // namespace frontend
188 #include "moc_GuiThesaurus.cpp"