]> git.lyx.org Git - lyx.git/blobdiff - src/lyxfr1.C
the buffer patch, moved Buffer::text to BufferView, moved Buffer::update(short) to...
[lyx.git] / src / lyxfr1.C
index 1e4cee8ca241f558cff4906669f29ca915ba1323..ea73c58e69e2fa09620383ba920438e59ba7ac67 100644 (file)
@@ -1,12 +1,12 @@
 /* This file is part of
- * ======================================================
+ * ====================================================== 
  * 
  *           LyX, The Document Processor
  *      
  *           Copyright 1995 Matthias Ettrich,
  *           Copyright 1995-1999 The LyX Team.
  *
- * ======================================================*/
+ * ====================================================== */
 
 #include <config.h>
 
@@ -33,6 +33,7 @@
 #include "lyx_gui_misc.h"
 #include "minibuffer.h"
 #include "support/lstrings.h"
+#include "support/textutils.h"
 
 extern BufferView *current_view; // called too many times in this file...
 extern MiniBuffer *minibuffer;
@@ -42,8 +43,6 @@ const int LYXSEARCH_MAXLEN =  128;
 
 // function prototypes
 
-bool IsLetterCharOrDigit(char ch);
-
 // If nothing selected, select the word at the cursor.
 // Returns the current selection
 // Note: this function should be in LyXText!
@@ -59,10 +58,6 @@ void SetSelectionOverLenChars(LyXText *lt, int len);
 
 //-------------------------------------------------------------
 
-bool IsLetterCharOrDigit(char ch)
-{
-       return IsLetterChar(ch) || isdigit(ch);
-}
 
 
 // Returns the current selection. If nothing is selected or if the selection
