]> git.lyx.org Git - lyx.git/blobdiff - src/lyxfind.C
more cursor dispatch
[lyx.git] / src / lyxfind.C
index 0f9747888c21bcc962e2c85b179cc3539286fd2c..b7869ba32725a8a26681cd2bc73816d7d131064d 100644 (file)
@@ -16,6 +16,7 @@
 #include "lyxfind.h"
 
 #include "buffer.h"
+#include "cursor.h"
 #include "BufferView.h"
 #include "debug.h"
 #include "iterators.h"
@@ -38,8 +39,7 @@ using lyx::support::lowercase;
 using lyx::support::uppercase;
 using lyx::support::split;
 
-using bv_funcs::put_selection_at;
-
+using std::advance;
 using std::ostringstream;
 using std::string;
 
@@ -79,7 +79,7 @@ namespace lyx {
 namespace find {
 
 string const find2string(string const & search,
-                        bool casesensitive, bool matchword, bool forward)
+                        bool casesensitive, bool matchword, bool forward)
 {
        ostringstream ss;
        ss << search << '\n'
@@ -89,7 +89,7 @@ string const find2string(string const & search,
 
        return ss.str();
 }
+
 
 string const replace2string(string const & search, string const & replace,
                            bool casesensitive, bool matchword,
@@ -107,9 +107,9 @@ string const replace2string(string const & search, string const & replace,
 }
 
 
-void find(FuncRequest const & ev)
+void find(BufferView * bv, FuncRequest const & ev)
 {
-       if (!ev.view() || ev.action != LFUN_WORD_FIND)
+       if (!bv || ev.action != LFUN_WORD_FIND)
                return;
 
        // data is of the form
@@ -122,18 +122,17 @@ void find(FuncRequest const & ev)
        bool matchword     = parse_bool(howto);
        bool forward       = parse_bool(howto);
 
-       BufferView * bv = ev.view();
        bool const found = ::find(bv, search,
-                                 forward, casesensitive, matchword);
+                                 casesensitive, matchword, forward);
 
        if (!found)
                bv->owner()->message(_("String not found!"));
 }
 
 
-void replace(FuncRequest const & ev)
+void replace(BufferView * bv, FuncRequest const & ev)
 {
-       if (!ev.view() || ev.action != LFUN_WORD_REPLACE)
+       if (!bv || ev.action != LFUN_WORD_REPLACE)
                return;
 
        // data is of the form
@@ -150,7 +149,6 @@ void replace(FuncRequest const & ev)
        bool all           = parse_bool(howto);
        bool forward       = parse_bool(howto);
 
-       BufferView * bv = ev.view();
        LyXView * lv = bv->owner();
 
        int const replace_count = all ?
@@ -158,7 +156,7 @@ void replace(FuncRequest const & ev)
                             casesensitive, matchword) :
                ::replace(bv, search, replace,
                          casesensitive, matchword, forward);
+
        if (replace_count == 0) {
                lv->message(_("String not found!"));
        } else {
@@ -183,10 +181,10 @@ bool findNextChange(BufferView * bv)
 
        if (!findChange(cur, endit))
                return false;
-       
+
        ParagraphList::iterator pit = cur.pit();
        pos_type pos = cur.pos();
-       
+
        Change orig_change = pit->lookupChangeFull(pos);
        pos_type parsize = pit->size();
        pos_type end = pos;
@@ -202,7 +200,7 @@ bool findNextChange(BufferView * bv)
                }
        }
        pos_type length = end - pos;
-       put_selection_at(bv, cur, length, true);
+       bv->putSelectionAt(cur, length, true);
        return true;
 }
 
@@ -212,7 +210,7 @@ bool findNextChange(BufferView * bv)
 
 namespace {
 
-class MatchString
+class MatchString : public std::binary_function<Paragraph, lyx::pos_type, bool>
 {
 public:
        MatchString(string const & str, bool cs, bool mw)
@@ -246,7 +244,7 @@ public:
 
                return true;
        }
-       
+
 private:
        // search string
        string str;
@@ -283,7 +281,7 @@ bool findBackwards(PosIterator & cur, PosIterator const & beg,
 bool findChange(PosIterator & cur, PosIterator const & end)
 {
        for (; cur != end; ++cur) {
-               if ((!cur.pit()->size() || !cur.at_end())
+               if ((cur.pit()->empty() || !cur.at_end())
                    && cur.pit()->lookupChange(cur.pos()) != Change::UNCHANGED)
                        return true;
        }
@@ -317,7 +315,7 @@ bool find(BufferView * bv, string const & searchstr, bool cs, bool mw, bool fw)
                : findBackwards(cur, beg, match);
 
        if (found)
-               put_selection_at(bv, cur, searchstr.length(), !fw);
+               bv->putSelectionAt(cur, searchstr.length(), !fw);
 
        return found;
 }
@@ -331,9 +329,9 @@ int replaceAll(BufferView * bv,
 
        if (!searchAllowed(bv, searchstr) || buf.isReadonly())
                return 0;
-       
-       recordUndo(Undo::ATOMIC, bv->text(), 0, buf.paragraphs().size() - 1);
-       
+
+       recordUndoFullDocument(bv->cursor());
+
        PosIterator cur = buf.pos_iterator_begin();
        PosIterator const end = buf.pos_iterator_end();
        MatchString const match(searchstr, cs, mw);
@@ -354,7 +352,7 @@ int replaceAll(BufferView * bv,
 
        PosIterator beg = buf.pos_iterator_begin();
        bv->text()->init(bv);
-       put_selection_at(bv, beg, 0, false);
+       bv->putSelectionAt(beg, 0, false);
        if (num)
                buf.markDirty();
        return num;
@@ -362,7 +360,7 @@ int replaceAll(BufferView * bv,
 
 
 bool stringSelected(BufferView * bv,
-                   string const & searchstr, 
+                   string const & searchstr,
                    bool cs, bool mw, bool fw)
 {
        LyXText * text = bv->getLyXText();
@@ -394,12 +392,11 @@ int replace(BufferView * bv,
 
        text->replaceSelectionWithString(replacestr);
        text->setSelectionRange(replacestr.length());
-       text->cursor = fw ? text->selEnd() : text->selStart();
-
+       bv->cursor().current() = fw ? bv->cursor().selEnd() : bv->cursor().selBegin();
        bv->buffer()->markDirty();
        find(bv, searchstr, cs, mw, fw);
        bv->update();
-       
+
        return 1;
 }