- if (text->selection.set())
- text->cursor = text->selection.end;
-
- text->clearSelection();
-
- return nextChange(bv, text, length);
+ if (!bv || ev.action != LFUN_WORD_REPLACE)
+ return;
+
+ // data is of the form
+ // "<search>
+ // <replace>
+ // <casesensitive> <matchword> <all> <forward>"
+ string search;
+ string replace;
+ string howto = split(ev.argument, search, '\n');
+ howto = split(howto, replace, '\n');
+
+ bool casesensitive = parse_bool(howto);
+ bool matchword = parse_bool(howto);
+ bool all = parse_bool(howto);
+ bool forward = parse_bool(howto);
+
+ LyXView * lv = bv->owner();
+
+ int const replace_count = all
+ ? ::replaceAll(bv, search, replace, casesensitive, matchword)
+ : ::replace(bv, search, replace, casesensitive, matchword, forward);
+
+ if (replace_count == 0) {
+ lv->message(_("String not found!"));
+ } else {
+ if (replace_count == 1) {
+ lv->message(_("String has been replaced."));
+ } else {
+ string str = tostr(replace_count);
+ str += _(" strings have been replaced.");
+ lv->message(str);
+ }
+ }