#include "lyxfind.h"
#include "Buffer.h"
+#include "BufferParams.h"
#include "Cursor.h"
#include "CutAndPaste.h"
#include "buffer_funcs.h"
#include "BufferView.h"
-#include "debug.h"
+#include "Changes.h"
+#include "support/debug.h"
#include "FuncRequest.h"
-#include "gettext.h"
+#include "support/gettext.h"
#include "Text.h"
#include "Paragraph.h"
#include "ParIterator.h"
-#include "Undo.h"
#include "frontends/alert.h"
#include "support/convert.h"
#include "support/docstream.h"
+#include "support/lstrings.h"
-namespace lyx {
-
-using support::compare_no_case;
-using support::uppercase;
-using support::split;
-
-using std::advance;
+using namespace std;
+using namespace lyx::support;
+namespace lyx {
namespace {
}
-class MatchString : public std::binary_function<Paragraph, pos_type, bool>
+class MatchString : public binary_function<Paragraph, pos_type, bool>
{
public:
MatchString(docstring const & str, bool cs, bool mw)
// del specifies whether deleted strings in ct mode will be considered
bool operator()(Paragraph const & par, pos_type pos, bool del = true) const
{
- docstring::size_type const size = str.length();
- pos_type i = 0;
- pos_type const parsize = par.size();
- for (i = 0; pos + i < parsize; ++i) {
- if (docstring::size_type(i) >= size)
- break;
- if (cs && str[i] != par.getChar(pos + i))
- break;
- if (!cs && uppercase(str[i]) != uppercase(par.getChar(pos + i)))
- break;
- if (!del && par.isDeleted(pos + i))
- break;
- }
-
- if (size != docstring::size_type(i))
- return false;
-
- // if necessary, check whether string matches word
- if (mw) {
- if (pos > 0 && par.isLetter(pos - 1))
- return false;
- if (pos + pos_type(size) < parsize
- && par.isLetter(pos + size))
- return false;
- }
-
- return true;
+ return par.find(str, cs, mw, pos, del);
}
private:
}
-bool searchAllowed(BufferView * bv, docstring const & str)
+bool searchAllowed(BufferView * /*bv*/, docstring const & str)
{
if (str.empty()) {
- frontend::Alert::error(_("Search error"),
- _("Search string is empty"));
+ frontend::Alert::error(_("Search error"), _("Search string is empty"));
return false;
}
- return bv->buffer();
+ return true;
}
-bool find(BufferView * bv, docstring const & searchstr, bool cs, bool mw, bool fw,
- bool find_del = true)
+bool find(BufferView * bv, docstring const & searchstr,
+ bool cs, bool mw, bool fw, bool find_del = true)
{
if (!searchAllowed(bv, searchstr))
return false;
docstring const & searchstr, docstring const & replacestr,
bool cs, bool mw)
{
- Buffer & buf = *bv->buffer();
+ Buffer & buf = bv->buffer();
if (!searchAllowed(bv, searchstr) || buf.isReadonly())
return 0;
- recordUndoFullDocument(bv);
+ bv->cursor().recordUndoFullDocument();
MatchString const match(searchstr, cs, mw);
int num = 0;
int replace(BufferView * bv, docstring const & searchstr,
docstring const & replacestr, bool cs, bool mw, bool fw)
{
- if (!searchAllowed(bv, searchstr) || bv->buffer()->isReadonly())
+ if (!searchAllowed(bv, searchstr) || bv->buffer().isReadonly())
return 0;
if (!stringSelected(bv, searchstr, cs, mw, fw))
Cursor & cur = bv->cursor();
cap::replaceSelectionWithString(cur, replacestr, fw);
- bv->buffer()->markDirty();
+ bv->buffer().markDirty();
find(bv, searchstr, cs, mw, fw, false);
- bv->update();
+ bv->buffer().updateMacros();
+ bv->processUpdateFlags(Update::Force | Update::FitCursor);
return 1;
}
if (!bv || ev.action != LFUN_WORD_FIND)
return;
- //lyxerr << "find called, cmd: " << ev << std::endl;
+ //lyxerr << "find called, cmd: " << ev << endl;
// data is of the form
// "<search>
bool all = parse_bool(howto);
bool forward = parse_bool(howto);
- Buffer * buf = bv->buffer();
-
if (!has_deleted) {
int const replace_count = all
? replaceAll(bv, search, rplc, casesensitive, matchword)
: replace(bv, search, rplc, casesensitive, matchword, forward);
+ Buffer & buf = bv->buffer();
if (replace_count == 0) {
// emit message signal.
- buf->message(_("String not found!"));
+ buf.message(_("String not found!"));
} else {
if (replace_count == 1) {
// emit message signal.
- buf->message(_("String has been replaced."));
+ buf.message(_("String has been replaced."));
} else {
docstring str = convert<docstring>(replace_count);
str += _(" strings have been replaced.");
// emit message signal.
- buf->message(str);
+ buf.message(str);
}
}
} else {
bool findNextChange(BufferView * bv)
{
- if (!bv->buffer())
- return false;
-
DocIterator cur = bv->cursor();
if (!findChange(cur))