+} // namespace anon
+
+
+namespace lyx {
+namespace find {
+
+string const find2string(string const & search,
+ bool casesensitive, bool matchword, bool forward)
+{
+ ostringstream ss;
+ ss << search << '\n'
+ << int(casesensitive) << ' '
+ << int(matchword) << ' '
+ << int(forward);
+ return ss.str();
+}
+
+
+string const replace2string(string const & search, string const & replace,
+ bool casesensitive, bool matchword,
+ bool all, bool forward)
+{
+ ostringstream ss;
+ ss << search << '\n'
+ << replace << '\n'
+ << int(casesensitive) << ' '
+ << int(matchword) << ' '
+ << int(all) << ' '
+ << int(forward);
+ return ss.str();
+}
+
+
+void find(BufferView * bv, FuncRequest const & ev)
+{
+ if (!bv || ev.action != LFUN_WORD_FIND)
+ return;
+
+ lyxerr << "find called, cmd: " << ev << std::endl;
+
+ // data is of the form
+ // "<search>
+ // <casesensitive> <matchword> <forward>"
+ string search;
+ string howto = split(ev.argument, search, '\n');
+
+ bool casesensitive = parse_bool(howto);
+ bool matchword = parse_bool(howto);
+ bool forward = parse_bool(howto);
+
+ bool const found = ::find(bv, search,
+ casesensitive, matchword, forward);
+
+ if (!found)
+ bv->owner()->message(_("String not found!"));
+}
+
+
+void replace(BufferView * bv, FuncRequest const & ev)
+{
+ 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);
+ }
+ }
+}
+