@@ -75,17 +70,10 @@ string const GetCurrentSelectionAsString(LyXText * lt)
        LyXParagraph * par = lt->cursor.par;
        if (lt->selection && (lt->sel_cursor.par == par)) {
                // (selected) and (begin/end in same paragraph)
-#ifdef NEW_TEXT
-               LyXParagraph::size_type pos =
-                       lt->sel_start_cursor.pos;
-               LyXParagraph::size_type endpos =
-                       lt->sel_end_cursor.pos;
-#else
-               int pos =
+               LyXParagraph::size_type pos = 
                        lt->sel_start_cursor.pos;
-               int endpos =
+               LyXParagraph::size_type endpos = 
                        lt->sel_end_cursor.pos;
-#endif
                int i = 0;
                bool fPrevIsSpace = false;
                char ch;
@@ -94,7 +82,7 @@ string const GetCurrentSelectionAsString(LyXText * lt)
                        ch = par->GetChar(pos);
 
                        //HB??: Maybe (ch <= ' ') 
-                       if ((ch == ' ') || (ch <= LYX_META_INSET)) {
+                       if ((ch == ' ') || (ch <= LyXParagraph::META_INSET)) {
                                // consecutive spaces --> 1 space char
                                if (fPrevIsSpace) {
                                        pos++;          // Next text pos
@@ -130,7 +118,7 @@ void SetSelectionOverLenChars(LyXText *lt, int len)
 {
        lt->sel_cursor = lt->cursor;
        int i;
-       for (i=0; i < len; i++)
+       for (i= 0; i < len; i++)
                lt->CursorRight();
        lt->SetSelection();
 }
@@ -143,16 +131,19 @@ void LyXFindReplace1::StartSearch()
        LyXFindReplace0::StartSearch();
        SetReplaceEnabled(!current_view->buffer()->isReadonly());
        searchForward = true;
+#ifdef MOVE_TEXT
+       if (lsSearch.empty()) 
+               SetSearchString(GetSelectionOrWordAtCursor(current_view->text));
+#else
        if (lsSearch.empty()) 
                SetSearchString(GetSelectionOrWordAtCursor(current_view->buffer()->text));
+#endif
 }      
 
 
 // TODO?: the user can insert multiple spaces with this routine (1999-01-11, dnaber)
 void LyXFindReplace1::SearchReplaceCB()
 {
-       LyXText         *ltCur;
-
        if (!current_view->getScreen())
                return;
        if (current_view->buffer()->isReadonly())
@@ -171,9 +162,23 @@ void LyXFindReplace1::SearchReplaceCB()
        string const replacestring = ReplaceString();
 
        current_view->getScreen()->HideCursor();
+#ifdef MOVE_TEXT
+       current_view->update(-2);
+
+       LyXText * ltCur = current_view->text;   
+       if (ltCur->selection) {
+               // clear the selection (if there is any) 
+               current_view->getScreen()->ToggleSelection(false);
+               current_view->text->
+                       ReplaceSelectionWithString(replacestring.c_str());
+               current_view->text->
+                       SetSelectionOverString(replacestring.c_str());
+               current_view->update(1);
+       }
+#else
        current_view->buffer()->update(-2);
 
-       ltCur = current_view->buffer()->text;   
+       LyXText * ltCur = current_view->buffer()->text; 
        if (ltCur->selection) {
                // clear the selection (if there is any) 
                current_view->getScreen()->ToggleSelection(false);
@@ -183,6 +188,7 @@ void LyXFindReplace1::SearchReplaceCB()
                        SetSelectionOverString(replacestring.c_str());
                current_view->buffer()->update(1);
        }
+#endif
        
        // jump to next match:
        SearchCB( searchForward );
@@ -192,7 +198,7 @@ void LyXFindReplace1::SearchReplaceCB()
 // replaces all occurences of a string (1999-01-15, dnaber@mini.gt.owl.de)
 void LyXFindReplace1::SearchReplaceAllCB()
 {
-       LyXText         *ltCur;
+       LyXText ltCur;
 
        if (!current_view->getScreen())
                return;
@@ -213,6 +219,26 @@ void LyXFindReplace1::SearchReplaceAllCB()
 
        current_view->getScreen()->HideCursor();
 
+#ifdef MOVE_TEXT
+       // start at top
+       current_view->text->ClearSelection();
+       current_view->text->CursorTop();
+
+       int replace_count = 0;
+       do {
+               ltCur = current_view->text;     
+               if (ltCur->selection) {
+                       current_view->update(-2);
+                       current_view->getScreen()->ToggleSelection(false);
+                       current_view->text->
+                               ReplaceSelectionWithString(replacestring.c_str());
+                       current_view->text->
+                               SetSelectionOverString(replacestring.c_str());
+                       current_view->update(1); 
+                       ++replace_count;
+               }
+       } while( SearchCB(true) );
+#else
        // start at top
        current_view->buffer()->text->ClearSelection();
        current_view->buffer()->text->CursorTop();
@@ -231,7 +257,7 @@ void LyXFindReplace1::SearchReplaceAllCB()
                        replace_count++;
                }
        } while( SearchCB(true) );
-
+#endif
        if( replace_count == 0 ) {
                LyXBell();      
                minibuffer->Set(_("String not found!"));
@@ -249,7 +275,7 @@ void LyXFindReplace1::SearchReplaceAllCB()
 
 bool LyXFindReplace1::SearchCB(bool fForward)
 {
-       LyXText         *ltCur;
+       LyXText ltCur;
        bool result;
 
        // store search direction
@@ -259,8 +285,13 @@ bool LyXFindReplace1::SearchCB(bool fForward)
                return(false);
    
        current_view->getScreen()->HideCursor();
+#ifdef MOVE_TEXT
+       current_view->update(-2);
+       ltCur = current_view->text;
+#else
        current_view->buffer()->update(-2);
        ltCur = current_view->buffer()->text;
+#endif
        if (ltCur->selection) 
                ltCur->cursor = fForward ? ltCur->sel_end_cursor :
                                                  ltCur->sel_start_cursor;
@@ -270,6 +301,16 @@ bool LyXFindReplace1::SearchCB(bool fForward)
    
        if (!ValidSearchData() ||
            (fForward ? SearchForward(ltCur) : SearchBackward(ltCur))) {
+#ifdef MOVE_TEXT
+               current_view->update(-2);
+
+               // clear the selection (if there is any) 
+               current_view->getScreen()->ToggleSelection();
+               current_view->text->ClearSelection();
+
+               // set the new selection 
+               SetSelectionOverLenChars(current_view->text, iLenSelected);
+#else
                current_view->buffer()->update(-2);
 
                // clear the selection (if there is any) 
@@ -278,6 +319,7 @@ bool LyXFindReplace1::SearchCB(bool fForward)
 
                // set the new selection 
                SetSelectionOverLenChars(current_view->buffer()->text, iLenSelected);
+#endif
                current_view->getScreen()->ToggleSelection(false);
                minibuffer->Set(_("Found."));
                result = true;
@@ -300,13 +342,9 @@ bool LyXFindReplace1::SearchCB(bool fForward)
 bool LyXFindReplace1::SearchForward(LyXText * lt)
 {
        LyXParagraph * par = lt->cursor.par;
-#ifdef NEW_TEXT
        LyXParagraph::size_type pos = lt->cursor.pos;
-#else
-       int pos = lt->cursor.pos;
-#endif
 
-       while (par && !IsSearchStringInText(par,pos)) {
+       while (par && !IsSearchStringInText(par, pos)) {
                if (pos<par->Last()-1)
                        pos++;
                else {
@@ -315,7 +353,7 @@ bool LyXFindReplace1::SearchForward(LyXText * lt)
                }
        }
        if (par) {
-               lt->SetCursor(par,pos);
+               lt->SetCursor(par, pos);
                return true;
        } else
                return false;
@@ -341,10 +379,10 @@ bool LyXFindReplace1::SearchBackward(LyXText *lt)
                                        pos = par->Last()-1;
                        } while (par && pos<0);
                }
-       } while (par && !IsSearchStringInText(par,pos));
+       } while (par && !IsSearchStringInText(par, pos));
   
        if (par) {
-               lt->SetCursor(par,pos);
+               lt->SetCursor(par, pos);
                return true;
        } else
                return false;
@@ -367,13 +405,8 @@ int LyXFindReplace1::CompareChars(char chSearch, char chText)
 
 // returns true if the search string is at the specified position 
 // (Copied from the original "LyXText::IsStringInText" in text2.C )
-#ifdef NEW_TEXT
 bool LyXFindReplace1::IsSearchStringInText(LyXParagraph * par,
                                           LyXParagraph::size_type pos)
-#else
-bool LyXFindReplace1::IsSearchStringInText(LyXParagraph * par,
-                                          int pos)
-#endif
 {
        char            chSrch = 0;
        char            chText;