#include <config.h>
-#include "GuiSearch.h"
-
-#include "FuncRequest.h"
#include "lyxfind.h"
-
#include "qt_helpers.h"
+#include "FuncRequest.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 <QCloseEvent>
#include <QShowEvent>
-using std::string;
-
+using namespace std;
namespace lyx {
namespace frontend {
if (box->itemText(i) == text)
return;
- box->addItem(text);
+ box->insertItem(0, text);
}
GuiSearch::GuiSearch(GuiView & lv)
- : GuiDialog(lv, "findreplace")
+ : GuiDialog(lv, "findreplace", qt_("Find and Replace"))
{
setupUi(this);
- setViewTitle(_("Find and Replace"));
connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose()));
connect(findPB, SIGNAL(clicked()), this, SLOT(findClicked()));
void GuiSearch::showEvent(QShowEvent * e)
{
+ findPB->setFocus();
findCO->lineEdit()->selectAll();
GuiDialog::showEvent(e);
}
-void GuiSearch::closeEvent(QCloseEvent * e)
-{
- slotClose();
- GuiDialog::closeEvent(e);
-}
-
-
void GuiSearch::findChanged()
{
if (findCO->currentText().isEmpty()) {
}
+void GuiSearch::wrap_dispatch(const FuncRequest & func, bool forward)
+{
+ dispatch(func);
+
+ BufferView * bv = const_cast<BufferView *>(bufferview());
+
+ if (!bv->cursor().result().dispatched()) {
+ GuiView & lv = *const_cast<GuiView *>(&lyxview());
+ DocIterator cur_orig(bv->cursor());
+ docstring q;
+ if (forward)
+ q = _("End of file reached while searching forward.\n"
+ "Continue searching from the beginning?");
+ else
+ q = _("Beginning 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;
+ }
+ bv->cursor().setCursor(cur_orig);
+ 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);
}
bool forward, bool all)
{
docstring const data =
- replace2string(search, replace, casesensitive,
+ 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); }
} // namespace lyx
-#include "GuiSearch_moc.cpp"
+#include "moc_GuiSearch.cpp"