]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/controllers/ControlThesaurus.C
fix crash due to invalidated iterator
[lyx.git] / src / frontends / controllers / ControlThesaurus.C
index 03f82ed0e1b4d5087106d0f319086dd36036ebad..f99770f071409a4eb84bfbb4a39ca6020c8c1a0c 100644 (file)
@@ -1,43 +1,40 @@
 /**
  * \file ControlThesaurus.C
- * Copyright 2001 the LyX Team
- * Read the file COPYING
+ * 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>
 
-#ifdef __GNUG__
-#pragma implementation
-#endif
-
-#include "ViewBase.h"
-#include "ButtonControllerBase.h"
 #include "ControlThesaurus.h"
-#include "Dialogs.h"
-#include "Liason.h"
-#include "LyXView.h"
+
 #include "lyxfind.h"
-#include "buffer.h"
-#include "debug.h"
-#include "gettext.h"
-#include "BufferView.h"
+#include "funcrequest.h"
+
+using std::string;
 
-using Liason::setMinibuffer;
-using SigC::slot;
+namespace lyx {
+namespace frontend {
 
-ControlThesaurus::ControlThesaurus(LyXView & lv, Dialogs & d)
-       : ControlDialog<ControlConnectBD>(lv, d)
+ControlThesaurus::ControlThesaurus(Dialog & parent)
+       : Dialog::Controller(parent)
+{}
+
+
+bool ControlThesaurus::initialiseParams(string const & data)
 {
-       d_.showThesaurus.connect(SigC::slot(this, &ControlThesaurus::showEntry));
+       oldstr_ = data;
+       return true;
 }
 
 
-void ControlThesaurus::showEntry(string const & entry)
+void ControlThesaurus::clearParams()
 {
-       oldstr_ = entry;
-       show();
+       oldstr_.erase();
 }
 
 
@@ -47,32 +44,22 @@ void ControlThesaurus::replace(string const & newstr)
         * on a particular charpos in a paragraph that is broken on
         * deletion/change !
         */
-       int const replace_count = LyXReplace(lv_.view(), oldstr_, newstr,
-                                       true, true, true, false, true);
-
-       oldstr_ = newstr;
-
-       if (replace_count == 0)
-               setMinibuffer(&lv_, _("String not found!"));
-       else
-               setMinibuffer(&lv_, _("String has been replaced."));
+       string const data =
+               find::replace2string(oldstr_, newstr,
+                                    true,  // case sensitive
+                                    true,  // match word
+                                    false, // all words
+                                    true); // forward
+       kernel().dispatch(FuncRequest(LFUN_WORD_REPLACE, data));
 }
 
 
-std::vector<string> ControlThesaurus::getEntries(string const & str, Thesaurus::POS pos)
+Thesaurus::Meanings const & ControlThesaurus::getMeanings(string const & str)
 {
        if (str != laststr_)
-               entries_ = thesaurus.lookup(str);
-
-       laststr_ = str;
-
-       std::vector<string> strs;
-
-       for (std::vector<Thesaurus::ThesaurusEntry>::const_iterator it = entries_.begin();
-               it != entries_.end(); ++it) {
-               if (it->pos & pos)
-                       strs.push_back(it->entry);
-       }
-
-       return strs;
+               meanings_ = thesaurus.lookup(str);
+       return meanings_;
 }
+
+} // namespace frontend
+} // namespace lyx