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
This commit is contained in:
Lars Gullik Bjønnes 2000-03-01 04:56:55 +00:00
parent 654f2c761a
commit b4f44f8c47
9 changed files with 254 additions and 285 deletions

View File

@ -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> 2000-03-01 Jean-Marc Lasgouttes <Jean-Marc.Lasgouttes@inria.fr>
* lib/bind/*.bind: make sure 'buffer-previous' function is not * lib/bind/*.bind: make sure 'buffer-previous' function is not

View File

@ -46,7 +46,6 @@
FD_form_title * fd_form_title; FD_form_title * fd_form_title;
FD_form_paragraph * fd_form_paragraph; FD_form_paragraph * fd_form_paragraph;
FD_form_paragraph_extra * fd_form_paragraph_extra; FD_form_paragraph_extra * fd_form_paragraph_extra;
FD_form_search * fd_form_search;
FD_form_character * fd_form_character; FD_form_character * fd_form_character;
FD_form_document * fd_form_document; FD_form_document * fd_form_document;
FD_form_paper * fd_form_paper; 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_set_input_return(fd_form_paragraph_extra->input_pextra_widthp,
FL_RETURN_ALWAYS); 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 // the character form
fd_form_character = create_form_form_character(); fd_form_character = create_form_form_character();
fl_set_form_atclose(fd_form_character->form_character, fl_set_form_atclose(fd_form_character->form_character,

View File

@ -38,7 +38,6 @@ extern BufferView * current_view;
extern FD_form_paragraph * fd_form_paragraph; extern FD_form_paragraph * fd_form_paragraph;
extern FD_form_paragraph_extra * fd_form_paragraph_extra; 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_character * fd_form_character;
extern FD_form_document * fd_form_document; extern FD_form_document * fd_form_document;
extern FD_form_paper * fd_form_paper; extern FD_form_paper * fd_form_paper;
@ -98,9 +97,6 @@ void CloseAllBufferRelatedPopups()
if (fd_form_paragraph_extra->form_paragraph_extra->visible) { if (fd_form_paragraph_extra->form_paragraph_extra->visible) {
fl_hide_form(fd_form_paragraph_extra->form_paragraph_extra); 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) { if (fd_form_character->form_character->visible) {
fl_hide_form(fd_form_character->form_character); fl_hide_form(fd_form_character->form_character);
} }

View File

@ -10,156 +10,126 @@
#include <config.h> #include <config.h>
#include <cctype>
#include <cstring>
#include <cstdlib>
#ifdef __GNUG__ #ifdef __GNUG__
#pragma implementation #pragma implementation
#endif #endif
#include "LString.h"
#include "lyx_main.h"
#include FORMS_H_LOCATION
#include "form1.h"
#include "lyxfr0.h" #include "lyxfr0.h"
#include "lyxfr1.h" #include "lyxfr1.h"
#include "lyxfunc.h" #include "lyx_gui_misc.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;
//---------------------------------------------------------------
// callbacks for form form_search // 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; // The search_form should be closed and freed when SearchForm
fMatchWord = false; // 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; static int ow = -1, oh;
FD_form_search *fd_fs = fd_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 (fd_fs->form_search->visible) {
fl_raise_form(fd_fs->form_search); if (search_form->form_search->visible) {
fl_raise_form(search_form->form_search);
} else { } else {
fl_show_form(fd_fs->form_search, fl_show_form(search_form->form_search,
FL_PLACE_MOUSE | FL_FREE_SIZE, FL_FULLBORDER, FL_PLACE_MOUSE | FL_FREE_SIZE, FL_FULLBORDER,
_("Find & Replace")); // RVDK_PATCH_5 _("Find & Replace")); // RVDK_PATCH_5
if (ow < 0) { if (ow < 0) {
ow = fd_form_search->form_search->w; ow = search_form->form_search->w;
oh = fd_form_search->form_search->h; 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 // 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; fReplaceEnabled = fEnable;
if (fEnable) { if (fEnable) {
fl_activate_object(fd_fs->replace_button); fl_activate_object(search_form->replace_button);
fl_activate_object(fd_fs->replaceall_button); fl_activate_object(search_form->replaceall_button);
fl_activate_object(fd_fs->input_replace); fl_activate_object(search_form->input_replace);
fl_set_object_lcol(fd_fs->replace_button, FL_BLACK); fl_set_object_lcol(search_form->replace_button, FL_BLACK);
fl_set_object_lcol(fd_fs->replaceall_button, FL_BLACK); fl_set_object_lcol(search_form->replaceall_button, FL_BLACK);
fl_set_object_lcol(fd_fs->input_replace, FL_BLACK); fl_set_object_lcol(search_form->input_replace, FL_BLACK);
} else { } else {
fl_deactivate_object(fd_fs->replace_button); fl_deactivate_object(search_form->replace_button);
fl_deactivate_object(fd_fs->replaceall_button); fl_deactivate_object(search_form->replaceall_button);
fl_deactivate_object(fd_fs->input_replace); fl_deactivate_object(search_form->input_replace);
fl_set_object_lcol(fd_fs->replace_button, FL_INACTIVE); fl_set_object_lcol(search_form->replace_button, FL_INACTIVE);
fl_set_object_lcol(fd_fs->replaceall_button, FL_INACTIVE); fl_set_object_lcol(search_form->replaceall_button, FL_INACTIVE);
fl_set_object_lcol(fd_fs->input_replace, 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(search_form->input_search, ls.c_str());
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();
} }

View File

@ -6,78 +6,81 @@
#pragma interface #pragma interface
#endif #endif
#include "LString.h"
#include FORMS_H_LOCATION #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 LyXFindReplace0
This is a virtual base class. It does not handle text specific This is a virtual base class. It does not handle text specific
items. It only manages the Find & Replace form and the variables. 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. - A history list for search and replace strings.
These 2 stringlists should match, so that you can replay previous replaces. 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 If you select another search string, then the first choice should be the
replace string you have typed before. replace string you have typed before.
- regex searches (I'm working on that -- dnaber, 1999-02-24) - regex searches (I'm working on that -- dnaber, 1999-02-24)
*/ */
class LyXFindReplace0 {
class SearchForm {
public: 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 /// Initialize internal variables and dialog
virtual void StartSearch(); void StartSearch(LyXFindReplace *);
///
void replaceEnabled(bool fEnabled);
///
bool replaceEnabled() const { return fReplaceEnabled; }
// Callbacks from form // Callbacks from form
/// ///
virtual void SearchCancelCB(); 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();
// Return values // Return values
/// ///
bool CaseSensitive() { return fCaseSensitive; } void SetSearchString(string const & ls);
/// ///
bool MatchWord() { return fMatchWord; } string ReplaceString() const;
///
string const SearchString() { return lsSearch; }
///
void SetSearchString(string const &ls);
///
string const ReplaceString();
/// ///
bool ValidSearchData() { return !lsSearch.empty(); } bool ValidSearchData() const { return !(SearchString().empty()); }
private:
///
FD_form_search * search_form;
/// replace buttons enabled?
bool fReplaceEnabled;
}; };
#endif #endif

