]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/GuiThesaurus.cpp
* fix spelling in comments to please John.
[lyx.git] / src / frontends / qt4 / GuiThesaurus.cpp
index 083ed2eac0d7d07102a1475d2bf1bd3ea7a41add..6d6269e6f5e34093c865b47d6f87086e9a81cb11 100644 (file)
@@ -105,15 +105,18 @@ void GuiThesaurus::selectionChanged()
                return;
 
        QString item = meaningsTV->currentItem()->text(col);
-       // cut out the classification in brackets
-       // (as in "hominid (generic term)")
-       // FIXME: not ideal yet. We need to cut off classifications
-       // at the beginning as well 
-       // (as in "(noun) man" and "(noun) male (generic term)")
+       // cut out the classification in brackets:
+       // "hominid (generic term)" -> "hominid"
        QRegExp re("^([^\\(\\)]+)\\b\\(?.*\\)?.*$");
+       // This is for items with classifications at the beginning:
+       // "(noun) man" -> "man"; "(noun) male (generic term)" -> "male"
+       QRegExp rex("^(\\(.+\\))\\s*([^\\(\\)]+)\\s*\\(?.*\\)?.*$");
        int pos = re.indexIn(item);
        if (pos > -1)
                item = re.cap(1).trimmed();
+       pos = rex.indexIn(item);
+       if (pos > -1)
+               item = rex.cap(2).trimmed();
        replaceED->setText(item);
        replacePB->setEnabled(true);
        changed();
@@ -129,15 +132,18 @@ void GuiThesaurus::itemClicked(QTreeWidgetItem * /*item*/, int /*col*/)
 void GuiThesaurus::selectionClicked(QTreeWidgetItem * item, int col)
 {
        QString str = item->text(col);
-       // cut out the classification in brackets
-       // (as in "hominid (generic term)")
-       // FIXME: not ideal yet. We need to cut off classifications
-       // at the beginning as well 
-       // (as in "(noun) man" and "(noun) male (generic term)")
+       // cut out the classification in brackets:
+       // "hominid (generic term)" -> "hominid"
        QRegExp re("^([^\\(\\)]+)\\b\\(?.*\\)?.*$");
+       // This is for items with classifications at the beginning:
+       // "(noun) man" -> "man"; "(noun) male (generic term)" -> "male"
+       QRegExp rex("^(\\(.+\\))\\s*([^\\(\\)]+)\\s*\\(?.*\\)?.*$");
        int pos = re.indexIn(str);
        if (pos > -1)
                str = re.cap(1).trimmed();
+       pos = rex.indexIn(str);
+       if (pos > -1)
+               str = rex.cap(2).trimmed();
        entryCO->insertItem(0, str);
        entryCO->setCurrentIndex(0);
 
@@ -241,7 +247,7 @@ void GuiThesaurus::replace(docstring const & newstr)
         * deletion/change !
         */
        docstring const data =
-               replace2string(text_, newstr,
+               replace2string(newstr, text_,
                                     true,  // case sensitive
                                     true,  // match word
                                     false, // all words