]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/GuiThesaurus.cpp
Complete the removal of the embedding stuff. Maybe. It's hard to be sure we got every...
[lyx.git] / src / frontends / qt4 / GuiThesaurus.cpp
index aab037436b6dc98f11a868cc420c4841bc686a9b..bd3e1794726233dd9be26f704a4466af4d918c2d 100644 (file)
 
 #include "GuiThesaurus.h"
 
-#include "ControlThesaurus.h"
 #include "qt_helpers.h"
-#include "debug.h"
 
-#include <QCloseEvent>
+#include "FuncRequest.h"
+#include "lyxfind.h"
+
+#include "support/debug.h"
+#include "support/gettext.h"
+
 #include <QHeaderView>
 #include <QLineEdit>
 #include <QPushButton>
 #include <QTreeWidget>
 #include <QTreeWidgetItem>
 
-using std::string;
 
+using namespace std;
 
 namespace lyx {
 namespace frontend {
 
-GuiThesaurusDialog::GuiThesaurusDialog(LyXView & lv)
-       : GuiDialog(lv, "thesaurus")
+GuiThesaurus::GuiThesaurus(GuiView & lv)
+       : GuiDialog(lv, "thesaurus", qt_("Thesaurus"))
 {
        setupUi(this);
-       setViewTitle(_("Thesaurus"));
-       setController(new ControlThesaurus(*this));
 
        meaningsTV->setColumnCount(1);
        meaningsTV->header()->hide();
@@ -43,8 +44,8 @@ GuiThesaurusDialog::GuiThesaurusDialog(LyXView & lv)
                this, SLOT(slotClose()));
        connect(replaceED, SIGNAL(returnPressed()),
                this, SLOT(replaceClicked()));
-       connect(replaceED, SIGNAL(textChanged(const QString &)),
-               this, SLOT(change_adaptor() ) );
+       connect(replaceED, SIGNAL(textChanged(QString)),
+               this, SLOT(change_adaptor()));
        connect(entryED, SIGNAL(returnPressed()),
                this, SLOT(entryChanged()));
        connect(replacePB, SIGNAL(clicked()),
@@ -64,34 +65,22 @@ GuiThesaurusDialog::GuiThesaurusDialog(LyXView & lv)
 }
 
 
-ControlThesaurus & GuiThesaurusDialog::controller() const
-{
-       return static_cast<ControlThesaurus &>(GuiDialog::controller());
-}
-
-void GuiThesaurusDialog::change_adaptor()
+void GuiThesaurus::change_adaptor()
 {
        changed();
 }
 
 
-void GuiThesaurusDialog::closeEvent(QCloseEvent * e)
-{
-       slotWMHide();
-       e->accept();
-}
-
-
-void GuiThesaurusDialog::entryChanged()
+void GuiThesaurus::entryChanged()
 {
        updateLists();
 }
 
 
-void GuiThesaurusDialog::selectionChanged()
+void GuiThesaurus::selectionChanged()
 {
        int const col = meaningsTV->currentColumn();
-       if (col<0 || readOnly())
+       if (col < 0 || isBufferReadonly())
                return;
 
        replaceED->setText(meaningsTV->currentItem()->text(col));
@@ -100,13 +89,13 @@ void GuiThesaurusDialog::selectionChanged()
 }
 
 
-void GuiThesaurusDialog::itemClicked(QTreeWidgetItem * /*item*/, int /*col*/)
+void GuiThesaurus::itemClicked(QTreeWidgetItem * /*item*/, int /*col*/)
 {
        selectionChanged();
 }
 
 
-void GuiThesaurusDialog::selectionClicked(QTreeWidgetItem * item, int col)
+void GuiThesaurus::selectionClicked(QTreeWidgetItem * item, int col)
 {
        entryED->setText(item->text(col));
        selectionChanged();
@@ -114,19 +103,19 @@ void GuiThesaurusDialog::selectionClicked(QTreeWidgetItem * item, int col)
 }
 
 
-void GuiThesaurusDialog::updateLists()
+void GuiThesaurus::updateLists()
 {
        meaningsTV->clear();
        meaningsTV->setUpdatesEnabled(false);
 
-       Thesaurus::Meanings meanings = controller().getMeanings(qstring_to_ucs4(entryED->text()));
+       Thesaurus::Meanings meanings = getMeanings(qstring_to_ucs4(entryED->text()));
 
        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);
-               for (std::vector<docstring>::const_iterator cit2 = cit->second.begin();
+               for (vector<docstring>::const_iterator cit2 = cit->second.begin();
                        cit2 != cit->second.end(); ++cit2) {
                                QTreeWidgetItem * i2 = new QTreeWidgetItem(i);
                                i2->setText(0, toqstr(*cit2));
@@ -138,19 +127,60 @@ void GuiThesaurusDialog::updateLists()
 }
 
 
-void GuiThesaurusDialog::update_contents()
+void GuiThesaurus::updateContents()
 {
-       entryED->setText(toqstr(controller().text()));
+       entryED->setText(toqstr(text_));
        replaceED->setText("");
        updateLists();
 }
 
 
-void GuiThesaurusDialog::replaceClicked()
+void GuiThesaurus::replaceClicked()
+{
+       replace(qstring_to_ucs4(replaceED->text()));
+}
+
+
+bool GuiThesaurus::initialiseParams(string const & data)
+{
+       text_ = from_utf8(data);
+       return true;
+}
+
+
+void GuiThesaurus::clearParams()
+{
+       text_.erase();
+}
+
+
+void GuiThesaurus::replace(docstring const & newstr)
 {
-       controller().replace(qstring_to_ucs4(replaceED->text()));
+       /* 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_;
+}
+
+
+Dialog * createGuiThesaurus(GuiView & lv) { return new GuiThesaurus(lv); }
+
+
 } // namespace frontend
 } // namespace lyx