mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-22 01:59:02 +00:00
Adding wrap-around pop-up question to simple find and replace dialog (fixing enhancement request #1262).
This commit is contained in:
parent
bb2a75b778
commit
2a86379ea7
@ -1513,8 +1513,14 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
|
||||
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;
|
||||
}
|
||||
|
||||
@ -1526,10 +1532,14 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
|
||||
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;
|
||||
}
|
||||
@ -1551,6 +1561,11 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
|
||||
if (lyxreplace(this, cmd, has_deleted)) {
|
||||
dr.forceBufferUpdate();
|
||||
dr.screenUpdate(Update::Force | Update::FitCursor);
|
||||
cur.dispatched();
|
||||
dispatched = true;
|
||||
} else {
|
||||
cur.undispatched();
|
||||
dispatched = false;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -12,12 +12,17 @@
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include "GuiSearch.h"
|
||||
|
||||
#include "qt_helpers.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 <QShowEvent>
|
||||
@ -115,12 +120,45 @@ void GuiSearch::replaceallClicked()
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
@ -131,9 +169,10 @@ void GuiSearch::replace(docstring const & search, docstring const & replace,
|
||||
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); }
|
||||
|
||||
|
||||
|
@ -40,6 +40,9 @@ private:
|
||||
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);
|
||||
|
Loading…
Reference in New Issue
Block a user