2006-03-05 17:24:44 +00:00
|
|
|
/**
|
2007-08-31 05:53:55 +00:00
|
|
|
* \file GuiThesaurus.cpp
|
2006-03-05 17:24:44 +00:00
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
*
|
|
|
|
* \author John Levon
|
|
|
|
*
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
#include "GuiThesaurus.h"
|
2007-09-05 20:33:29 +00:00
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
#include "qt_helpers.h"
|
2007-11-29 07:04:28 +00:00
|
|
|
#include "support/debug.h"
|
2006-03-05 17:24:44 +00:00
|
|
|
|
2007-08-31 22:16:11 +00:00
|
|
|
#include <QCloseEvent>
|
2007-04-24 14:35:15 +00:00
|
|
|
#include <QHeaderView>
|
2006-05-03 19:51:15 +00:00
|
|
|
#include <QLineEdit>
|
|
|
|
#include <QPushButton>
|
2007-04-24 14:35:15 +00:00
|
|
|
#include <QTreeWidget>
|
|
|
|
#include <QTreeWidgetItem>
|
|
|
|
|
2007-10-06 19:59:13 +00:00
|
|
|
#include "lyxfind.h"
|
|
|
|
#include "FuncRequest.h"
|
|
|
|
|
2007-12-12 10:16:00 +00:00
|
|
|
using namespace std;
|
2007-09-05 20:33:29 +00:00
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
namespace lyx {
|
|
|
|
namespace frontend {
|
|
|
|
|
2007-11-23 09:44:02 +00:00
|
|
|
GuiThesaurus::GuiThesaurus(GuiView & lv)
|
2007-10-09 19:34:27 +00:00
|
|
|
: GuiDialog(lv, "thesaurus")
|
2007-04-24 14:35:15 +00:00
|
|
|
{
|
|
|
|
setupUi(this);
|
2007-09-05 20:33:29 +00:00
|
|
|
setViewTitle(_("Thesaurus"));
|
2007-04-24 14:35:15 +00:00
|
|
|
|
|
|
|
meaningsTV->setColumnCount(1);
|
|
|
|
meaningsTV->header()->hide();
|
|
|
|
|
|
|
|
connect(closePB, SIGNAL(clicked()),
|
2007-09-05 20:33:29 +00:00
|
|
|
this, SLOT(slotClose()));
|
2007-04-24 14:35:15 +00:00
|
|
|
connect(replaceED, SIGNAL(returnPressed()),
|
|
|
|
this, SLOT(replaceClicked()));
|
2007-10-06 19:59:13 +00:00
|
|
|
connect(replaceED, SIGNAL(textChanged(QString)),
|
|
|
|
this, SLOT(change_adaptor()));
|
2007-04-24 14:35:15 +00:00
|
|
|
connect(entryED, SIGNAL(returnPressed()),
|
|
|
|
this, SLOT(entryChanged()));
|
|
|
|
connect(replacePB, SIGNAL(clicked()),
|
|
|
|
this, SLOT(replaceClicked()));
|
|
|
|
connect(meaningsTV, SIGNAL(itemClicked(QTreeWidgetItem *, int)),
|
|
|
|
this, SLOT(itemClicked(QTreeWidgetItem *, int)));
|
|
|
|
connect(meaningsTV, SIGNAL(itemSelectionChanged()),
|
|
|
|
this, SLOT(selectionChanged()));
|
|
|
|
connect(meaningsTV, SIGNAL(itemActivated(QTreeWidgetItem *, int)),
|
|
|
|
this, SLOT(selectionClicked(QTreeWidgetItem *, int)));
|
2007-09-05 20:33:29 +00:00
|
|
|
|
|
|
|
bc().setCancel(closePB);
|
|
|
|
bc().setApply(replacePB);
|
|
|
|
bc().addReadOnly(replaceED);
|
|
|
|
bc().addReadOnly(replacePB);
|
|
|
|
bc().setPolicy(ButtonPolicy::OkApplyCancelReadOnlyPolicy);
|
2007-04-24 14:35:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-06 19:59:13 +00:00
|
|
|
void GuiThesaurus::change_adaptor()
|
2007-04-24 14:35:15 +00:00
|
|
|
{
|
2007-09-05 20:33:29 +00:00
|
|
|
changed();
|
2007-04-24 14:35:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-06 19:59:13 +00:00
|
|
|
void GuiThesaurus::closeEvent(QCloseEvent * e)
|
2007-04-24 14:35:15 +00:00
|
|
|
{
|
2007-09-11 17:06:15 +00:00
|
|
|
slotClose();
|
2007-09-27 14:59:51 +00:00
|
|
|
GuiDialog::closeEvent(e);
|
2007-04-24 14:35:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-06 19:59:13 +00:00
|
|
|
void GuiThesaurus::entryChanged()
|
2007-04-24 14:35:15 +00:00
|
|
|
{
|
|
|
|
updateLists();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-06 19:59:13 +00:00
|
|
|
void GuiThesaurus::selectionChanged()
|
2007-04-24 14:35:15 +00:00
|
|
|
{
|
|
|
|
int const col = meaningsTV->currentColumn();
|
2007-10-06 19:59:13 +00:00
|
|
|
if (col < 0 || isBufferReadonly())
|
2007-04-24 14:35:15 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
replaceED->setText(meaningsTV->currentItem()->text(col));
|
|
|
|
replacePB->setEnabled(true);
|
2007-09-05 20:33:29 +00:00
|
|
|
changed();
|
2007-04-24 14:35:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-06 19:59:13 +00:00
|
|
|
void GuiThesaurus::itemClicked(QTreeWidgetItem * /*item*/, int /*col*/)
|
2007-04-24 14:35:15 +00:00
|
|
|
{
|
|
|
|
selectionChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-06 19:59:13 +00:00
|
|
|
void GuiThesaurus::selectionClicked(QTreeWidgetItem * item, int col)
|
2007-04-24 14:35:15 +00:00
|
|
|
{
|
|
|
|
entryED->setText(item->text(col));
|
|
|
|
selectionChanged();
|
|
|
|
updateLists();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-06 19:59:13 +00:00
|
|
|
void GuiThesaurus::updateLists()
|
2007-04-24 14:35:15 +00:00
|
|
|
{
|
|
|
|
meaningsTV->clear();
|
|
|
|
meaningsTV->setUpdatesEnabled(false);
|
|
|
|
|
2007-10-06 19:59:13 +00:00
|
|
|
Thesaurus::Meanings meanings = getMeanings(qstring_to_ucs4(entryED->text()));
|
2007-04-24 14:35:15 +00:00
|
|
|
|
|
|
|
for (Thesaurus::Meanings::const_iterator cit = meanings.begin();
|
|
|
|
cit != meanings.end(); ++cit) {
|
|
|
|
QTreeWidgetItem * i = new QTreeWidgetItem(meaningsTV);
|
|
|
|
i->setText(0, toqstr(cit->first));
|
|
|
|
meaningsTV->expandItem(i);
|
2007-12-12 19:28:07 +00:00
|
|
|
for (vector<docstring>::const_iterator cit2 = cit->second.begin();
|
2007-04-24 14:35:15 +00:00
|
|
|
cit2 != cit->second.end(); ++cit2) {
|
|
|
|
QTreeWidgetItem * i2 = new QTreeWidgetItem(i);
|
|
|
|
i2->setText(0, toqstr(*cit2));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
meaningsTV->setUpdatesEnabled(true);
|
|
|
|
meaningsTV->update();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-06 19:59:13 +00:00
|
|
|
void GuiThesaurus::updateContents()
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2007-10-06 19:59:13 +00:00
|
|
|
entryED->setText(toqstr(text_));
|
2007-09-05 20:33:29 +00:00
|
|
|
replaceED->setText("");
|
|
|
|
updateLists();
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-10-06 19:59:13 +00:00
|
|
|
void GuiThesaurus::replaceClicked()
|
|
|
|
{
|
|
|
|
replace(qstring_to_ucs4(replaceED->text()));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool GuiThesaurus::initialiseParams(string const & data)
|
|
|
|
{
|
|
|
|
text_ = from_utf8(data);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void GuiThesaurus::clearParams()
|
2006-03-05 17:24:44 +00:00
|
|
|
{
|
2007-10-06 19:59:13 +00:00
|
|
|
text_.erase();
|
2006-03-05 17:24:44 +00:00
|
|
|
}
|
|
|
|
|
2007-10-06 19:59:13 +00:00
|
|
|
|
|
|
|
void GuiThesaurus::replace(docstring const & newstr)
|
|
|
|
{
|
|
|
|
/* FIXME: this is not suitable ! We need to have a "lock"
|
|
|
|
* on a particular charpos in a paragraph that is broken on
|
|
|
|
* deletion/change !
|
|
|
|
*/
|
|
|
|
docstring const data =
|
|
|
|
replace2string(text_, newstr,
|
|
|
|
true, // case sensitive
|
|
|
|
true, // match word
|
|
|
|
false, // all words
|
|
|
|
true); // forward
|
|
|
|
dispatch(FuncRequest(LFUN_WORD_REPLACE, data));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Thesaurus::Meanings const & GuiThesaurus::getMeanings(docstring const & str)
|
|
|
|
{
|
|
|
|
if (str != laststr_)
|
|
|
|
meanings_ = thesaurus.lookup(str);
|
|
|
|
return meanings_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-11-23 09:44:02 +00:00
|
|
|
Dialog * createGuiThesaurus(GuiView & lv) { return new GuiThesaurus(lv); }
|
2007-10-06 19:59:13 +00:00
|
|
|
|
|
|
|
|
2006-03-05 17:24:44 +00:00
|
|
|
} // namespace frontend
|
|
|
|
} // namespace lyx
|
2007-04-24 14:35:15 +00:00
|
|
|
|
|
|
|
|
2007-08-31 05:53:55 +00:00
|
|
|
#include "GuiThesaurus_moc.cpp"
|