View File

@ -10,73 +10,35 @@
#include <config.h> #include <config.h>
#include <cctype>
#include <cstring>
#include <cstdlib>
#ifdef __GNUG__ #ifdef __GNUG__
#pragma implementation #pragma implementation
#endif #endif
#include "LString.h"
#include "lyx_main.h"
#include FORMS_H_LOCATION
#include "form1.h"
#include "lyxfr0.h"
#include "lyxfr1.h" #include "lyxfr1.h"
#include "lyxfunc.h"
#include "debug.h"
#include "lyxtext.h" #include "lyxtext.h"
#include "gettext.h"
#include "LyXView.h" #include "LyXView.h"
#include "lyx_gui_misc.h"
#include "minibuffer.h" #include "minibuffer.h"
#include "support/lstrings.h"
#include "support/textutils.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 // Returns the current selection. If nothing is selected or if the selection
// spans 2 paragraphs, an empty string is returned. // spans 2 paragraphs, an empty string is returned.
string const GetCurrentSelectionAsString(LyXText * lt); static
string 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)
{ {
char sz[LYXSEARCH_MAXLEN]; string sz;
sz[0] = 0;
LyXParagraph * par = lt->cursor.par; 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) // (selected) and (begin/end in same paragraph)
LyXParagraph::size_type pos = LyXParagraph::size_type pos =
lt->sel_start_cursor.pos; lt->sel_start_cursor.pos;
LyXParagraph::size_type endpos = LyXParagraph::size_type endpos =
lt->sel_end_cursor.pos; lt->sel_end_cursor.pos;
int i = 0;
bool fPrevIsSpace = false; bool fPrevIsSpace = false;
char ch; char ch;
while ((i < LYXSEARCH_MAXLEN - 2) && while (pos < par->Last() && pos < endpos) {
(pos < par->Last()) && (pos < endpos)) {
ch = par->GetChar(pos); ch = par->GetChar(pos);
//HB??: Maybe (ch <= ' ') //HB??: Maybe (ch <= ' ')
@ -86,24 +48,23 @@ string const GetCurrentSelectionAsString(LyXText * lt)
++pos; // Next text pos ++pos; // Next text pos
continue; // same search pos continue; // same search pos
} }
sz[i] = ' '; sz += ' ';
fPrevIsSpace = true; fPrevIsSpace = true;
} else { } else {
sz[i] = ch; sz += ch;
fPrevIsSpace = false; fPrevIsSpace = false;
} }
++pos; ++pos;
++i;
} }
sz[i] = 0;
} }
return string(sz); return sz;
} }
// If nothing selected, select the word at the cursor. // If nothing selected, select the word at the cursor.
// Returns the current selection // Returns the current selection
string const GetSelectionOrWordAtCursor(LyXText * lt) static inline
string GetSelectionOrWordAtCursor(LyXText * lt)
{ {
lt->SelectWordWhenUnderCursor(); lt->SelectWordWhenUnderCursor();
return GetCurrentSelectionAsString(lt); return GetCurrentSelectionAsString(lt);
@ -112,6 +73,7 @@ string const GetSelectionOrWordAtCursor(LyXText * lt)
// This is a copy of SetSelectionOverString from text.C // This is a copy of SetSelectionOverString from text.C
// It does the same, but uses only the length as a parameter // It does the same, but uses only the length as a parameter
static inline
void SetSelectionOverLenChars(LyXText * lt, int len) void SetSelectionOverLenChars(LyXText * lt, int len)
{ {
lt->sel_cursor = lt->cursor; 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(); bv = b;
SetReplaceEnabled(!current_view->buffer()->isReadonly()); SF.StartSearch(this);
SF.replaceEnabled(!bv->buffer()->isReadonly());
searchForward = true; searchForward = true;
if (lsSearch.empty()) if (SF.SearchString().empty())
SetSearchString(GetSelectionOrWordAtCursor(current_view->text)); SF.SetSearchString(GetSelectionOrWordAtCursor(bv->text));
} }
// TODO?: the user can insert multiple spaces with this // TODO?: the user can insert multiple spaces with this
// routine (1999-01-11, dnaber) // routine (1999-01-11, dnaber)
void LyXFindReplace1::SearchReplaceCB() void LyXFindReplace::SearchReplaceCB()
{ {
if (!current_view->available()) return; if (!bv->available()) return;
if (current_view->buffer()->isReadonly()) return; if (bv->buffer()->isReadonly()) return;
// CutSelection cannot cut a single space, so we have to stop // CutSelection cannot cut a single space, so we have to stop
// in order to avoid endless loop :-( // in order to avoid endless loop :-(
ReInitFromForm(); if (SF.SearchString().length() == 0
if (SearchString().length() == 0 || (SearchString().length() == 1 || (SF.SearchString().length() == 1
&& SearchString()[0] == ' ') ) { && SF.SearchString()[0] == ' ') ) {
WriteAlert(_("Sorry!"), _("You cannot replace a single space, " WriteAlert(_("Sorry!"), _("You cannot replace a single space, "
"nor an empty character.")); "nor an empty character."));
return; return;
} }
string const replacestring = ReplaceString(); string const replacestring = SF.ReplaceString();
current_view->hideCursor(); bv->hideCursor();
current_view->update(-2); bv->update(-2);
LyXText * ltCur = current_view->text; LyXText * ltCur = bv->text;
if (ltCur->selection) { if (ltCur->selection) {
// clear the selection (if there is any) // clear the selection (if there is any)
current_view->toggleSelection(false); bv->toggleSelection(false);
current_view->text-> bv->text->
ReplaceSelectionWithString(replacestring.c_str()); ReplaceSelectionWithString(replacestring.c_str());
current_view->text-> bv->text->
SetSelectionOverString(replacestring.c_str()); SetSelectionOverString(replacestring.c_str());
current_view->update(1); bv->update(1);
} }
// jump to next match: // jump to next match:
SearchCB( searchForward ); SearchCB(searchForward);
} }
// replaces all occurences of a string (1999-01-15, dnaber@mini.gt.owl.de) // 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 (!bv->available()) return;
if (current_view->buffer()->isReadonly()) return; if (bv->buffer()->isReadonly()) return;
// CutSelection cannot cut a single space, so we have to stop // CutSelection cannot cut a single space, so we have to stop
// in order to avoid endless loop :-( // in order to avoid endless loop :-(
ReInitFromForm(); if (SF.SearchString().length() == 0
if (SearchString().length() == 0 || (SearchString().length() == 1 || (SF.SearchString().length() == 1
&& SearchString()[0] == ' ') ) { && SF.SearchString()[0] == ' ') ) {
WriteAlert(_("Sorry!"), _("You cannot replace a single space, " WriteAlert(_("Sorry!"), _("You cannot replace a single space, "
"nor an empty character.")); "nor an empty character."));
return; return;
} }
string const replacestring = ReplaceString(); string const replacestring = SF.ReplaceString();
current_view->hideCursor(); bv->hideCursor();
// start at top // start at top
current_view->text->ClearSelection(); bv->text->ClearSelection();
current_view->text->CursorTop(); bv->text->CursorTop();
int replace_count = 0; int replace_count = 0;
LyXText * ltCur; LyXText * ltCur;
do { do {
ltCur = current_view->text; ltCur = bv->text;
if (ltCur->selection) { if (ltCur->selection) {
current_view->update(-2); bv->update(-2);
current_view->toggleSelection(false); bv->toggleSelection(false);
current_view->text-> bv->text->
ReplaceSelectionWithString(replacestring.c_str()); ReplaceSelectionWithString(replacestring.c_str());
current_view->text-> bv->text->
SetSelectionOverString(replacestring.c_str()); SetSelectionOverString(replacestring.c_str());
current_view->update(1); bv->update(1);
++replace_count; ++replace_count;
} }
} while( SearchCB(true) ); } while (SearchCB(true));
if( replace_count == 0 ) { if( replace_count == 0 ) {
LyXBell(); LyXBell();
current_view->owner()->getMiniBuffer()->Set( bv->owner()->getMiniBuffer()->Set(
_("String not found!")); _("String not found!"));
} else { } else {
if (replace_count == 1) { if (replace_count == 1) {
current_view->owner()->getMiniBuffer()->Set( bv->owner()->getMiniBuffer()->Set(
_("1 string has been replaced.")); _("1 string has been replaced."));
} else { } else {
string str = tostr(replace_count); string str = tostr(replace_count);
str += _(" strings have been replaced."); 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 // store search direction
searchForward = fForward; searchForward = fForward;
if (!current_view->available()) if (!bv->available())
return false; return false;
current_view->hideCursor(); bv->hideCursor();
current_view->update(-2); bv->update(-2);
LyXText * ltCur = current_view->text; LyXText * ltCur = bv->text;
if (ltCur->selection) if (ltCur->selection)
ltCur->cursor = fForward ? ltCur->sel_end_cursor : ltCur->cursor = fForward ? ltCur->sel_end_cursor :
ltCur->sel_start_cursor; ltCur->sel_start_cursor;
ReInitFromForm(); iLenSelected = SF.SearchString().length();
iLenSelected = SearchString().length();
bool result; bool result;
if (!ValidSearchData() || if (!SF.ValidSearchData() ||
(fForward ? SearchForward(ltCur) : SearchBackward(ltCur))) { (fForward ? SearchForward(ltCur) : SearchBackward(ltCur))) {
current_view->update(-2); bv->update(-2);
// clear the selection (if there is any) // clear the selection (if there is any)
current_view->toggleSelection(); bv->toggleSelection();
current_view->text->ClearSelection(); bv->text->ClearSelection();
// set the new selection // set the new selection
SetSelectionOverLenChars(current_view->text, iLenSelected); SetSelectionOverLenChars(bv->text, iLenSelected);
current_view->toggleSelection(false); bv->toggleSelection(false);
current_view->owner()->getMiniBuffer()->Set(_("Found.")); bv->owner()->getMiniBuffer()->Set(_("Found."));
result = true; result = true;
} else { } else {
LyXBell(); LyXBell();
current_view->owner()->getMiniBuffer()->Set(_("String not found!")); bv->owner()->getMiniBuffer()->Set(_("String not found!"));
result = false; result = false;
} }
if (current_view->focus()) if (bv->focus())
current_view->showCursor(); bv->showCursor();
return result; return result;
} }
@ -275,7 +247,7 @@ bool LyXFindReplace1::SearchCB(bool fForward)
// if the string can be found: return true and set the cursor to // if the string can be found: return true and set the cursor to
// the new position // the new position
// (was: LyXText::SearchForward(char const* string) in text2.C ) // (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 * par = lt->cursor.par;
LyXParagraph::size_type pos = lt->cursor.pos; 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 // if the string can be found: return true and set the cursor to
// the new position // the new position
// (was: LyXText::SearchBackward(char const* string) in text2.C ) // (was: LyXText::SearchBackward(char const* string) in text2.C )
bool LyXFindReplace1::SearchBackward(LyXText * lt) bool LyXFindReplace::SearchBackward(LyXText * lt)
{ {
LyXParagraph * par = lt->cursor.par; LyXParagraph * par = lt->cursor.par;
int pos = lt->cursor.pos; int pos = lt->cursor.pos;
@ -331,9 +303,9 @@ return value is
= 0 if chSearch == ch2 = 0 if chSearch == ch2
< 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 (chSearch - chText);
return (toupper(chSearch) - toupper(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 // returns true if the search string is at the specified position
// (Copied from the original "LyXText::IsStringInText" in text2.C ) // (Copied from the original "LyXText::IsStringInText" in text2.C )
bool LyXFindReplace1::IsSearchStringInText(LyXParagraph * par, bool LyXFindReplace::IsSearchStringInText(LyXParagraph * par,
LyXParagraph::size_type pos) LyXParagraph::size_type pos) const
{ {
if (!par) return false; if (!par) return false;
@ -352,8 +324,8 @@ bool LyXFindReplace1::IsSearchStringInText(LyXParagraph * par,
int iText = 0; int iText = 0;
string::size_type iSrch = 0; string::size_type iSrch = 0;
while (pos + iText < par->Last() && while (pos + iText < par->Last() &&
iSrch < SearchString().length()) { iSrch < SF.SearchString().length()) {
chSrch = SearchString()[iSrch]; chSrch = SF.SearchString()[iSrch];
chText = par->GetChar(pos+iText); chText = par->GetChar(pos+iText);
if (chText == ' ') { if (chText == ' ') {
if (fPrevIsSpace) { if (fPrevIsSpace) {
@ -370,10 +342,10 @@ bool LyXFindReplace1::IsSearchStringInText(LyXParagraph * par,
++iText; ++iText;
} }
if (iSrch < SearchString().length()) if (iSrch < SF.SearchString().length())
return false; return false;
if (!MatchWord() if (!SF.MatchWord()
|| ((pos <= 0 || !IsLetterCharOrDigit(par->GetChar(pos - 1))) || ((pos <= 0 || !IsLetterCharOrDigit(par->GetChar(pos - 1)))
&& (pos + iText >= par->Last() && (pos + iText >= par->Last()
|| !IsLetterCharOrDigit(par->GetChar(pos + iText))))) { || !IsLetterCharOrDigit(par->GetChar(pos + iText))))) {

View File

@ -6,44 +6,44 @@
#pragma interface #pragma interface
#endif #endif
#include FORMS_H_LOCATION
#include "lyxparagraph.h" #include "lyxparagraph.h"
#include "lyxfr0.h"
class LyXText; class LyXText;
/** /**
LyXFindReplace1" LyXFindReplace"
This class implements Find & Replace in LyXText texts. It is based on This class implements Find & Replace in LyXText texts. It is based on
LyXFindReplace0, which implements the form related stuff. (see lyxfr0.h) LyXFindReplace0, which implements the form related stuff. (see lyxfr0.h)
*/ */
class LyXFindReplace1 : public LyXFindReplace0 { class LyXFindReplace {
public: public:
/// ///
LyXFindReplace1() : LyXFindReplace0() {}; LyXFindReplace();
/// ///
~LyXFindReplace1() {}; ~LyXFindReplace();
/// Initialize internal variables and search form /// 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(); void SearchReplaceAllCB();
protected: private:
/// Set by IsSearchStringInText: /// Set by IsSearchStringInText:
int iLenSelected; mutable int iLenSelected;
/// Direction we are searching: /// Direction we are searching:
bool searchForward; bool searchForward;
/// ///
bool SearchForward(LyXText *lt); bool SearchForward(LyXText * lt);
/// ///
bool SearchBackward(LyXText *lt); bool SearchBackward(LyXText * lt);
/** Compares 2 char values. /** Compares 2 char values.
return value is return value is
@ -53,9 +53,13 @@ protected:
\item < 0 if ch1 < ch2 \item < 0 if ch1 < ch2
\end{itemize} \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 /// returns true if the specified string is at the specified position
bool IsSearchStringInText(LyXParagraph * par, bool IsSearchStringInText(LyXParagraph * par,
LyXParagraph::size_type pos); LyXParagraph::size_type pos) const;
///
SearchForm SF;
///
BufferView * bv;
}; };
#endif #endif

View File

@ -66,6 +66,7 @@
#include "ImportNoweb.h" #include "ImportNoweb.h"
#include "layout.h" #include "layout.h"
#include "WorkArea.h" #include "WorkArea.h"
#include "lyxfr1.h"
extern bool cursor_follows_scrollbar; extern bool cursor_follows_scrollbar;
@ -97,7 +98,6 @@ extern LyXAction lyxaction;
extern tex_accent_struct get_accent(kb_action action); extern tex_accent_struct get_accent(kb_action action);
extern void AutoSave(); extern void AutoSave();
extern void MenuSearch();
extern void SetUpdateTimer(float timer = 0.3); extern void SetUpdateTimer(float timer = 0.3);
extern void FreeUpdateTimer(); extern void FreeUpdateTimer();
extern bool PreviewDVI(Buffer *); extern bool PreviewDVI(Buffer *);
@ -857,7 +857,14 @@ string LyXFunc::Dispatch(int ac,
break; break;
case LFUN_MENUSEARCH: 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; break;
case LFUN_PASTE: case LFUN_PASTE:

View File

@ -1731,7 +1731,7 @@ int LyXParagraph::BeginningOfMainBody() const
&& GetChar(i) != LyXParagraph::META_NEWLINE && GetChar(i) != LyXParagraph::META_NEWLINE
) { ) {
++i; ++i;
char previous_char, temp; char previous_char = 0, temp = 0;
if (i < size() if (i < size()
&& (previous_char = GetChar(i)) != LyXParagraph::META_NEWLINE) { && (previous_char = GetChar(i)) != LyXParagraph::META_NEWLINE) {
// Yes, this ^ is supposed to be "= " not "==" // Yes, this ^ is supposed to be "= " not "=="