// FIXME: it would be nice if sorting was enabled/disabled via a checkbox.
language_model->sort(0);
languageCO->setModel(language_model);
+ languageCO->setModelColumn(2);
bc().setCancel(closePB);
bc().setApply(replacePB);
bc().setPolicy(ButtonPolicy::OkApplyCancelReadOnlyPolicy);
}
-
+void GuiThesaurus::checkStatus()
+{
+ if (!isBufferAvailable()) {
+ // deactivate the thesaurus if we have no buffer
+ enableView(false);
+ return;
+ }
+ updateView();
+}
+
void GuiThesaurus::change_adaptor()
{
changed();
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);
+ replacePB->setEnabled(!isBufferReadonly());
changed();
}
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);
void GuiThesaurus::updateLists()
{
meaningsTV->clear();
+
+ if (entryCO->currentText().isEmpty())
+ return;
+
meaningsTV->setUpdatesEnabled(false);
QString const lang = languageCO->itemData(
}
meaningsTV->setEnabled(true);
lookupPB->setEnabled(true);
- replaceED->setEnabled(true);
- replacePB->setEnabled(true);
+ bool const readonly = isBufferReadonly();
+ replaceED->setEnabled(!readonly);
+ replacePB->setEnabled(!readonly);
}
if (meanings.empty()) {
* deletion/change !
*/
docstring const data =
- replace2string(text_, newstr,
+ replace2string(newstr, text_,
true, // case sensitive
true, // match word
false, // all words