#include "buffer.h"
#include "gettext.h"
-// declare local prototypes here so they cannot be used without hack
-// externally and also we won't see them in the lyxfind.h file so we
-// know this are internal files!
-
-
///
// locally used enum
///
int LyXReplace(BufferView * bv,
string const & searchstr, string const & replacestr,
- bool const & forward, bool const & casesens,
- bool const & matchwrd, bool const & replaceall)
+ bool forward, bool casesens, bool matchwrd, bool replaceall,
+ bool once)
{
if (!bv->available() || bv->buffer()->isReadonly())
return 0;
// start at top if replaceall
bool fw = forward;
if (replaceall) {
- text->clearSelection(bv);
+ text->clearSelection();
if (text->inset_owner) {
bv->unlockInset(bv->theLockingInset());
text = bv->text;
// if nothing selected or selection does not equal search string
// search and select next occurance and return if no replaceall
- if (searchstr!=text->selectionAsString(bv->buffer())) {
+ string str1;
+ string str2;
+ if (casesens) {
+ str1 = searchstr;
+ str2 = text->selectionAsString(bv->buffer());
+ } else {
+ str1 = lowercase(searchstr);
+ str2 = lowercase(text->selectionAsString(bv->buffer()));
+ }
+ if (str1 != str2) {
if (!LyXFind(bv, searchstr, fw, false, casesens, matchwrd) ||
!replaceall)
{
return 0;
}
}
-
- bool found;
+
+ bool found = false;
int replace_count = 0;
do {
bv->hideCursor();
bv->getLyXText()->setSelectionOverString(bv, replacestr);
bv->update(bv->getLyXText(), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
++replace_count;
- found = LyXFind(bv, searchstr, fw, false, casesens, matchwrd);
- } while (replaceall && found);
+ if (!once)
+ found = LyXFind(bv, searchstr, fw, false, casesens, matchwrd);
+ } while (!once && replaceall && found);
if (bv->focus())
bv->showCursor();
}
bool LyXFind(BufferView * bv,
- string const & searchstr, bool const & forward,
- bool const & frominset,
- bool const & casesens, bool const & matchwrd)
+ string const & searchstr, bool forward,
+ bool frominset, bool casesens, bool matchwrd)
{
if (!bv->available() || searchstr.empty())
return false;
bv->theLockingInset()->searchBackward(bv, searchstr, casesens, matchwrd);
if (found)
result = SR_FOUND_NOUPDATE;
+ else {
+ text = bv->getLyXText();
+ Paragraph * par = text->cursor.par();
+ Paragraph::size_type pos = text->cursor.pos();
+ if (forward) {
+ if (pos < par->size() - 1)
+ ++pos;
+ else {
+ pos = 0;
+ par = par->next();
+ }
+ if (par)
+ text->setCursor(bv, par, pos);
+ }
+ if (par) {
+ result = forward ?
+ SearchForward(bv, text, searchstr, casesens, matchwrd) :
+ SearchBackward(bv, text, searchstr, casesens, matchwrd);
+ }
+ }
} else {
result = forward ?
SearchForward(bv, text, searchstr, casesens, matchwrd) :
// the actual text pointer could have changed!
bv->update(bv->getLyXText(), BufferView::SELECT|BufferView::FITCUR);
bv->toggleSelection();
- bv->getLyXText()->clearSelection(bv);
+ bv->getLyXText()->clearSelection();
bv->getLyXText()->setSelectionOverString(bv, searchstr);
bv->toggleSelection(false);
bv->update(bv->getLyXText(), BufferView::SELECT|BufferView::FITCUR);
if (par) {
text->setCursor(bv, par, pos);
return SR_FOUND;
+#if 0
} else if (text->inset_owner) {
// test if we're inside an inset if yes unlock the inset
// and recall us with the outside LyXText!
bv->unlockInset((UpdatableInset *)text->inset_owner);
- text = bv->getLyXText();
- par = text->cursor.par();
- pos = text->cursor.pos();
- if (pos < par->size() - 1)
- ++pos;
- else {
- pos = 0;
- par = par->next();
- }
- if (!par)
+ if (!bv->theLockingInset()) {
+ text = bv->getLyXText();
+ par = text->cursor.par();
+ pos = text->cursor.pos();
+ if (pos < par->size() - 1)
+ ++pos;
+ else {
+ pos = 0;
+ par = par->next();
+ }
+ if (!par)
+ return SR_NOT_FOUND;
+ text->setCursor(bv, par, pos);
+ return SearchForward(bv, text, str, cs, mw);
+ } else {
return SR_NOT_FOUND;
- text->setCursor(bv, par, pos);
- return SearchForward(bv, text, str, cs, mw);
+ }
+#endif
} else
return SR_NOT_FOUND;
}
if (par) {
text->setCursor(bv, par, pos);
return SR_FOUND;
- } else if (text->inset_owner) {
+ }
+#if 0
+ else if (text->inset_owner) {
// test if we're inside an inset if yes unlock the inset
// and recall us with the outside LyXText!
bv->unlockInset((UpdatableInset *)text->inset_owner);
- return SearchBackward(bv, bv->getLyXText(), str, cs, mw);
- } else {
- return SR_NOT_FOUND;
+ if (!bv->theLockingInset()) {
+ return SearchBackward(bv, bv->getLyXText(), str, cs, mw);
+ }
}
+#endif
+ return SR_NOT_FOUND;
}