X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Flyxfr1.C;h=ca5e9aa51a0469506b2a6b5fe5fe444fc38eea20;hb=ebfcf1c0e72288b7131607af0330500c8739cead;hp=7fd124624db6520abba3633fdf844c85d68e7531;hpb=0088121bd8c3fc7f2109e8dc9b22b73ca193f20e;p=lyx.git diff --git a/src/lyxfr1.C b/src/lyxfr1.C index 7fd124624d..ca5e9aa51a 100644 --- a/src/lyxfr1.C +++ b/src/lyxfr1.C @@ -19,8 +19,11 @@ #include "lyxtext.h" #include "LyXView.h" #include "minibuffer.h" +#include "lyx_gui_misc.h" #include "support/textutils.h" - +#include "support/lstrings.h" +#include "BufferView.h" +#include "buffer.h" // Returns the current selection. If nothing is selected or if the selection // spans 2 paragraphs, an empty string is returned. @@ -29,13 +32,13 @@ string GetCurrentSelectionAsString(LyXText * lt) { string sz; - LyXParagraph * par = lt->cursor.par; - if (lt->selection && lt->sel_cursor.par == par) { + LyXParagraph * par = lt->cursor.par(); + if (lt->selection && lt->sel_cursor.par() == par) { // (selected) and (begin/end in same paragraph) LyXParagraph::size_type pos = - lt->sel_start_cursor.pos; + lt->sel_start_cursor.pos(); LyXParagraph::size_type endpos = - lt->sel_end_cursor.pos; + lt->sel_end_cursor.pos(); bool fPrevIsSpace = false; char ch; while (pos < par->Last() && pos < endpos) { @@ -64,22 +67,22 @@ string GetCurrentSelectionAsString(LyXText * lt) // If nothing selected, select the word at the cursor. // Returns the current selection static inline -string GetSelectionOrWordAtCursor(LyXText * lt) +string GetSelectionOrWordAtCursor(BufferView * bv) { - lt->SelectWordWhenUnderCursor(); - return GetCurrentSelectionAsString(lt); + bv->text->SelectWordWhenUnderCursor(bv); + return GetCurrentSelectionAsString(bv->text); } // This is a copy of SetSelectionOverString from text.C // It does the same, but uses only the length as a parameter static inline -void SetSelectionOverLenChars(LyXText * lt, int len) +void SetSelectionOverLenChars(BufferView * bv, int len) { - lt->sel_cursor = lt->cursor; + bv->text->sel_cursor = bv->text->cursor; for (int i = 0; i < len; ++i) - lt->CursorRight(); - lt->SetSelection(); + bv->text->CursorRight(bv); + bv->text->SetSelection(); } @@ -102,7 +105,7 @@ void LyXFindReplace::StartSearch(BufferView * b) SF.replaceEnabled(!bv->buffer()->isReadonly()); searchForward = true; if (SF.SearchString().empty()) - SF.SetSearchString(GetSelectionOrWordAtCursor(bv->text)); + SF.SetSearchString(GetSelectionOrWordAtCursor(bv)); } @@ -126,17 +129,17 @@ void LyXFindReplace::SearchReplaceCB() string const replacestring = SF.ReplaceString(); bv->hideCursor(); - bv->update(-2); + bv->update(BufferView::SELECT|BufferView::FITCUR); LyXText * ltCur = bv->text; if (ltCur->selection) { // clear the selection (if there is any) bv->toggleSelection(false); bv->text-> - ReplaceSelectionWithString(replacestring.c_str()); + ReplaceSelectionWithString(bv, replacestring); bv->text-> - SetSelectionOverString(replacestring.c_str()); - bv->update(1); + SetSelectionOverString(bv, replacestring); + bv->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE); } // jump to next match: @@ -166,20 +169,20 @@ void LyXFindReplace::SearchReplaceAllCB() // start at top bv->text->ClearSelection(); - bv->text->CursorTop(); + bv->text->CursorTop(bv); int replace_count = 0; LyXText * ltCur; do { ltCur = bv->text; if (ltCur->selection) { - bv->update(-2); + bv->update(BufferView::SELECT|BufferView::FITCUR); bv->toggleSelection(false); bv->text-> - ReplaceSelectionWithString(replacestring.c_str()); + ReplaceSelectionWithString(bv, replacestring); bv->text-> - SetSelectionOverString(replacestring.c_str()); - bv->update(1); + SetSelectionOverString(bv, replacestring); + bv->update(BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE); ++replace_count; } } while (SearchCB(true)); @@ -209,7 +212,7 @@ bool LyXFindReplace::SearchCB(bool fForward) return false; bv->hideCursor(); - bv->update(-2); + bv->update(BufferView::SELECT|BufferView::FITCUR); LyXText * ltCur = bv->text; if (ltCur->selection) ltCur->cursor = fForward ? ltCur->sel_end_cursor : @@ -219,15 +222,15 @@ bool LyXFindReplace::SearchCB(bool fForward) bool result; if (!SF.ValidSearchData() || - (fForward ? SearchForward(ltCur) : SearchBackward(ltCur))) { - bv->update(-2); + (fForward ? SearchForward(bv):SearchBackward(bv))) { + bv->update(BufferView::SELECT|BufferView::FITCUR); // clear the selection (if there is any) bv->toggleSelection(); bv->text->ClearSelection(); // set the new selection - SetSelectionOverLenChars(bv->text, iLenSelected); + SetSelectionOverLenChars(bv, iLenSelected); bv->toggleSelection(false); bv->owner()->getMiniBuffer()->Set(_("Found.")); result = true; @@ -247,10 +250,10 @@ bool LyXFindReplace::SearchCB(bool fForward) // if the string can be found: return true and set the cursor to // the new position // (was: LyXText::SearchForward(char const* string) in text2.C ) -bool LyXFindReplace::SearchForward(LyXText * lt) +bool LyXFindReplace::SearchForward(BufferView * bv) { - LyXParagraph * par = lt->cursor.par; - LyXParagraph::size_type pos = lt->cursor.pos; + LyXParagraph * par = bv->text->cursor.par(); + LyXParagraph::size_type pos = bv->text->cursor.pos(); while (par && !IsSearchStringInText(par, pos)) { if (pos < par->Last() - 1) @@ -261,7 +264,7 @@ bool LyXFindReplace::SearchForward(LyXText * lt) } } if (par) { - lt->SetCursor(par, pos); + bv->text->SetCursor(bv, par, pos); return true; } else return false; @@ -271,10 +274,10 @@ bool LyXFindReplace::SearchForward(LyXText * lt) // if the string can be found: return true and set the cursor to // the new position // (was: LyXText::SearchBackward(char const* string) in text2.C ) -bool LyXFindReplace::SearchBackward(LyXText * lt) +bool LyXFindReplace::SearchBackward(BufferView * bv) { - LyXParagraph * par = lt->cursor.par; - int pos = lt->cursor.pos; + LyXParagraph * par = bv->text->cursor.par(); + int pos = bv->text->cursor.pos(); do { if (pos > 0) @@ -290,7 +293,7 @@ bool LyXFindReplace::SearchBackward(LyXText * lt) } while (par && !IsSearchStringInText(par, pos)); if (par) { - lt->SetCursor(par, pos); + bv->text->SetCursor(bv, par, pos); return true; } else return false;