]> git.lyx.org Git - features.git/commitdiff
got rid of more current_views rewritten the search and replace dialog
authorLars Gullik Bjønnes <larsbj@gullik.org>
Wed, 1 Mar 2000 04:56:55 +0000 (04:56 +0000)
committerLars Gullik Bjønnes <larsbj@gullik.org>
Wed, 1 Mar 2000 04:56:55 +0000 (04:56 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@578 a592a061-630c-0410-9148-cb99ea01b6c8

ChangeLog
src/lyx_gui.C
src/lyx_gui_misc.C
src/lyxfr0.C
src/lyxfr0.h
src/lyxfr1.C
src/lyxfr1.h
src/lyxfunc.C
src/paragraph.C

index 1dd43244730f5f1cfd8831892e9d1eeee18d0cd1..ea2a481992bc4806bd39365195b2ae71788a3994 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,26 @@
+2000-03-01  Lars Gullik Bjønnes  <larsbj@lyx.org>
+
+       * 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  <Jean-Marc.Lasgouttes@inria.fr>
 
        * lib/bind/*.bind: make sure 'buffer-previous' function is not
index 1d12994f9674d11791d2d886a985dc844d6a9b8a..20cde249053e92e508c2a5b4fd30a8cfab411da4 100644 (file)
@@ -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,
index 18068c6e7b1ca0c54cd22781a291e529ee302908..b29cdd7ac8c378d1aa8bb26b1523e7e56dd05b33 100644 (file)
@@ -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);
        }
index 70bdadb5d6e36ee80fb33a3c9ade0a07a6015d87..d397968b3e660594607b53c5e855fd30b47ea38a 100644 (file)
 
 #include <config.h>
 
-#include <cctype>
-#include <cstring>
-#include <cstdlib>
-
 #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<LyXFindReplace*>(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<LyXFindReplace*>(ob->form->u_vdata);
+       lfr->SearchCB(false);
 }
 
 
-void SearchReplaceAllCB(FL_OBJECT *, long)
+void SearchReplaceAllCB(FL_OBJECT * ob, long)
 {
-       _FR.SearchReplaceAllCB();
+       LyXFindReplace * lfr = static_cast<LyXFindReplace*>(ob->form->u_vdata);
+       lfr->SearchReplaceAllCB();
 }
 
 
-void SearchReplaceCB(FL_OBJECT *, long)
+void SearchReplaceCB(FL_OBJECT * ob, long)
 {
-       _FR.SearchReplaceCB();
+       LyXFindReplace * lfr = static_cast<LyXFindReplace*>(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()
 {
-       static int ow = -1, oh;
+       fl_hide_form(search_form->form_search);
+}
+
 
-       FD_form_search *fd_fs = fd_form_search;
+void SearchForm::StartSearch(LyXFindReplace * lfr)
+{
+       static int ow = -1, oh;
 
-       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)
-{
-       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()
+void SearchForm::SetSearchString(string const & ls)
 {
-       _FR.StartSearch();   
+       fl_set_input(search_form->input_search, ls.c_str());    
 }
index 923a4af19bc5f1ae04659e06ca6a94dfefa784c7..d3ddfc93bdba59ca876451225f6d5a5d7cc30355 100644 (file)
@@ -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();  
        
-       /// Initialize internal variables and dialog
-       virtual void StartSearch();
-
-       // 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;
+       bool CaseSensitive() const {
+               return fl_get_button(search_form->btnCaseSensitive);
+       }
 
        ///
-       void SetReplaceEnabled(bool fEnabled);
+       bool MatchWord() const {
+               return fl_get_button(search_form->btnMatchWord);
+       }
+
        ///
-       bool ReplaceEnabled() { return fReplaceEnabled; }
+       string SearchString() const {
+               return fl_get_input(search_form->input_search);
+       }
 
-       /// Initialize search variables from Find & Replace form
-       virtual void ReInitFromForm();
+       /// Initialize internal variables and dialog
+       void StartSearch(LyXFindReplace *);
 
-       // Return values
        ///
-       bool CaseSensitive() { return fCaseSensitive; }
+       void replaceEnabled(bool fEnabled);
        ///
-       bool MatchWord() { return fMatchWord; }
+       bool replaceEnabled() const { return fReplaceEnabled; }
+
+       // Callbacks from form
        ///
-       string const SearchString() { return lsSearch; }
+       void SearchCancelCB();
+
+       // Return values
        ///
-       void SetSearchString(string const &ls);
+       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
index 387104862cc0fb695f5c133d1bb9845f39573b59..57c2cb33089aa8b18728af4343931036d0687635 100644 (file)
 
 #include <config.h>
 
-#include <cctype>
-#include <cstring>
-#include <cstdlib>
-
 #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))))) {
index e47c746d419e64918542fc500174819541b47403..d1a6781d21b4617a26cb0ff0c43f969f81835110 100644 (file)
@@ -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
index 821a1fd8cb9cb422a0aaf09dc3e9c80d5ee804c1..0af4ce33cde93db8219615902e88df926041285c 100644 (file)
@@ -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:
index 73ef0be674ea861d7f54e88515812ce890b5599d..2504a391ba08bfa72f953aadc39ddd05e133c473 100644 (file)
@@ -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 "=="