docstring const data =
find2string(searched_string, true, false, fw);
bool found = lyxfind(this, FuncRequest(LFUN_WORD_FIND, data));
- if (found)
+ if (found) {
dr.screenUpdate(Update::Force | Update::FitCursor);
+ cur.dispatched();
+ dispatched = true;
+ } else {
+ cur.undispatched();
+ dispatched = false;
+ }
break;
}
lyx::dispatch(FuncRequest(LFUN_DIALOG_SHOW, "findreplace"));
break;
}
- if (lyxfind(this, req))
+ if (lyxfind(this, req)) {
dr.screenUpdate(Update::Force | Update::FitCursor);
- else
- message(_("String not found."));
+ cur.dispatched();
+ dispatched = true;
+ } else {
+ cur.undispatched();
+ dispatched = false;
+ }
d->search_request_cache_ = req;
break;
}
if (lyxreplace(this, cmd, has_deleted)) {
dr.forceBufferUpdate();
dr.screenUpdate(Update::Force | Update::FitCursor);
+ cur.dispatched();
+ dispatched = true;
+ } else {
+ cur.undispatched();
+ dispatched = false;
}
break;
}
#include <config.h>
-#include "GuiSearch.h"
-
+#include "lyxfind.h"
#include "qt_helpers.h"
-
#include "FuncRequest.h"
-#include "lyxfind.h"
+#include "BufferView.h"
+#include "Buffer.h"
+#include "Cursor.h"
+#include "GuiSearch.h"
+#include "GuiView.h"
+
+#include "support/gettext.h"
+#include "frontends/alert.h"
#include <QLineEdit>
#include <QShowEvent>
}
+void GuiSearch::wrap_dispatch(const FuncRequest & func, bool forward) {
+ dispatch(func);
+
+ BufferView * bv = const_cast<BufferView *>(bufferview());
+ GuiView & lv = *const_cast<GuiView *>(&lyxview());
+ if (!bv->cursor().result().dispatched()) {
+ docstring q;
+ if (forward)
+ q = _("End of file reached while searching forward.\n"
+ "Continue searching from the beginning?");
+ else
+ q = _("End of file reached while searching backward.\n"
+ "Continue searching from the end?");
+ int wrap_answer = frontend::Alert::prompt(_("Wrap search?"),
+ q, 0, 1, _("&Yes"), _("&No"));
+ if (wrap_answer == 0) {
+ if (forward) {
+ bv->cursor().clear();
+ bv->cursor().push_back(CursorSlice(bv->buffer().inset()));
+ } else {
+ bv->cursor().setCursor(doc_iterator_end(&bv->buffer()));
+ bv->cursor().backwardPos();
+ }
+ bv->clearSelection();
+ dispatch(func);
+ if (bv->cursor().result().dispatched())
+ return;
+ }
+ lv.message(_("String not found."));
+ }
+}
+
+
void GuiSearch::find(docstring const & search, bool casesensitive,
bool matchword, bool forward)
{
docstring const data =
find2string(search, casesensitive, matchword, forward);
- dispatch(FuncRequest(LFUN_WORD_FIND, data));
+ wrap_dispatch(FuncRequest(LFUN_WORD_FIND, data), forward);
}
docstring const data =
replace2string(replace, search, casesensitive,
matchword, all, forward);
- dispatch(FuncRequest(LFUN_WORD_REPLACE, data));
+ wrap_dispatch(FuncRequest(LFUN_WORD_REPLACE, data), forward);
}
+
Dialog * createGuiSearch(GuiView & lv) { return new GuiSearch(lv); }
void dispatchParams() {}
bool isBufferDependent() const { return true; }
+ /// Dispatches repeatedly func with wrap around question
+ void wrap_dispatch(const FuncRequest & func, bool forward);
+
/// Searches occurence of string
void find(docstring const & search,
bool casesensitive, bool matchword, bool forward);