From b4f44f8c47360b82870aedfa33a970c4d6b34df1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lars=20Gullik=20Bj=C3=B8nnes?= Date: Wed, 1 Mar 2000 04:56:55 +0000 Subject: [PATCH] got rid of more current_views rewritten the search and replace dialog git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@578 a592a061-630c-0410-9148-cb99ea01b6c8 --- ChangeLog | 23 +++++ src/lyx_gui.C | 6 -- src/lyx_gui_misc.C | 4 - src/lyxfr0.C | 154 +++++++++++++-------------------- src/lyxfr0.h | 93 ++++++++++---------- src/lyxfr1.C | 210 ++++++++++++++++++++------------------------- src/lyxfr1.h | 36 ++++---- src/lyxfunc.C | 11 ++- src/paragraph.C | 2 +- 9 files changed, 254 insertions(+), 285 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1dd4324473..ea2a481992 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,26 @@ +2000-03-01 Lars Gullik Bjønnes + + * src/paragraph.C (BeginningOfMainBody): initialize previous_char + and temp. + + * src/lyxfunc.C (Dispatch(LFUN_MENUSEARCH)): Do the Search dialog + directly instead of going through a func. One very bad thing: a + static LyXFindReplace, but I don't know where to place it. + + * src/lyxfr1.C (GetCurrentSelectionAsString): rewritten to use a + string instead of char[]. Also changed to static. + (GetSelectionOrWordAtCursor): changed to static inline + (SetSelectionOverLenChars): ditto. + + * src/lyxfr0.[Ch] src/lyxfr1.[Ch]: rewrite to get rid of + current_view and global variables. both classes has changed names + and LyXFindReplace is not inherited from SearchForm. + + * src/lyx_gui_misc.C (CloseAllBufferRelatedPopups): remove the + fl_form_search form. + + * src/lyx_gui.C (create_forms): removed the fl_form_search form. + 2000-03-01 Jean-Marc Lasgouttes * lib/bind/*.bind: make sure 'buffer-previous' function is not diff --git a/src/lyx_gui.C b/src/lyx_gui.C index 1d12994f96..20cde24905 100644 --- a/src/lyx_gui.C +++ b/src/lyx_gui.C @@ -46,7 +46,6 @@ FD_form_title * fd_form_title; FD_form_paragraph * fd_form_paragraph; FD_form_paragraph_extra * fd_form_paragraph_extra; -FD_form_search * fd_form_search; FD_form_character * fd_form_character; FD_form_document * fd_form_document; FD_form_paper * fd_form_paper; @@ -361,11 +360,6 @@ void LyXGUI::create_forms() fl_set_input_return(fd_form_paragraph_extra->input_pextra_widthp, FL_RETURN_ALWAYS); - // the search form - fd_form_search = create_form_form_search(); - fl_set_form_atclose(fd_form_search->form_search, - CancelCloseBoxCB, 0); - // the character form fd_form_character = create_form_form_character(); fl_set_form_atclose(fd_form_character->form_character, diff --git a/src/lyx_gui_misc.C b/src/lyx_gui_misc.C index 18068c6e7b..b29cdd7ac8 100644 --- a/src/lyx_gui_misc.C +++ b/src/lyx_gui_misc.C @@ -38,7 +38,6 @@ extern BufferView * current_view; extern FD_form_paragraph * fd_form_paragraph; extern FD_form_paragraph_extra * fd_form_paragraph_extra; -extern FD_form_search * fd_form_search; extern FD_form_character * fd_form_character; extern FD_form_document * fd_form_document; extern FD_form_paper * fd_form_paper; @@ -98,9 +97,6 @@ void CloseAllBufferRelatedPopups() if (fd_form_paragraph_extra->form_paragraph_extra->visible) { fl_hide_form(fd_form_paragraph_extra->form_paragraph_extra); } - if (fd_form_search->form_search->visible) { - fl_hide_form(fd_form_search->form_search); - } if (fd_form_character->form_character->visible) { fl_hide_form(fd_form_character->form_character); } diff --git a/src/lyxfr0.C b/src/lyxfr0.C index 70bdadb5d6..d397968b3e 100644 --- a/src/lyxfr0.C +++ b/src/lyxfr0.C @@ -10,156 +10,126 @@ #include -#include -#include -#include - #ifdef __GNUG__ #pragma implementation #endif -#include "LString.h" -#include "lyx_main.h" -#include FORMS_H_LOCATION -#include "form1.h" #include "lyxfr0.h" #include "lyxfr1.h" -#include "lyxfunc.h" -#include "debug.h" -#include "lyxtext.h" -#include "gettext.h" -#include "LyXView.h" // only because of form_main - -//--------------------------------------------------------------- -// I hate global variables, but the same search object must be used everywhere, -// and the form is also global, so... -LyXFindReplace1 _FR; - -// This one should be a protected member of LyXFindReplace1 -// Form creation/destruction must also be done in LyXFindReplace1 -extern FD_form_search *fd_form_search; - -//--------------------------------------------------------------- +#include "lyx_gui_misc.h" // callbacks for form form_search -void SearchCancelCB(FL_OBJECT *, long) +void SearchCancelCB(FL_OBJECT * ob, long) { - _FR.SearchCancelCB(); + fl_hide_form(ob->form); } -void SearchForwardCB(FL_OBJECT *, long) +void SearchForwardCB(FL_OBJECT * ob, long) { - _FR.SearchCB(true); + LyXFindReplace * lfr = static_cast(ob->form->u_vdata); + lfr->SearchCB(true); } -void SearchBackwardCB(FL_OBJECT *, long) +void SearchBackwardCB(FL_OBJECT * ob, long) { - _FR.SearchCB(false); + LyXFindReplace * lfr = static_cast(ob->form->u_vdata); + lfr->SearchCB(false); } -void SearchReplaceAllCB(FL_OBJECT *, long) +void SearchReplaceAllCB(FL_OBJECT * ob, long) { - _FR.SearchReplaceAllCB(); + LyXFindReplace * lfr = static_cast(ob->form->u_vdata); + lfr->SearchReplaceAllCB(); } -void SearchReplaceCB(FL_OBJECT *, long) +void SearchReplaceCB(FL_OBJECT * ob, long) { - _FR.SearchReplaceCB(); + LyXFindReplace * lfr = static_cast(ob->form->u_vdata); + lfr->SearchReplaceCB(); } -//--------------------- LyXFindReplace0's implementation ------------ -LyXFindReplace0::LyXFindReplace0() +SearchForm::SearchForm() + : search_form(0) +{} + + +SearchForm::~SearchForm() { - fCaseSensitive = false; - fMatchWord = false; + // The search_form should be closed and freed when SearchForm + // is destructed. } -void LyXFindReplace0::StartSearch() +void SearchForm::SearchCancelCB() +{ + fl_hide_form(search_form->form_search); +} + + +void SearchForm::StartSearch(LyXFindReplace * lfr) { static int ow = -1, oh; - FD_form_search *fd_fs = fd_form_search; - - if (fd_fs->form_search->visible) { - fl_raise_form(fd_fs->form_search); + if (!search_form) { + search_form = create_form_form_search(); + fl_set_form_atclose(search_form->form_search, + CancelCloseBoxCB, 0); + } + // Set the u_vdata + search_form->form_search->u_vdata = lfr; + + + if (search_form->form_search->visible) { + fl_raise_form(search_form->form_search); } else { - fl_show_form(fd_fs->form_search, + fl_show_form(search_form->form_search, FL_PLACE_MOUSE | FL_FREE_SIZE, FL_FULLBORDER, _("Find & Replace")); // RVDK_PATCH_5 if (ow < 0) { - ow = fd_form_search->form_search->w; - oh = fd_form_search->form_search->h; + ow = search_form->form_search->w; + oh = search_form->form_search->h; } - fl_set_form_minsize(fd_form_search->form_search, ow, oh); + fl_set_form_minsize(search_form->form_search, ow, oh); } - ReInitFromForm(); -} - - -void LyXFindReplace0::ReInitFromForm() -{ - FD_form_search *fd_fs = fd_form_search; - - lsSearch = fl_get_input(fd_fs->input_search); - fCaseSensitive = fl_get_button(fd_fs->btnCaseSensitive); - fMatchWord = fl_get_button(fd_fs->btnMatchWord); } // Returns the value of the replace string in the form -string const LyXFindReplace0::ReplaceString() +string SearchForm::ReplaceString() const { - return string(fl_get_input(fd_form_search->input_replace)); + return fl_get_input(search_form->input_replace); } -void LyXFindReplace0::SearchCancelCB() +void SearchForm::replaceEnabled(bool fEnable) { - fl_hide_form(fd_form_search->form_search); -} - - -void LyXFindReplace0::SetReplaceEnabled(bool fEnable) -{ - FD_form_search *fd_fs = fd_form_search; fReplaceEnabled = fEnable; if (fEnable) { - fl_activate_object(fd_fs->replace_button); - fl_activate_object(fd_fs->replaceall_button); - fl_activate_object(fd_fs->input_replace); - fl_set_object_lcol(fd_fs->replace_button, FL_BLACK); - fl_set_object_lcol(fd_fs->replaceall_button, FL_BLACK); - fl_set_object_lcol(fd_fs->input_replace, FL_BLACK); + fl_activate_object(search_form->replace_button); + fl_activate_object(search_form->replaceall_button); + fl_activate_object(search_form->input_replace); + fl_set_object_lcol(search_form->replace_button, FL_BLACK); + fl_set_object_lcol(search_form->replaceall_button, FL_BLACK); + fl_set_object_lcol(search_form->input_replace, FL_BLACK); } else { - fl_deactivate_object(fd_fs->replace_button); - fl_deactivate_object(fd_fs->replaceall_button); - fl_deactivate_object(fd_fs->input_replace); - fl_set_object_lcol(fd_fs->replace_button, FL_INACTIVE); - fl_set_object_lcol(fd_fs->replaceall_button, FL_INACTIVE); - fl_set_object_lcol(fd_fs->input_replace, FL_INACTIVE); + fl_deactivate_object(search_form->replace_button); + fl_deactivate_object(search_form->replaceall_button); + fl_deactivate_object(search_form->input_replace); + fl_set_object_lcol(search_form->replace_button, FL_INACTIVE); + fl_set_object_lcol(search_form->replaceall_button, FL_INACTIVE); + fl_set_object_lcol(search_form->input_replace, FL_INACTIVE); } } -void LyXFindReplace0::SetSearchString(string const &ls) +void SearchForm::SetSearchString(string const & ls) { - lsSearch = ls; - fl_set_input(fd_form_search->input_search, ls.c_str()); -} - - -//--------------------------------------------------------------- -//HB??: Maybe _FR.StartSearch should be called in lyxfunc.C instead of MenuSearch() ? - -void MenuSearch() -{ - _FR.StartSearch(); + fl_set_input(search_form->input_search, ls.c_str()); } diff --git a/src/lyxfr0.h b/src/lyxfr0.h index 923a4af19b..d3ddfc93bd 100644 --- a/src/lyxfr0.h +++ b/src/lyxfr0.h @@ -6,78 +6,81 @@ #pragma interface #endif +#include "LString.h" #include FORMS_H_LOCATION +#include "form1.h" +class LyXFindReplace; /** + The comments below are most likely not valied anymore since + the rewrite of LyXFindReplace0 and LyXFindReplace1. (Lgb) + LyXFindReplace0 This is a virtual base class. It does not handle text specific items. It only manages the Find & Replace form and the variables. -To be added: + To be added: -- Confirm replace lightbutton (checkbox) + - Confirm replace lightbutton (checkbox) -- A history list for search and replace strings. -These 2 stringlists should match, so that you can replay previous replaces. -If you select another search string, then the first choice should be the -replace string you have typed before. - -- regex searches (I'm working on that -- dnaber, 1999-02-24) + - A history list for search and replace strings. + These 2 stringlists should match, so that you can replay previous replaces. + If you select another search string, then the first choice should be the + replace string you have typed before. + + - regex searches (I'm working on that -- dnaber, 1999-02-24) */ -class LyXFindReplace0 { + +class SearchForm { public: /// - LyXFindReplace0(); + SearchForm(); /// - virtual ~LyXFindReplace0() {}; + ~SearchForm(); + /// + bool CaseSensitive() const { + return fl_get_button(search_form->btnCaseSensitive); + } + + /// + bool MatchWord() const { + return fl_get_button(search_form->btnMatchWord); + } + + /// + string SearchString() const { + return fl_get_input(search_form->input_search); + } + /// Initialize internal variables and dialog - virtual void StartSearch(); + void StartSearch(LyXFindReplace *); + + /// + void replaceEnabled(bool fEnabled); + /// + bool replaceEnabled() const { return fReplaceEnabled; } // Callbacks from form /// - virtual void SearchCancelCB(); - /// - virtual bool SearchCB(bool fForward) = 0; - /// - virtual void SearchReplaceCB() = 0; - /// - virtual void SearchReplaceAllCB() = 0; -protected: - /// - bool fCaseSensitive; - /// Match complete word only. - bool fMatchWord; - /// replace buttons enabled? - bool fReplaceEnabled; - /// search string - string lsSearch; - - /// - void SetReplaceEnabled(bool fEnabled); - /// - bool ReplaceEnabled() { return fReplaceEnabled; } - - /// Initialize search variables from Find & Replace form - virtual void ReInitFromForm(); + void SearchCancelCB(); // Return values /// - bool CaseSensitive() { return fCaseSensitive; } + void SetSearchString(string const & ls); /// - bool MatchWord() { return fMatchWord; } - /// - string const SearchString() { return lsSearch; } - /// - void SetSearchString(string const &ls); - /// - string const ReplaceString(); + string ReplaceString() const; /// - bool ValidSearchData() { return !lsSearch.empty(); } + bool ValidSearchData() const { return !(SearchString().empty()); } +private: + /// + FD_form_search * search_form; + /// replace buttons enabled? + bool fReplaceEnabled; }; #endif diff --git a/src/lyxfr1.C b/src/lyxfr1.C index 387104862c..57c2cb3308 100644 --- a/src/lyxfr1.C +++ b/src/lyxfr1.C @@ -10,75 +10,37 @@ #include -#include -#include -#include - #ifdef __GNUG__ #pragma implementation #endif -#include "LString.h" -#include "lyx_main.h" -#include FORMS_H_LOCATION -#include "form1.h" -#include "lyxfr0.h" #include "lyxfr1.h" -#include "lyxfunc.h" -#include "debug.h" + #include "lyxtext.h" -#include "gettext.h" #include "LyXView.h" -#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... - -// Maximum length copied from the current selection to the search string -const int LYXSEARCH_MAXLEN = 128; - -// function prototypes - -// If nothing selected, select the word at the cursor. -// Returns the current selection -// Note: this function should be in LyXText! -string const GetSelectionOrWordAtCursor(LyXText * lt); // Returns the current selection. If nothing is selected or if the selection // spans 2 paragraphs, an empty string is returned. -string const GetCurrentSelectionAsString(LyXText * lt); - -// This is a copy of SetSelectionOverString from text.C -// It does the same, but uses only the length as a parameter -void SetSelectionOverLenChars(LyXText * lt, int len); - -//------------------------------------------------------------- - - - -// Returns the current selection. If nothing is selected or if the selection -// spans 2 paragraphs, an empty string is returned. -string const GetCurrentSelectionAsString(LyXText * lt) +static +string GetCurrentSelectionAsString(LyXText * lt) { - char sz[LYXSEARCH_MAXLEN]; - sz[0] = 0; + string sz; LyXParagraph * par = lt->cursor.par; - if (lt->selection && (lt->sel_cursor.par == 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; LyXParagraph::size_type endpos = lt->sel_end_cursor.pos; - int i = 0; bool fPrevIsSpace = false; char ch; - while ((i < LYXSEARCH_MAXLEN - 2) && - (pos < par->Last()) && (pos < endpos)) { + while (pos < par->Last() && pos < endpos) { ch = par->GetChar(pos); - + //HB??: Maybe (ch <= ' ') if ((ch == ' ') || (ch <= LyXParagraph::META_INSET)) { // consecutive spaces --> 1 space char @@ -86,24 +48,23 @@ string const GetCurrentSelectionAsString(LyXText * lt) ++pos; // Next text pos continue; // same search pos } - sz[i] = ' '; + sz += ' '; fPrevIsSpace = true; } else { - sz[i] = ch; + sz += ch; fPrevIsSpace = false; } ++pos; - ++i; - } - sz[i] = 0; + } } - return string(sz); + return sz; } // If nothing selected, select the word at the cursor. // Returns the current selection -string const GetSelectionOrWordAtCursor(LyXText * lt) +static inline +string GetSelectionOrWordAtCursor(LyXText * lt) { lt->SelectWordWhenUnderCursor(); return GetCurrentSelectionAsString(lt); @@ -112,6 +73,7 @@ string const GetSelectionOrWordAtCursor(LyXText * lt) // 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) { lt->sel_cursor = lt->cursor; @@ -123,150 +85,160 @@ void SetSelectionOverLenChars(LyXText * lt, int len) //------------------------------ -void LyXFindReplace1::StartSearch() + +LyXFindReplace::LyXFindReplace() + : bv(0) +{} + + +LyXFindReplace::~LyXFindReplace() +{} + + +void LyXFindReplace::StartSearch(BufferView * b) { - LyXFindReplace0::StartSearch(); - SetReplaceEnabled(!current_view->buffer()->isReadonly()); + bv = b; + SF.StartSearch(this); + SF.replaceEnabled(!bv->buffer()->isReadonly()); searchForward = true; - if (lsSearch.empty()) - SetSearchString(GetSelectionOrWordAtCursor(current_view->text)); + if (SF.SearchString().empty()) + SF.SetSearchString(GetSelectionOrWordAtCursor(bv->text)); } // TODO?: the user can insert multiple spaces with this // routine (1999-01-11, dnaber) -void LyXFindReplace1::SearchReplaceCB() +void LyXFindReplace::SearchReplaceCB() { - if (!current_view->available()) return; - if (current_view->buffer()->isReadonly()) return; + if (!bv->available()) return; + if (bv->buffer()->isReadonly()) return; // CutSelection cannot cut a single space, so we have to stop // in order to avoid endless loop :-( - ReInitFromForm(); - if (SearchString().length() == 0 || (SearchString().length() == 1 - && SearchString()[0] == ' ') ) { + if (SF.SearchString().length() == 0 + || (SF.SearchString().length() == 1 + && SF.SearchString()[0] == ' ') ) { WriteAlert(_("Sorry!"), _("You cannot replace a single space, " "nor an empty character.")); return; } - string const replacestring = ReplaceString(); + string const replacestring = SF.ReplaceString(); - current_view->hideCursor(); - current_view->update(-2); + bv->hideCursor(); + bv->update(-2); - LyXText * ltCur = current_view->text; + LyXText * ltCur = bv->text; if (ltCur->selection) { // clear the selection (if there is any) - current_view->toggleSelection(false); - current_view->text-> + bv->toggleSelection(false); + bv->text-> ReplaceSelectionWithString(replacestring.c_str()); - current_view->text-> + bv->text-> SetSelectionOverString(replacestring.c_str()); - current_view->update(1); + bv->update(1); } // jump to next match: - SearchCB( searchForward ); + SearchCB(searchForward); } // replaces all occurences of a string (1999-01-15, dnaber@mini.gt.owl.de) -void LyXFindReplace1::SearchReplaceAllCB() +void LyXFindReplace::SearchReplaceAllCB() { - if (!current_view->available()) return; - if (current_view->buffer()->isReadonly()) return; + if (!bv->available()) return; + if (bv->buffer()->isReadonly()) return; // CutSelection cannot cut a single space, so we have to stop // in order to avoid endless loop :-( - ReInitFromForm(); - if (SearchString().length() == 0 || (SearchString().length() == 1 - && SearchString()[0] == ' ') ) { + if (SF.SearchString().length() == 0 + || (SF.SearchString().length() == 1 + && SF.SearchString()[0] == ' ') ) { WriteAlert(_("Sorry!"), _("You cannot replace a single space, " "nor an empty character.")); return; } - string const replacestring = ReplaceString(); + string const replacestring = SF.ReplaceString(); - current_view->hideCursor(); + bv->hideCursor(); // start at top - current_view->text->ClearSelection(); - current_view->text->CursorTop(); + bv->text->ClearSelection(); + bv->text->CursorTop(); int replace_count = 0; LyXText * ltCur; do { - ltCur = current_view->text; + ltCur = bv->text; if (ltCur->selection) { - current_view->update(-2); - current_view->toggleSelection(false); - current_view->text-> + bv->update(-2); + bv->toggleSelection(false); + bv->text-> ReplaceSelectionWithString(replacestring.c_str()); - current_view->text-> + bv->text-> SetSelectionOverString(replacestring.c_str()); - current_view->update(1); + bv->update(1); ++replace_count; } - } while( SearchCB(true) ); + } while (SearchCB(true)); if( replace_count == 0 ) { LyXBell(); - current_view->owner()->getMiniBuffer()->Set( + bv->owner()->getMiniBuffer()->Set( _("String not found!")); } else { if (replace_count == 1) { - current_view->owner()->getMiniBuffer()->Set( + bv->owner()->getMiniBuffer()->Set( _("1 string has been replaced.")); } else { string str = tostr(replace_count); str += _(" strings have been replaced."); - current_view->owner()->getMiniBuffer()->Set(str); + bv->owner()->getMiniBuffer()->Set(str); } } } -bool LyXFindReplace1::SearchCB(bool fForward) +bool LyXFindReplace::SearchCB(bool fForward) { // store search direction searchForward = fForward; - if (!current_view->available()) + if (!bv->available()) return false; - current_view->hideCursor(); - current_view->update(-2); - LyXText * ltCur = current_view->text; + bv->hideCursor(); + bv->update(-2); + LyXText * ltCur = bv->text; if (ltCur->selection) ltCur->cursor = fForward ? ltCur->sel_end_cursor : ltCur->sel_start_cursor; - ReInitFromForm(); - iLenSelected = SearchString().length(); + iLenSelected = SF.SearchString().length(); bool result; - if (!ValidSearchData() || + if (!SF.ValidSearchData() || (fForward ? SearchForward(ltCur) : SearchBackward(ltCur))) { - current_view->update(-2); + bv->update(-2); // clear the selection (if there is any) - current_view->toggleSelection(); - current_view->text->ClearSelection(); + bv->toggleSelection(); + bv->text->ClearSelection(); // set the new selection - SetSelectionOverLenChars(current_view->text, iLenSelected); - current_view->toggleSelection(false); - current_view->owner()->getMiniBuffer()->Set(_("Found.")); + SetSelectionOverLenChars(bv->text, iLenSelected); + bv->toggleSelection(false); + bv->owner()->getMiniBuffer()->Set(_("Found.")); result = true; } else { LyXBell(); - current_view->owner()->getMiniBuffer()->Set(_("String not found!")); + bv->owner()->getMiniBuffer()->Set(_("String not found!")); result = false; } - if (current_view->focus()) - current_view->showCursor(); + if (bv->focus()) + bv->showCursor(); return result; } @@ -275,7 +247,7 @@ bool LyXFindReplace1::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 LyXFindReplace1::SearchForward(LyXText * lt) +bool LyXFindReplace::SearchForward(LyXText * lt) { LyXParagraph * par = lt->cursor.par; LyXParagraph::size_type pos = lt->cursor.pos; @@ -299,7 +271,7 @@ bool LyXFindReplace1::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 LyXFindReplace1::SearchBackward(LyXText * lt) +bool LyXFindReplace::SearchBackward(LyXText * lt) { LyXParagraph * par = lt->cursor.par; int pos = lt->cursor.pos; @@ -331,9 +303,9 @@ return value is = 0 if chSearch == ch2 < 0 if chSearch < ch2 */ -int LyXFindReplace1::CompareChars(char chSearch, char chText) +int LyXFindReplace::CompareChars(char chSearch, char chText) const { - if (CaseSensitive()) + if (SF.CaseSensitive()) return (chSearch - chText); return (toupper(chSearch) - toupper(chText)); } @@ -341,8 +313,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 ) -bool LyXFindReplace1::IsSearchStringInText(LyXParagraph * par, - LyXParagraph::size_type pos) +bool LyXFindReplace::IsSearchStringInText(LyXParagraph * par, + LyXParagraph::size_type pos) const { if (!par) return false; @@ -352,8 +324,8 @@ bool LyXFindReplace1::IsSearchStringInText(LyXParagraph * par, int iText = 0; string::size_type iSrch = 0; while (pos + iText < par->Last() && - iSrch < SearchString().length()) { - chSrch = SearchString()[iSrch]; + iSrch < SF.SearchString().length()) { + chSrch = SF.SearchString()[iSrch]; chText = par->GetChar(pos+iText); if (chText == ' ') { if (fPrevIsSpace) { @@ -370,10 +342,10 @@ bool LyXFindReplace1::IsSearchStringInText(LyXParagraph * par, ++iText; } - if (iSrch < SearchString().length()) + if (iSrch < SF.SearchString().length()) return false; - if (!MatchWord() + if (!SF.MatchWord() || ((pos <= 0 || !IsLetterCharOrDigit(par->GetChar(pos - 1))) && (pos + iText >= par->Last() || !IsLetterCharOrDigit(par->GetChar(pos + iText))))) { diff --git a/src/lyxfr1.h b/src/lyxfr1.h index e47c746d41..d1a6781d21 100644 --- a/src/lyxfr1.h +++ b/src/lyxfr1.h @@ -6,44 +6,44 @@ #pragma interface #endif -#include FORMS_H_LOCATION #include "lyxparagraph.h" +#include "lyxfr0.h" -class LyXText; +class LyXText; /** - LyXFindReplace1" + LyXFindReplace" This class implements Find & Replace in LyXText texts. It is based on LyXFindReplace0, which implements the form related stuff. (see lyxfr0.h) */ -class LyXFindReplace1 : public LyXFindReplace0 { +class LyXFindReplace { public: /// - LyXFindReplace1() : LyXFindReplace0() {}; + LyXFindReplace(); /// - ~LyXFindReplace1() {}; + ~LyXFindReplace(); /// Initialize internal variables and search form - virtual void StartSearch(); + void StartSearch(BufferView *); /// - virtual bool SearchCB(bool fForward); + bool SearchCB(bool fForward); /// - virtual void SearchReplaceCB(); + void SearchReplaceCB(); /// - virtual void SearchReplaceAllCB(); -protected: + void SearchReplaceAllCB(); +private: /// Set by IsSearchStringInText: - int iLenSelected; + mutable int iLenSelected; /// Direction we are searching: bool searchForward; /// - bool SearchForward(LyXText *lt); + bool SearchForward(LyXText * lt); /// - bool SearchBackward(LyXText *lt); + bool SearchBackward(LyXText * lt); /** Compares 2 char values. return value is @@ -53,9 +53,13 @@ protected: \item < 0 if ch1 < ch2 \end{itemize} */ - int CompareChars(char chSearch, char chText); + int CompareChars(char chSearch, char chText) const; /// returns true if the specified string is at the specified position bool IsSearchStringInText(LyXParagraph * par, - LyXParagraph::size_type pos); + LyXParagraph::size_type pos) const; + /// + SearchForm SF; + /// + BufferView * bv; }; #endif diff --git a/src/lyxfunc.C b/src/lyxfunc.C index 821a1fd8cb..0af4ce33cd 100644 --- a/src/lyxfunc.C +++ b/src/lyxfunc.C @@ -66,6 +66,7 @@ #include "ImportNoweb.h" #include "layout.h" #include "WorkArea.h" +#include "lyxfr1.h" extern bool cursor_follows_scrollbar; @@ -97,7 +98,6 @@ extern LyXAction lyxaction; extern tex_accent_struct get_accent(kb_action action); extern void AutoSave(); -extern void MenuSearch(); extern void SetUpdateTimer(float timer = 0.3); extern void FreeUpdateTimer(); extern bool PreviewDVI(Buffer *); @@ -857,7 +857,14 @@ string LyXFunc::Dispatch(int ac, break; case LFUN_MENUSEARCH: - MenuSearch(); + { + // Ok this is one _very_ bad solution, but I think that some + // of this will be rewritten as part of GUI indep anyway. + // Lgb + static LyXFindReplace FR_; + FR_.StartSearch(owner->view()); + } + break; case LFUN_PASTE: diff --git a/src/paragraph.C b/src/paragraph.C index 73ef0be674..2504a391ba 100644 --- a/src/paragraph.C +++ b/src/paragraph.C @@ -1731,7 +1731,7 @@ int LyXParagraph::BeginningOfMainBody() const && GetChar(i) != LyXParagraph::META_NEWLINE ) { ++i; - char previous_char, temp; + char previous_char = 0, temp = 0; if (i < size() && (previous_char = GetChar(i)) != LyXParagraph::META_NEWLINE) { // Yes, this ^ is supposed to be "= " not "=="