]> git.lyx.org Git - lyx.git/blobdiff - src/lyxfind.C
add missing writeNormal() methods to some insets
[lyx.git] / src / lyxfind.C
index 4feec5b0484182f1ccbc3050b813b69276848f9f..e5d0f75afbc6eb18d592aeb27ad6b1153d604f2f 100644 (file)
 #include "buffer.h"
 #include "gettext.h"
 
-// declare local prototypes here so they cannot be used without hack
-// externally and also we won't see them in the lyxfind.h file so we
-// know this are internal files!
-
-
 ///
 // locally used enum
 ///
@@ -47,8 +42,8 @@ SearchResult SearchBackward(BufferView *, LyXText * text, string const & str,
 
 int LyXReplace(BufferView * bv,
                string const & searchstr, string const & replacestr,
-               bool const & forward, bool const & casesens,
-               bool const & matchwrd, bool const & replaceall)
+               bool forward, bool casesens, bool matchwrd, bool replaceall,
+               bool once)
 {
        if (!bv->available() || bv->buffer()->isReadonly()) 
                return 0;
@@ -69,7 +64,7 @@ int LyXReplace(BufferView * bv,
        // start at top if replaceall
        bool fw = forward;
        if (replaceall) {
-               text->clearSelection(bv);
+               text->clearSelection();
                if (text->inset_owner) {
                        bv->unlockInset(bv->theLockingInset());
                        text = bv->text;
@@ -81,15 +76,24 @@ int LyXReplace(BufferView * bv,
        
        // if nothing selected or selection does not equal search string
        // search and select next occurance and return if no replaceall
-       if (searchstr!=text->selectionAsString(bv->buffer())) {
+       string str1;
+       string str2;
+       if (casesens) {
+               str1 = searchstr;
+               str2 = text->selectionAsString(bv->buffer(), false);
+       } else {
+               str1 = lowercase(searchstr);
+               str2 = lowercase(text->selectionAsString(bv->buffer(), false));
+       }
+       if (str1 != str2) {
                if (!LyXFind(bv, searchstr, fw, false, casesens, matchwrd) ||
                        !replaceall)
                {
                        return 0;
                }
        }
-   
-       bool found;
+
+       bool found = false;
        int replace_count = 0;
        do {
                bv->hideCursor();
@@ -99,8 +103,9 @@ int LyXReplace(BufferView * bv,
                bv->getLyXText()->setSelectionOverString(bv, replacestr);
                bv->update(bv->getLyXText(), BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE);
                ++replace_count;
-               found = LyXFind(bv, searchstr, fw, false, casesens, matchwrd);
-       } while (replaceall && found);
+               if (!once)
+                       found = LyXFind(bv, searchstr, fw, false, casesens, matchwrd);
+       } while (!once && replaceall && found);
    
        if (bv->focus())
                bv->showCursor();
@@ -109,9 +114,8 @@ int LyXReplace(BufferView * bv,
 }
 
 bool LyXFind(BufferView * bv,
-             string const & searchstr, bool const & forward,
-                        bool const & frominset,
-             bool const & casesens, bool const & matchwrd)
+             string const & searchstr, bool forward,
+             bool frominset, bool casesens, bool matchwrd)
 {
        if (!bv->available() || searchstr.empty())
                return false;
@@ -133,6 +137,26 @@ bool LyXFind(BufferView * bv,
                        bv->theLockingInset()->searchBackward(bv, searchstr, casesens, matchwrd);
                if (found)
                        result = SR_FOUND_NOUPDATE;
+               else {
+                       text = bv->getLyXText();
+                       Paragraph * par = text->cursor.par();
+                       Paragraph::size_type pos = text->cursor.pos();
+                       if (forward) {
+                               if (pos < par->size() - 1)
+                                       ++pos;
+                               else {
+                                       pos = 0;
+                                       par = par->next();
+                               }
+                               if (par)
+                                       text->setCursor(bv, par, pos);
+                       }
+                       if (par) {
+                               result = forward ? 
+                                       SearchForward(bv, text, searchstr, casesens, matchwrd) :
+                                       SearchBackward(bv, text, searchstr, casesens, matchwrd);
+                       }
+               }
        } else {
                result = forward ? 
                        SearchForward(bv, text, searchstr, casesens, matchwrd) :
@@ -144,7 +168,7 @@ bool LyXFind(BufferView * bv,
                // the actual text pointer could have changed!
                bv->update(bv->getLyXText(), BufferView::SELECT|BufferView::FITCUR);
                bv->toggleSelection();
-               bv->getLyXText()->clearSelection(bv);
+               bv->getLyXText()->clearSelection();
                bv->getLyXText()->setSelectionOverString(bv, searchstr);
                bv->toggleSelection(false);
                bv->update(bv->getLyXText(), BufferView::SELECT|BufferView::FITCUR);
@@ -221,23 +245,29 @@ SearchResult SearchForward(BufferView * bv, LyXText * text, string const & str,
        if (par) {
                text->setCursor(bv, par, pos);
                return SR_FOUND;
+#if 0
        } else if (text->inset_owner) {
                // test if we're inside an inset if yes unlock the inset
                // and recall us with the outside LyXText!
                bv->unlockInset((UpdatableInset *)text->inset_owner);
-               text = bv->getLyXText();
-               par = text->cursor.par();
-               pos = text->cursor.pos();
-               if (pos < par->size() - 1)
-                       ++pos;
-               else {
-                       pos = 0;
-                       par = par->next();
-               }
-               if (!par)
+               if (!bv->theLockingInset()) {
+                       text = bv->getLyXText();
+                       par = text->cursor.par();
+                       pos = text->cursor.pos();
+                       if (pos < par->size() - 1)
+                               ++pos;
+                       else {
+                               pos = 0;
+                               par = par->next();
+                       }
+                       if (!par)
+                               return SR_NOT_FOUND;
+                       text->setCursor(bv, par, pos);
+                       return SearchForward(bv, text, str, cs, mw);
+               } else {
                        return SR_NOT_FOUND;
-               text->setCursor(bv, par, pos);
-               return SearchForward(bv, text, str, cs, mw);
+               }
+#endif
        } else
                return SR_NOT_FOUND;
 }
@@ -281,13 +311,17 @@ SearchResult SearchBackward(BufferView * bv, LyXText * text,
        if (par) {
                text->setCursor(bv, par, pos);
                return SR_FOUND;
-       } else if (text->inset_owner) {
+       }
+#if 0
+       else if (text->inset_owner) {
                // test if we're inside an inset if yes unlock the inset
                // and recall us with the outside LyXText!
                bv->unlockInset((UpdatableInset *)text->inset_owner);
-               return SearchBackward(bv, bv->getLyXText(), str, cs, mw);
-       } else {
-               return SR_NOT_FOUND;
+               if (!bv->theLockingInset()) {
+                       return SearchBackward(bv, bv->getLyXText(), str, cs, mw);
+               }
        }
+#endif
+       return SR_NOT_FOUND;
 }