]> git.lyx.org Git - features.git/commitdiff
Adding wrap-around pop-up question to simple find and replace dialog (fixing enhancem...
authorTommaso Cucinotta <tommaso@lyx.org>
Sun, 21 Jul 2013 16:51:53 +0000 (17:51 +0100)
committerTommaso Cucinotta <tommaso@lyx.org>
Sun, 21 Jul 2013 16:51:53 +0000 (17:51 +0100)
src/BufferView.cpp
src/frontends/qt4/GuiSearch.cpp
src/frontends/qt4/GuiSearch.h

index d26f9496870c54021cd68e9bdff60092592e54ed..84194605a59200d3a6f816f22aa40e02d73e6720 100644 (file)
@@ -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;
        }
index a8f10e7c63cf59b1169b0c5b59911e2cb495c9d8..295bf42e4fc856f0997eb5a2e6b8959fb4226a75 100644 (file)
 
 #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>
@@ -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); }
 
 
index b56555307456b50c33b821213939d26b62c40721..bd8231996a88572d95bdb590fda8008366f1841d 100644 (file)
@@ -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);