From f88cee29f6737f5eb6623e5e6cbdbf3ec0bbaedd Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=BCrgen=20Vigna?= Date: Tue, 6 Mar 2001 10:20:33 +0000 Subject: [PATCH] Edwins f&r GUII patch with a small fix. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@1678 a592a061-630c-0410-9148-cb99ea01b6c8 --- forms/ChangeLog | 4 + forms/form1.fd | 214 +------------ po/POTFILES.in | 44 +-- src/ChangeLog | 8 + src/Makefile.am | 6 +- src/form1.C | 49 --- src/form1.h | 9 - src/frontends/Dialogs.h | 2 + src/frontends/xforms/ChangeLog | 7 + src/frontends/xforms/Dialogs.C | 2 + src/frontends/xforms/FormSearch.C | 127 ++++++++ src/frontends/xforms/FormSearch.h | 58 ++++ src/frontends/xforms/Makefile.am | 4 + src/frontends/xforms/form_search.C | 109 +++++++ src/frontends/xforms/form_search.h | 28 ++ src/frontends/xforms/forms/form_search.fd | 214 +++++++++++++ src/frontends/xforms/forms/makefile | 1 + src/lyxfind.C | 195 ++++++++++++ src/lyxfind.h | 32 ++ src/lyxfr0.C | 149 --------- src/lyxfr0.h | 97 ------ src/lyxfr1.C | 358 ---------------------- src/lyxfr1.h | 64 ---- src/lyxfunc.C | 13 +- src/lyxtext.h | 12 - src/text2.C | 69 ----- 26 files changed, 827 insertions(+), 1048 deletions(-) create mode 100644 src/frontends/xforms/FormSearch.C create mode 100644 src/frontends/xforms/FormSearch.h create mode 100644 src/frontends/xforms/form_search.C create mode 100644 src/frontends/xforms/form_search.h create mode 100644 src/frontends/xforms/forms/form_search.fd create mode 100644 src/lyxfind.C create mode 100644 src/lyxfind.h delete mode 100644 src/lyxfr0.C delete mode 100644 src/lyxfr0.h delete mode 100644 src/lyxfr1.C delete mode 100644 src/lyxfr1.h diff --git a/forms/ChangeLog b/forms/ChangeLog index 43b57703fb..c73dd50cff 100644 --- a/forms/ChangeLog +++ b/forms/ChangeLog @@ -1,3 +1,7 @@ +2001-03-05 Edwin Leuven + + * form1.fd: search_form deleted + 2001-02-26 Lars Gullik Bjønnes * layout_forms.fd: delete diff --git a/forms/form1.fd b/forms/form1.fd index 1ac333c4aa..2e552f912a 100644 --- a/forms/form1.fd +++ b/forms/form1.fd @@ -3,7 +3,7 @@ Magic: 13000 Internal Form Definition File (do not change) -Number of forms: 4 +Number of forms: 3 Unit of measure: FL_COORD_PIXEL =============== FORM =============== @@ -249,7 +249,7 @@ argument: -------------------- class: FL_BEGIN_GROUP type: 0 -box: 0 10 10 0 +box: 0 0 0 0 boxtype: FL_NO_BOX colors: FL_COL1 FL_MCOL alignment: FL_ALIGN_CENTER @@ -687,7 +687,7 @@ argument: 2 -------------------- class: FL_BEGIN_GROUP type: 0 -box: 0 10 10 0 +box: 0 0 0 0 boxtype: FL_NO_BOX colors: FL_COL1 FL_MCOL alignment: FL_ALIGN_CENTER @@ -867,7 +867,7 @@ argument: -------------------- class: FL_BEGIN_GROUP type: 0 -box: 0 10 10 0 +box: 0 0 0 0 boxtype: FL_NO_BOX colors: FL_COL1 FL_MCOL alignment: FL_ALIGN_CENTER @@ -975,7 +975,7 @@ argument: -------------------- class: FL_BEGIN_GROUP type: 0 -box: 0 10 10 0 +box: 0 0 0 0 boxtype: FL_NO_BOX colors: FL_COL1 FL_MCOL alignment: FL_ALIGN_CENTER @@ -1392,209 +1392,5 @@ name: timer callback: argument: -=============== FORM =============== -Name: form_search -Width: 440 -Height: 160 -Number of Objects: 11 - --------------------- -class: FL_BOX -type: UP_BOX -box: 0 0 440 160 -boxtype: FL_UP_BOX -colors: FL_COL1 FL_COL1 -alignment: FL_ALIGN_CENTER -style: FL_NORMAL_STYLE -size: FL_DEFAULT_SIZE -lcol: FL_BLACK -label: -shortcut: -resize: FL_RESIZE_ALL -gravity: FL_NoGravity FL_NoGravity -name: -callback: -argument: - --------------------- -class: FL_FRAME -type: ENGRAVED_FRAME -box: 300 10 130 80 -boxtype: FL_NO_BOX -colors: FL_BLACK FL_COL1 -alignment: FL_ALIGN_CENTER -style: FL_NORMAL_STYLE -size: FL_DEFAULT_SIZE -lcol: FL_BLACK -label: -shortcut: -resize: FL_RESIZE_NONE -gravity: FL_NorthEast FL_NorthEast -name: -callback: -argument: - --------------------- -class: FL_INPUT -type: NORMAL_INPUT -box: 110 10 180 30 -boxtype: FL_DOWN_BOX -colors: FL_COL1 FL_MCOL -alignment: FL_ALIGN_LEFT -style: FL_NORMAL_STYLE -size: FL_NORMAL_SIZE -lcol: FL_BLACK -label: Find|#n -shortcut: -resize: FL_RESIZE_X -gravity: FL_NorthWest FL_NorthEast -name: input_search -callback: -argument: - --------------------- -class: FL_INPUT -type: NORMAL_INPUT -box: 110 40 180 30 -boxtype: FL_DOWN_BOX -colors: FL_COL1 FL_MCOL -alignment: FL_ALIGN_LEFT -style: FL_NORMAL_STYLE -size: FL_NORMAL_SIZE -lcol: FL_BLACK -label: Replace with|#W -shortcut: -resize: FL_RESIZE_X -gravity: FL_NorthWest FL_NorthEast -name: input_replace -callback: -argument: - --------------------- -class: FL_BUTTON -type: NORMAL_BUTTON -box: 200 80 90 30 -boxtype: FL_UP_BOX -colors: FL_COL1 FL_COL1 -alignment: FL_ALIGN_CENTER -style: FL_NORMAL_STYLE -size: FL_NORMAL_SIZE -lcol: FL_BLACK -label: @>|#F^s -shortcut: -resize: FL_RESIZE_NONE -gravity: FL_SouthEast FL_SouthEast -name: -callback: SearchForwardCB -argument: 0 - --------------------- -class: FL_BUTTON -type: NORMAL_BUTTON -box: 110 80 90 30 -boxtype: FL_UP_BOX -colors: FL_COL1 FL_COL1 -alignment: FL_ALIGN_CENTER -style: FL_NORMAL_STYLE -size: FL_NORMAL_SIZE -lcol: FL_BLACK -label: @<|#B^r -shortcut: -resize: FL_RESIZE_NONE -gravity: FL_SouthEast FL_SouthEast -name: -callback: SearchBackwardCB -argument: 0 - --------------------- -class: FL_BUTTON -type: NORMAL_BUTTON -box: 110 120 90 30 -boxtype: FL_UP_BOX -colors: FL_COL1 FL_COL1 -alignment: FL_ALIGN_CENTER -style: FL_NORMAL_STYLE -size: FL_NORMAL_SIZE -lcol: FL_BLACK -label: Replace|#R#r -shortcut: -resize: FL_RESIZE_NONE -gravity: FL_SouthEast FL_SouthEast -name: replace_button -callback: SearchReplaceCB -argument: 0 - --------------------- -class: FL_BUTTON -type: NORMAL_BUTTON -box: 350 120 80 30 -boxtype: FL_UP_BOX -colors: FL_COL1 FL_COL1 -alignment: FL_ALIGN_CENTER -style: FL_NORMAL_STYLE -size: FL_NORMAL_SIZE -lcol: FL_BLACK -label: Close|^[ -shortcut: -resize: FL_RESIZE_NONE -gravity: FL_SouthEast FL_SouthEast -name: -callback: SearchCancelCB -argument: 0 - --------------------- -class: FL_CHECKBUTTON -type: PUSH_BUTTON -box: 300 20 150 30 -boxtype: FL_NO_BOX -colors: FL_COL1 FL_YELLOW -alignment: FL_ALIGN_CENTER -style: FL_NORMAL_STYLE -size: FL_DEFAULT_SIZE -lcol: FL_BLACK -label: Case sensitive|#s#S -shortcut: -resize: FL_RESIZE_NONE -gravity: FL_NorthEast FL_NorthEast -name: btnCaseSensitive -callback: -argument: 0 - --------------------- -class: FL_CHECKBUTTON -type: PUSH_BUTTON -box: 300 50 150 30 -boxtype: FL_NO_BOX -colors: FL_COL1 FL_YELLOW -alignment: FL_ALIGN_CENTER -style: FL_NORMAL_STYLE -size: FL_DEFAULT_SIZE -lcol: FL_BLACK -label: Match word|#M#m -shortcut: -resize: FL_RESIZE_NONE -gravity: FL_NorthEast FL_NorthEast -name: btnMatchWord -callback: -argument: 0 - --------------------- -class: FL_BUTTON -type: NORMAL_BUTTON -box: 200 120 90 30 -boxtype: FL_UP_BOX -colors: FL_COL1 FL_COL1 -alignment: FL_ALIGN_CENTER -style: FL_NORMAL_STYLE -size: FL_NORMAL_SIZE -lcol: FL_BLACK -label: Replace All|#A#a -shortcut: -resize: FL_RESIZE_NONE -gravity: FL_SouthEast FL_SouthEast -name: replaceall_button -callback: SearchReplaceAllCB -argument: 0 - ============================== -------------------- diff --git a/po/POTFILES.in b/po/POTFILES.in index adbe2e8da4..daf35bfa7f 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -64,6 +64,7 @@ src/frontends/kde/refdlg.C src/frontends/kde/tabcreatedlg.C src/frontends/kde/tocdlg.C src/frontends/kde/urldlg.C +src/frontends/qt2/FormCharacter.C src/frontends/qt2/FormCopyright.C src/frontends/qt2/FormParagraph.C src/frontends/qt2/FormPrint.C @@ -71,52 +72,54 @@ src/frontends/qt2/FormTabularCreate.C src/frontends/qt2/paragraphdlgimpl.C src/frontends/qt2/tabularcreatedlgimpl.C src/frontends/xforms/FormBase.h -src/frontends/xforms/FormBibitem.C src/frontends/xforms/form_bibitem.C -src/frontends/xforms/FormBibtex.C +src/frontends/xforms/FormBibitem.C src/frontends/xforms/form_bibtex.C +src/frontends/xforms/FormBibtex.C src/frontends/xforms/form_browser.C -src/frontends/xforms/FormCharacter.C src/frontends/xforms/form_character.C -src/frontends/xforms/FormCitation.C +src/frontends/xforms/FormCharacter.C src/frontends/xforms/form_citation.C -src/frontends/xforms/FormCopyright.C +src/frontends/xforms/FormCitation.C src/frontends/xforms/form_copyright.C -src/frontends/xforms/FormDocument.C +src/frontends/xforms/FormCopyright.C src/frontends/xforms/form_document.C -src/frontends/xforms/FormError.C +src/frontends/xforms/FormDocument.C src/frontends/xforms/form_error.C -src/frontends/xforms/FormGraphics.C +src/frontends/xforms/FormError.C src/frontends/xforms/form_graphics.C -src/frontends/xforms/FormInclude.C +src/frontends/xforms/FormGraphics.C src/frontends/xforms/form_include.C -src/frontends/xforms/FormIndex.C +src/frontends/xforms/FormInclude.C src/frontends/xforms/form_index.C +src/frontends/xforms/FormIndex.C src/frontends/xforms/FormInset.h src/frontends/xforms/FormLog.C -src/frontends/xforms/FormParagraph.C src/frontends/xforms/form_paragraph.C -src/frontends/xforms/FormPreamble.C +src/frontends/xforms/FormParagraph.C src/frontends/xforms/form_preamble.C -src/frontends/xforms/FormPreferences.C +src/frontends/xforms/FormPreamble.C src/frontends/xforms/form_preferences.C -src/frontends/xforms/FormPrint.C +src/frontends/xforms/FormPreferences.C src/frontends/xforms/form_print.C -src/frontends/xforms/FormRef.C +src/frontends/xforms/FormPrint.C src/frontends/xforms/form_ref.C +src/frontends/xforms/FormRef.C +src/frontends/xforms/form_search.C +src/frontends/xforms/FormSearch.C src/frontends/xforms/FormSplash.C -src/frontends/xforms/FormTabular.C src/frontends/xforms/form_tabular.C -src/frontends/xforms/FormTabularCreate.C +src/frontends/xforms/FormTabular.C src/frontends/xforms/form_tabular_create.C -src/frontends/xforms/FormToc.C +src/frontends/xforms/FormTabularCreate.C src/frontends/xforms/form_toc.C -src/frontends/xforms/FormUrl.C +src/frontends/xforms/FormToc.C src/frontends/xforms/form_url.C +src/frontends/xforms/FormUrl.C src/frontends/xforms/FormVCLog.C src/frontends/xforms/input_validators.C src/frontends/xforms/Menubar_pimpl.C -src/frontends/xforms/xform_helpers.C +src/frontends/xforms/xforms_helpers.C src/gettext.h src/importer.C src/insets/figinset.C @@ -151,6 +154,7 @@ src/LColor.C src/LyXAction.C src/lyx.C src/lyx_cb.C +src/lyxfind.C src/lyxfont.C src/lyxfr0.C src/lyxfr1.C diff --git a/src/ChangeLog b/src/ChangeLog index eb20f0c317..0116dc70b0 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,11 @@ +2001-03-06 Juergen Vigna + + * lyxfind.C (IsStringInText): put parentes around expressions. + +2001-03-05 Edwin Leuven + + * lyxfind.[Ch]: find stuff moved out of text2.C/lyxtext.h + 2001-02-23 John Levon * lyx_main.C: add ISO_Left_Tab as bind synonym for Tab diff --git a/src/Makefile.am b/src/Makefile.am index 360de916e6..72c92a32a6 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -151,10 +151,8 @@ lyx_SOURCES = \ lyxcursor.h \ lyxfont.C \ lyxfont.h \ - lyxfr0.C \ - lyxfr0.h \ - lyxfr1.C \ - lyxfr1.h \ + lyxfind.C \ + lyxfind.h \ lyxfunc.C \ lyxfunc.h \ lyxlex.C \ diff --git a/src/form1.C b/src/form1.C index 7c1e5b239f..e05c888575 100644 --- a/src/form1.C +++ b/src/form1.C @@ -274,52 +274,3 @@ FD_FileDlg *create_form_FileDlg(void) } /*---------------------------------------*/ -FD_form_search *create_form_form_search(void) -{ - FL_OBJECT *obj; - FD_form_search *fdui = (FD_form_search *) fl_calloc(1, sizeof(FD_form_search)); - - fdui->form_search = fl_bgn_form(FL_NO_BOX, 440, 160); - obj = fl_add_box(FL_UP_BOX, 0, 0, 440, 160, ""); - obj = fl_add_frame(FL_ENGRAVED_FRAME, 300, 10, 130, 80, ""); - fl_set_object_gravity(obj, FL_NorthEast, FL_NorthEast); - fdui->input_search = obj = fl_add_input(FL_NORMAL_INPUT, 110, 10, 180, 30, idex(_("Find|#n")));fl_set_button_shortcut(obj, scex(_("Find|#n")), 1); - fl_set_object_lsize(obj, FL_NORMAL_SIZE); - fl_set_object_gravity(obj, FL_NorthWest, FL_NorthEast); - fl_set_object_resize(obj, FL_RESIZE_X); - fdui->input_replace = obj = fl_add_input(FL_NORMAL_INPUT, 110, 40, 180, 30, idex(_("Replace with|#W")));fl_set_button_shortcut(obj, scex(_("Replace with|#W")), 1); - fl_set_object_lsize(obj, FL_NORMAL_SIZE); - fl_set_object_gravity(obj, FL_NorthWest, FL_NorthEast); - fl_set_object_resize(obj, FL_RESIZE_X); - obj = fl_add_button(FL_NORMAL_BUTTON, 200, 80, 90, 30, idex(_("@>|#F^s")));fl_set_button_shortcut(obj, scex(_("@>|#F^s")), 1); - fl_set_object_lsize(obj, FL_NORMAL_SIZE); - fl_set_object_gravity(obj, FL_SouthEast, FL_SouthEast); - fl_set_object_callback(obj, SearchForwardCB, 0); - obj = fl_add_button(FL_NORMAL_BUTTON, 110, 80, 90, 30, idex(_("@<|#B^r")));fl_set_button_shortcut(obj, scex(_("@<|#B^r")), 1); - fl_set_object_lsize(obj, FL_NORMAL_SIZE); - fl_set_object_gravity(obj, FL_SouthEast, FL_SouthEast); - fl_set_object_callback(obj, SearchBackwardCB, 0); - fdui->replace_button = obj = fl_add_button(FL_NORMAL_BUTTON, 110, 120, 90, 30, idex(_("Replace|#R#r")));fl_set_button_shortcut(obj, scex(_("Replace|#R#r")), 1); - fl_set_object_lsize(obj, FL_NORMAL_SIZE); - fl_set_object_gravity(obj, FL_SouthEast, FL_SouthEast); - fl_set_object_callback(obj, SearchReplaceCB, 0); - obj = fl_add_button(FL_NORMAL_BUTTON, 350, 120, 80, 30, idex(_("Close|^[")));fl_set_button_shortcut(obj, scex(_("Close|^[")), 1); - fl_set_object_lsize(obj, FL_NORMAL_SIZE); - fl_set_object_gravity(obj, FL_SouthEast, FL_SouthEast); - fl_set_object_callback(obj, SearchCancelCB, 0); - fdui->btnCaseSensitive = obj = fl_add_checkbutton(FL_PUSH_BUTTON, 300, 20, 150, 30, idex(_("Case sensitive|#s#S")));fl_set_button_shortcut(obj, scex(_("Case sensitive|#s#S")), 1); - fl_set_object_gravity(obj, FL_NorthEast, FL_NorthEast); - fdui->btnMatchWord = obj = fl_add_checkbutton(FL_PUSH_BUTTON, 300, 50, 150, 30, idex(_("Match word|#M#m")));fl_set_button_shortcut(obj, scex(_("Match word|#M#m")), 1); - fl_set_object_gravity(obj, FL_NorthEast, FL_NorthEast); - fdui->replaceall_button = obj = fl_add_button(FL_NORMAL_BUTTON, 200, 120, 90, 30, idex(_("Replace All|#A#a")));fl_set_button_shortcut(obj, scex(_("Replace All|#A#a")), 1); - fl_set_object_lsize(obj, FL_NORMAL_SIZE); - fl_set_object_gravity(obj, FL_SouthEast, FL_SouthEast); - fl_set_object_callback(obj, SearchReplaceAllCB, 0); - fl_end_form(); - - fdui->form_search->fdui = fdui; - - return fdui; -} -/*---------------------------------------*/ - diff --git a/src/form1.h b/src/form1.h index d26101da33..ed1ecd820c 100644 --- a/src/form1.h +++ b/src/form1.h @@ -8,13 +8,6 @@ extern "C" void GraphicsCB(FL_OBJECT *, long); -extern "C" void SearchForwardCB(FL_OBJECT *, long); -extern "C" void SearchBackwardCB(FL_OBJECT *, long); -extern "C" void SearchReplaceCB(FL_OBJECT *, long); -extern "C" void SearchCancelCB(FL_OBJECT *, long); -extern "C" void SearchReplaceAllCB(FL_OBJECT *, long); - - /**** Forms and Objects ****/ typedef struct { FL_FORM *KeyMap; @@ -107,6 +100,4 @@ typedef struct { FL_OBJECT *replaceall_button; } FD_form_search; -extern FD_form_search * create_form_form_search(void); - #endif /* FD_KeyMap_h_ */ diff --git a/src/frontends/Dialogs.h b/src/frontends/Dialogs.h index a8cd032036..472e959c8b 100644 --- a/src/frontends/Dialogs.h +++ b/src/frontends/Dialogs.h @@ -134,6 +134,8 @@ public: Signal1 showRef; /// Signal1 createRef; + /// + Signal0 showSearch; /// pop up the splash Signal0 showSplash; /// hide the splash immediately diff --git a/src/frontends/xforms/ChangeLog b/src/frontends/xforms/ChangeLog index 97d04907f8..97a52b3a50 100644 --- a/src/frontends/xforms/ChangeLog +++ b/src/frontends/xforms/ChangeLog @@ -1,3 +1,10 @@ +2001-03-05 Edwin Leuven + + * added find/replace dialog: + * FormSearch.*: added + * form_search.*: added + * forms/form_search.fd: added + 2001-03-05 Angus Leeming * xform_helpers.[Ch]: renamed as xforms_helpers.[Ch]. diff --git a/src/frontends/xforms/Dialogs.C b/src/frontends/xforms/Dialogs.C index e078af96a9..7884a781cf 100644 --- a/src/frontends/xforms/Dialogs.C +++ b/src/frontends/xforms/Dialogs.C @@ -28,6 +28,7 @@ #include "FormPreferences.h" #include "FormPrint.h" #include "FormRef.h" +#include "FormSearch.h" #include "FormSplash.h" #include "FormTabular.h" #include "FormTabularCreate.h" @@ -68,6 +69,7 @@ Dialogs::Dialogs(LyXView * lv) dialogs_.push_back(new FormPreferences(lv, this)); dialogs_.push_back(new FormPrint(lv, this)); dialogs_.push_back(new FormRef(lv, this)); + dialogs_.push_back(new FormSearch(lv, this)); dialogs_.push_back(new FormSplash(lv, this)); dialogs_.push_back(new FormTabular(lv, this)); dialogs_.push_back(new FormTabularCreate(lv, this)); diff --git a/src/frontends/xforms/FormSearch.C b/src/frontends/xforms/FormSearch.C new file mode 100644 index 0000000000..03a113b4b3 --- /dev/null +++ b/src/frontends/xforms/FormSearch.C @@ -0,0 +1,127 @@ +/** + * \file FormSearch.C + * Copyright 2001 The LyX Team. + * See the file COPYING. + * + * \author Edwin Leuven + */ + +#include + +#include "FormSearch.h" +#include "form_search.h" +#include "gettext.h" +#include "Dialogs.h" +#include "Liason.h" +#include "LyXView.h" +#include "buffer.h" +#include "gettext.h" +#include "lyxfind.h" +#include "debug.h" + +#ifdef CXX_WORKING_NAMESPACES +using Liason::setMinibuffer; +#endif + + +FormSearch::FormSearch(LyXView * lv, Dialogs * d) + : FormBaseBD(lv, d, _("LyX: Find and Replace"), new NoRepeatedApplyReadOnlyPolicy), + dialog_(0) +{ + // let the popup be shown + // This is a permanent connection so we won't bother + // storing a copy because we won't be disconnecting. + d->showSearch.connect(slot(this, &FormSearch::show)); + // perhaps in the future we'd like a + // "search again" button/keybinding +// d->searchAgain.connect(slot(this, &FormSearch::FindNext)); +} + + +FormSearch::~FormSearch() +{ + delete dialog_; +} + + +FL_FORM * FormSearch::form() const +{ + if (dialog_) + return dialog_->form; + return 0; +} + +void FormSearch::build() +{ + dialog_ = build_search(); + // Workaround dumb xforms sizing bug + minw_ = form()->w; + minh_ = form()->h; + + // Manage the ok, apply and cancel/close buttons + bc_.setCancel(dialog_->button_cancel); + bc_.addReadOnly(dialog_->input_replace); + bc_.addReadOnly(dialog_->replace); + bc_.addReadOnly(dialog_->replaceall); + bc_.refresh(); +} + +void FormSearch::update() +{ + if (!dialog_) + return; + + bc_.readOnly(lv_->buffer()->isReadonly()); +} + +bool FormSearch::input(FL_OBJECT * obj, long) +{ + if (obj == dialog_->findnext) + Find(); + else if (obj == dialog_->findprev) + Find(false); + else if (obj == dialog_->replace) + Replace(); + else if (obj == dialog_->replaceall) + Replace(true); + + return 0; +} + +void FormSearch::Find(bool const next = true) +{ + bool found = LyXFind(lv_->view(), + fl_get_input(dialog_->input_search), + fl_get_button(dialog_->casesensitive), + fl_get_button(dialog_->matchword), + next); + + if (!found) + setMinibuffer(lv_, _("String not found!")); + }; + + +void FormSearch::Replace(bool const all = false) +{ + int replace_count = LyXReplace(lv_->view(), + fl_get_input(dialog_->input_search), + fl_get_input(dialog_->input_replace), + fl_get_button(dialog_->casesensitive), + fl_get_button(dialog_->matchword), + true, + all); + + if (replace_count == 0) { + setMinibuffer(lv_, _("String not found!")); + } else { + if (replace_count == 1) { + setMinibuffer(lv_, _("String has been replaced.")); + } else { + string str = tostr(replace_count); + str += _(" strings have been replaced."); + setMinibuffer(lv_, str.c_str()); + } + } +}; + + diff --git a/src/frontends/xforms/FormSearch.h b/src/frontends/xforms/FormSearch.h new file mode 100644 index 0000000000..66ad7acf46 --- /dev/null +++ b/src/frontends/xforms/FormSearch.h @@ -0,0 +1,58 @@ +/** + * \file FormSearch.h + * Copyright 2001 The LyX Team. + * See the file COPYING. + * + * \author Edwin Leuven + */ + +#ifndef FORMSEARCH_H +#define FORMSEARCH_H + +#include "FormBase.h" + +struct FD_form_search; +class LyXView; +class Dialogs; + +/** This class provides an XForms implementation of the FormSearch Dialog. + */ +class FormSearch : public FormBaseBD { +public: + /// + FormSearch(LyXView *, Dialogs *); + /// + ~FormSearch(); + +private: + /** Redraw the form (on receipt of a Signal indicating, for example, + * that the xform colours have been re-mapped). + */ + + /// Filter the inputs + virtual bool input(FL_OBJECT *, long); + + /// Build the popup + virtual void build(); + + /// Update the popup + virtual void update(); + + /// Searches occurance of string + /// if argument=true forward search otherwise backward search + void Find(bool const = true); + /// if argument=false replace once otherwise replace all + /// Replaces occurance of string + void Replace(bool const = false); + + /// + virtual FL_FORM * form() const; + + /// Typedefinitions from the fdesign produced Header file + FD_form_search * build_search(); + + /// Real GUI implementation. + FD_form_search * dialog_; +}; + +#endif diff --git a/src/frontends/xforms/Makefile.am b/src/frontends/xforms/Makefile.am index 60f689b7b4..a4489c5259 100644 --- a/src/frontends/xforms/Makefile.am +++ b/src/frontends/xforms/Makefile.am @@ -88,6 +88,10 @@ libxforms_la_SOURCES = \ FormRef.h \ form_ref.C \ form_ref.h \ + FormSearch.C \ + FormSearch.h \ + form_search.C \ + form_search.h \ FormSplash.C \ FormSplash.h \ form_splash.C \ diff --git a/src/frontends/xforms/form_search.C b/src/frontends/xforms/form_search.C new file mode 100644 index 0000000000..00bd8ba0ab --- /dev/null +++ b/src/frontends/xforms/form_search.C @@ -0,0 +1,109 @@ +// File modified by fdfix.sh for use by lyx (with xforms >= 0.88) and gettext +#include +#include "lyx_gui_misc.h" +#include "gettext.h" + +/* Form definition file generated with fdesign. */ + +#include FORMS_H_LOCATION +#include +#include "form_search.h" +#include "FormSearch.h" + +FD_form_search::~FD_form_search() +{ + if ( form->visible ) fl_hide_form( form ); + fl_free_form( form ); +} + + +FD_form_search * FormSearch::build_search() +{ + FL_OBJECT *obj; + FD_form_search *fdui = new FD_form_search; + + fdui->form = fl_bgn_form(FL_NO_BOX, 440, 160); + fdui->form->u_vdata = this; + obj = fl_add_box(FL_UP_BOX, 0, 0, 440, 160, ""); + obj = fl_add_frame(FL_ENGRAVED_FRAME, 300, 10, 130, 80, ""); + fl_set_object_gravity(obj, FL_NorthEast, FL_NorthEast); + { + char const * const dummy = N_("Find|#n"); + fdui->input_search = obj = fl_add_input(FL_NORMAL_INPUT, 110, 10, 180, 30, idex(_(dummy))); + fl_set_button_shortcut(obj, scex(_(dummy)), 1); + } + fl_set_object_lsize(obj, FL_NORMAL_SIZE); + fl_set_object_gravity(obj, FL_NorthWest, FL_NorthEast); + fl_set_object_resize(obj, FL_RESIZE_X); + fl_set_object_callback(obj, C_FormBaseInputCB, 0); + { + char const * const dummy = N_("Replace with|#W"); + fdui->input_replace = obj = fl_add_input(FL_NORMAL_INPUT, 110, 40, 180, 30, idex(_(dummy))); + fl_set_button_shortcut(obj, scex(_(dummy)), 1); + } + fl_set_object_lsize(obj, FL_NORMAL_SIZE); + fl_set_object_gravity(obj, FL_NorthWest, FL_NorthEast); + fl_set_object_resize(obj, FL_RESIZE_X); + fl_set_object_callback(obj, C_FormBaseInputCB, 0); + { + char const * const dummy = N_(" >|#F^s"); + fdui->findnext = obj = fl_add_button(FL_NORMAL_BUTTON, 200, 80, 90, 30, idex(_(dummy))); + fl_set_button_shortcut(obj, scex(_(dummy)), 1); + } + fl_set_object_lsize(obj, FL_NORMAL_SIZE); + fl_set_object_gravity(obj, FL_SouthEast, FL_SouthEast); + fl_set_object_callback(obj, C_FormBaseInputCB, 0); + { + char const * const dummy = N_(" <|#B^r"); + fdui->findprev = obj = fl_add_button(FL_NORMAL_BUTTON, 110, 80, 90, 30, idex(_(dummy))); + fl_set_button_shortcut(obj, scex(_(dummy)), 1); + } + fl_set_object_lsize(obj, FL_NORMAL_SIZE); + fl_set_object_gravity(obj, FL_SouthEast, FL_SouthEast); + fl_set_object_callback(obj, C_FormBaseInputCB, 0); + { + char const * const dummy = N_("Replace|#R#r"); + fdui->replace = obj = fl_add_button(FL_NORMAL_BUTTON, 110, 120, 90, 30, idex(_(dummy))); + fl_set_button_shortcut(obj, scex(_(dummy)), 1); + } + fl_set_object_lsize(obj, FL_NORMAL_SIZE); + fl_set_object_gravity(obj, FL_SouthEast, FL_SouthEast); + fl_set_object_callback(obj, C_FormBaseInputCB, 0); + { + char const * const dummy = N_("Close|^["); + fdui->button_cancel = obj = fl_add_button(FL_NORMAL_BUTTON, 350, 120, 80, 30, idex(_(dummy))); + fl_set_button_shortcut(obj, scex(_(dummy)), 1); + } + fl_set_object_lsize(obj, FL_NORMAL_SIZE); + fl_set_object_gravity(obj, FL_SouthEast, FL_SouthEast); + fl_set_object_callback(obj, C_FormBaseCancelCB, 0); + { + char const * const dummy = N_("Case sensitive|#s#S"); + fdui->casesensitive = obj = fl_add_checkbutton(FL_PUSH_BUTTON, 300, 20, 150, 30, idex(_(dummy))); + fl_set_button_shortcut(obj, scex(_(dummy)), 1); + } + fl_set_object_gravity(obj, FL_NorthEast, FL_NorthEast); + fl_set_object_callback(obj, C_FormBaseInputCB, 0); + { + char const * const dummy = N_("Match word|#M#m"); + fdui->matchword = obj = fl_add_checkbutton(FL_PUSH_BUTTON, 300, 50, 150, 30, idex(_(dummy))); + fl_set_button_shortcut(obj, scex(_(dummy)), 1); + } + fl_set_object_gravity(obj, FL_NorthEast, FL_NorthEast); + fl_set_object_callback(obj, C_FormBaseInputCB, 0); + { + char const * const dummy = N_("Replace All|#A#a"); + fdui->replaceall = obj = fl_add_button(FL_NORMAL_BUTTON, 200, 120, 90, 30, idex(_(dummy))); + fl_set_button_shortcut(obj, scex(_(dummy)), 1); + } + fl_set_object_lsize(obj, FL_NORMAL_SIZE); + fl_set_object_gravity(obj, FL_SouthEast, FL_SouthEast); + fl_set_object_callback(obj, C_FormBaseInputCB, 0); + fl_end_form(); + + fdui->form->fdui = fdui; + + return fdui; +} +/*---------------------------------------*/ + diff --git a/src/frontends/xforms/form_search.h b/src/frontends/xforms/form_search.h new file mode 100644 index 0000000000..4147005583 --- /dev/null +++ b/src/frontends/xforms/form_search.h @@ -0,0 +1,28 @@ +// File modified by fdfix.sh for use by lyx (with xforms >= 0.88) and gettext +/** Header file generated with fdesign **/ + +#ifndef FD_form_search_h_ +#define FD_form_search_h_ + +/** Callbacks, globals and object handlers **/ +extern "C" void C_FormBaseInputCB(FL_OBJECT *, long); +extern "C" void C_FormBaseCancelCB(FL_OBJECT *, long); + + +/**** Forms and Objects ****/ +struct FD_form_search { + ~FD_form_search(); + + FL_FORM *form; + FL_OBJECT *input_search; + FL_OBJECT *input_replace; + FL_OBJECT *findnext; + FL_OBJECT *findprev; + FL_OBJECT *replace; + FL_OBJECT *button_cancel; + FL_OBJECT *casesensitive; + FL_OBJECT *matchword; + FL_OBJECT *replaceall; +}; + +#endif /* FD_form_search_h_ */ diff --git a/src/frontends/xforms/forms/form_search.fd b/src/frontends/xforms/forms/form_search.fd new file mode 100644 index 0000000000..bd9196ce63 --- /dev/null +++ b/src/frontends/xforms/forms/form_search.fd @@ -0,0 +1,214 @@ +Magic: 13000 + +Internal Form Definition File + (do not change) + +Number of forms: 1 +Unit of measure: FL_COORD_PIXEL + +=============== FORM =============== +Name: form_search +Width: 440 +Height: 160 +Number of Objects: 11 + +-------------------- +class: FL_BOX +type: UP_BOX +box: 0 0 440 160 +boxtype: FL_UP_BOX +colors: FL_COL1 FL_COL1 +alignment: FL_ALIGN_CENTER +style: FL_NORMAL_STYLE +size: FL_DEFAULT_SIZE +lcol: FL_BLACK +label: +shortcut: +resize: FL_RESIZE_ALL +gravity: FL_NoGravity FL_NoGravity +name: +callback: +argument: + +-------------------- +class: FL_FRAME +type: ENGRAVED_FRAME +box: 300 10 130 80 +boxtype: FL_NO_BOX +colors: FL_BLACK FL_COL1 +alignment: FL_ALIGN_CENTER +style: FL_NORMAL_STYLE +size: FL_DEFAULT_SIZE +lcol: FL_BLACK +label: +shortcut: +resize: FL_RESIZE_NONE +gravity: FL_NorthEast FL_NorthEast +name: +callback: +argument: + +-------------------- +class: FL_INPUT +type: NORMAL_INPUT +box: 110 10 180 30 +boxtype: FL_DOWN_BOX +colors: FL_COL1 FL_MCOL +alignment: FL_ALIGN_LEFT +style: FL_NORMAL_STYLE +size: FL_NORMAL_SIZE +lcol: FL_BLACK +label: Find|#n +shortcut: +resize: FL_RESIZE_X +gravity: FL_NorthWest FL_NorthEast +name: input_search +callback: C_FormBaseInputCB +argument: 0 + +-------------------- +class: FL_INPUT +type: NORMAL_INPUT +box: 110 40 180 30 +boxtype: FL_DOWN_BOX +colors: FL_COL1 FL_MCOL +alignment: FL_ALIGN_LEFT +style: FL_NORMAL_STYLE +size: FL_NORMAL_SIZE +lcol: FL_BLACK +label: Replace with|#W +shortcut: +resize: FL_RESIZE_X +gravity: FL_NorthWest FL_NorthEast +name: input_replace +callback: C_FormBaseInputCB +argument: 0 + +-------------------- +class: FL_BUTTON +type: NORMAL_BUTTON +box: 200 80 90 30 +boxtype: FL_UP_BOX +colors: FL_COL1 FL_COL1 +alignment: FL_ALIGN_CENTER +style: FL_NORMAL_STYLE +size: FL_NORMAL_SIZE +lcol: FL_BLACK +label: >|#F^s +shortcut: +resize: FL_RESIZE_NONE +gravity: FL_SouthEast FL_SouthEast +name: findnext +callback: C_FormBaseInputCB +argument: 0 + +-------------------- +class: FL_BUTTON +type: NORMAL_BUTTON +box: 110 80 90 30 +boxtype: FL_UP_BOX +colors: FL_COL1 FL_COL1 +alignment: FL_ALIGN_CENTER +style: FL_NORMAL_STYLE +size: FL_NORMAL_SIZE +lcol: FL_BLACK +label: <|#B^r +shortcut: +resize: FL_RESIZE_NONE +gravity: FL_SouthEast FL_SouthEast +name: findprev +callback: C_FormBaseInputCB +argument: 0 + +-------------------- +class: FL_BUTTON +type: NORMAL_BUTTON +box: 110 120 90 30 +boxtype: FL_UP_BOX +colors: FL_COL1 FL_COL1 +alignment: FL_ALIGN_CENTER +style: FL_NORMAL_STYLE +size: FL_NORMAL_SIZE +lcol: FL_BLACK +label: Replace|#R#r +shortcut: +resize: FL_RESIZE_NONE +gravity: FL_SouthEast FL_SouthEast +name: replace +callback: C_FormBaseInputCB +argument: 0 + +-------------------- +class: FL_BUTTON +type: NORMAL_BUTTON +box: 350 120 80 30 +boxtype: FL_UP_BOX +colors: FL_COL1 FL_COL1 +alignment: FL_ALIGN_CENTER +style: FL_NORMAL_STYLE +size: FL_NORMAL_SIZE +lcol: FL_BLACK +label: Close|^[ +shortcut: +resize: FL_RESIZE_NONE +gravity: FL_SouthEast FL_SouthEast +name: button_cancel +callback: C_FormBaseCancelCB +argument: 0 + +-------------------- +class: FL_CHECKBUTTON +type: PUSH_BUTTON +box: 300 20 150 30 +boxtype: FL_NO_BOX +colors: FL_COL1 FL_YELLOW +alignment: FL_ALIGN_CENTER +style: FL_NORMAL_STYLE +size: FL_DEFAULT_SIZE +lcol: FL_BLACK +label: Case sensitive|#s#S +shortcut: +resize: FL_RESIZE_NONE +gravity: FL_NorthEast FL_NorthEast +name: casesensitive +callback: C_FormBaseInputCB +argument: 0 + +-------------------- +class: FL_CHECKBUTTON +type: PUSH_BUTTON +box: 300 50 150 30 +boxtype: FL_NO_BOX +colors: FL_COL1 FL_YELLOW +alignment: FL_ALIGN_CENTER +style: FL_NORMAL_STYLE +size: FL_DEFAULT_SIZE +lcol: FL_BLACK +label: Match word|#M#m +shortcut: +resize: FL_RESIZE_NONE +gravity: FL_NorthEast FL_NorthEast +name: matchword +callback: C_FormBaseInputCB +argument: 0 + +-------------------- +class: FL_BUTTON +type: NORMAL_BUTTON +box: 200 120 90 30 +boxtype: FL_UP_BOX +colors: FL_COL1 FL_COL1 +alignment: FL_ALIGN_CENTER +style: FL_NORMAL_STYLE +size: FL_NORMAL_SIZE +lcol: FL_BLACK +label: Replace All|#A#a +shortcut: +resize: FL_RESIZE_NONE +gravity: FL_SouthEast FL_SouthEast +name: replaceall +callback: C_FormBaseInputCB +argument: 0 + +============================== +-------------------- diff --git a/src/frontends/xforms/forms/makefile b/src/frontends/xforms/forms/makefile index 9f324fb4d9..2d0782e3a7 100644 --- a/src/frontends/xforms/forms/makefile +++ b/src/frontends/xforms/forms/makefile @@ -33,6 +33,7 @@ SRCS := form_bibitem.fd \ form_preferences.fd \ form_print.fd \ form_ref.fd \ + form_search.fd \ form_splash.fd \ form_tabular.fd \ form_tabular_create.fd \ diff --git a/src/lyxfind.C b/src/lyxfind.C new file mode 100644 index 0000000000..ae521a65e0 --- /dev/null +++ b/src/lyxfind.C @@ -0,0 +1,195 @@ +#include + +#ifdef __GNUG__ +#pragma implementation +#endif + +#include "lyxtext.h" +#include "lyxfind.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" + +int LyXReplace(BufferView * bv, + string const & searchstr, + string const & replacestr, + bool const & casesens, + bool const & matchwrd, + bool const & forward, + bool const & replaceall=false) +{ + int replace_count = 0; + + if (!bv->available() || bv->buffer()->isReadonly()) + return replace_count; + + // CutSelection cannot cut a single space, so we have to stop + // in order to avoid endless loop :-( + if (searchstr.length() == 0 + || (searchstr.length() == 1 && searchstr[0] == ' ')) { + WriteAlert(_("Sorry!"), _("You cannot replace a single space, " + "nor an empty character.")); + return replace_count; + } + // now we can start searching for the first + // start at top if replaceall + bool fw = forward; + if (replaceall) { + bv->text->ClearSelection(bv); + bv->text->CursorTop(bv); + // override search direction because we search top to bottom + fw = true; + } + + // if nothing selected or selection does not equal search string + // search and select next occurance and return if no replaceall + if (searchstr!=bv->text->selectionAsString(bv->buffer())) { + LyXFind(bv, searchstr, casesens, matchwrd, fw); + if (!replaceall) + return replace_count; + } + + bool found; + do { + bv->hideCursor(); + bv->update(bv->text, BufferView::SELECT|BufferView::FITCUR); + bv->toggleSelection(false); + bv->text->ReplaceSelectionWithString(bv, replacestr); + bv->text->SetSelectionOverString(bv, replacestr); + bv->update(bv->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE); + ++replace_count; + found = LyXFind(bv, searchstr, casesens, matchwrd, fw); + } while (replaceall && found); + + if (bv->focus()) + bv->showCursor(); + + return replace_count; +} + +bool LyXFind(BufferView * bv, + string const & searchstr, + bool const & casesens, + bool const & matchwrd, + bool const & forward) +{ + bool found = false; + + if (!bv->available() || searchstr.empty()) + return found; + + bv->hideCursor(); + bv->update(bv->text, BufferView::SELECT|BufferView::FITCUR); + + LyXText * ltCur = bv->text; + if (ltCur->selection) + ltCur->cursor = forward ? ltCur->sel_end_cursor + : ltCur->sel_start_cursor; + + if (forward + ? SearchForward(bv, searchstr, casesens, matchwrd) + : SearchBackward(bv, searchstr, casesens, matchwrd)) { + bv->update(bv->text, BufferView::SELECT|BufferView::FITCUR); + bv->toggleSelection(); + bv->text->ClearSelection(bv); + bv->text->SetSelectionOverString(bv, searchstr); + bv->toggleSelection(false); + found = true; + }; + + if (bv->focus()) + bv->showCursor(); + + return found; +} + + +// returns true if the specified string is at the specified position +bool IsStringInText(LyXParagraph * par, LyXParagraph::size_type pos, + string const & str, bool const & cs = true, + bool const & mw = false) +{ + if (!par) + return false; + + string::size_type size = str.length(); + LyXParagraph::size_type i = 0; + while (((pos + i) < par->Last()) + && (string::size_type(i) < size) + && (cs ? (str[i] == par->GetChar(pos + i)) + : (toupper(str[i]) == toupper(par->GetChar(pos + i))))) + { + ++i; + } + if (size == string::size_type(i)) { + // if necessary, check whether string matches word + if (!mw || + (mw && ((pos <= 0 || !IsLetterCharOrDigit(par->GetChar(pos - 1))) + && (pos + size >= par->Last() + || !IsLetterCharOrDigit(par->GetChar(pos + size)))) + ) + ) + return true; + } + return false; +} + +// forward search: +// if the string can be found: return true and set the cursor to +// the new position, cs = casesensitive, mw = matchword +bool SearchForward(BufferView * bv, string const & str, + bool const & cs = true, bool const & mw = false) +{ + LyXParagraph * par = bv->text->cursor.par(); + LyXParagraph::size_type pos = bv->text->cursor.pos(); + + while (par && !IsStringInText(par, pos, str, cs, mw)) { + if (pos < par->Last() - 1) + ++pos; + else { + pos = 0; + par = par->Next(); + } + } + if (par) { + bv->text->SetCursor(bv, par, pos); + return true; + } + else + return false; +} + + +// backward search: +// if the string can be found: return true and set the cursor to +// the new position, cs = casesensitive, mw = matchword +bool SearchBackward(BufferView * bv, string const & str, + bool const & cs = true, bool const & mw = false) +{ + LyXParagraph * par = bv->text->cursor.par(); + LyXParagraph::size_type pos = bv->text->cursor.pos(); + + do { + if (pos > 0) + --pos; + else { + // We skip empty paragraphs (Asger) + do { + par = par->Previous(); + if (par) + pos = par->Last() - 1; + } while (par && pos < 0); + } + } while (par && !IsStringInText(par, pos, str, cs, mw)); + + if (par) { + bv->text->SetCursor(bv, par, pos); + return true; + } else + return false; +} + diff --git a/src/lyxfind.h b/src/lyxfind.h new file mode 100644 index 0000000000..37509ef0a2 --- /dev/null +++ b/src/lyxfind.h @@ -0,0 +1,32 @@ +#ifndef LYXFIND_H +#define LYXFIND_H + +#ifdef __GNUG__ +#pragma interface +#endif + +#include "LString.h" +#include "lyxparagraph.h" + +class BufferView; + +int LyXReplace(BufferView * bv, string const &, string const &, + bool const &, bool const &, bool const &, bool const & = false); + +bool LyXFind(BufferView * bv, string const &, bool const &, bool const &, + bool const &); + +/// returns true if the specified string is at the specified position +bool IsStringInText(LyXParagraph * par, LyXParagraph::size_type pos, + string const & str, bool const & = true, + bool const & = false); + +/// if the string is found: return true and set the cursor to the new position +bool SearchForward(BufferView *, string const & str, bool const & = true, + bool const & = false); +/// +bool SearchBackward(BufferView *, string const & str, bool const & = true, + bool const & = false); + + +#endif diff --git a/src/lyxfr0.C b/src/lyxfr0.C deleted file mode 100644 index 21bd2a2e4a..0000000000 --- a/src/lyxfr0.C +++ /dev/null @@ -1,149 +0,0 @@ -/* This file is part of - * ====================================================== - * - * LyX, The Document Processor - * - * Copyright 1995 Matthias Ettrich, - * Copyright 1995-2000 The LyX Team. - * - * ====================================================== */ - -#include - -#ifdef __GNUG__ -#pragma implementation -#endif - -#include "lyxfr0.h" -#include "lyxfr1.h" -#include "lyx_gui_misc.h" -#include "frontends/Dialogs.h" // redrawGUI - -#ifdef SIGC_CXX_NAMESPACES -using SigC::slot; -#endif - -// callbacks for form form_search -void SearchCancelCB(FL_OBJECT * ob, long) -{ - fl_hide_form(ob->form); -} - - -void SearchForwardCB(FL_OBJECT * ob, long) -{ - LyXFindReplace * lfr = static_cast(ob->form->u_vdata); - lfr->SearchCB(true); -} - - -void SearchBackwardCB(FL_OBJECT * ob, long) -{ - LyXFindReplace * lfr = static_cast(ob->form->u_vdata); - lfr->SearchCB(false); -} - - -void SearchReplaceAllCB(FL_OBJECT * ob, long) -{ - LyXFindReplace * lfr = static_cast(ob->form->u_vdata); - lfr->SearchReplaceAllCB(); -} - - -void SearchReplaceCB(FL_OBJECT * ob, long) -{ - LyXFindReplace * lfr = static_cast(ob->form->u_vdata); - lfr->SearchReplaceCB(); -} - - - -SearchForm::SearchForm() - : search_form(0) -{ - r_ = Dialogs::redrawGUI.connect(slot(this, &SearchForm::redraw)); -} - - -SearchForm::~SearchForm() -{ - // The search_form should be closed and freed when SearchForm - // is destructed. - r_.disconnect(); -} - - -void SearchForm::redraw() -{ - if (search_form && search_form->form_search->visible) - fl_redraw_form(search_form->form_search); -} - - -void SearchForm::SearchCancelCB() -{ - fl_hide_form(search_form->form_search); -} - - -void SearchForm::StartSearch(LyXFindReplace * lfr) -{ - static int ow = -1, oh; - - 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(search_form->form_search, - FL_PLACE_MOUSE | FL_FREE_SIZE, FL_TRANSIENT, - _("Find & Replace")); // RVDK_PATCH_5 - if (ow < 0) { - ow = search_form->form_search->w; - oh = search_form->form_search->h; - } - fl_set_form_minsize(search_form->form_search, ow, oh); - } -} - - -// Returns the value of the replace string in the form -string const SearchForm::ReplaceString() const -{ - return fl_get_input(search_form->input_replace); -} - - -void SearchForm::replaceEnabled(bool fEnable) -{ - fReplaceEnabled = fEnable; - if (fEnable) { - 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(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 SearchForm::SetSearchString(string const & ls) -{ - fl_set_input(search_form->input_search, ls.c_str()); -} diff --git a/src/lyxfr0.h b/src/lyxfr0.h deleted file mode 100644 index e30e4f25ad..0000000000 --- a/src/lyxfr0.h +++ /dev/null @@ -1,97 +0,0 @@ -// -*- C++ -*- -#ifndef LYXFR0_H -#define LYXFR0_H - -#ifdef __GNUG__ -#pragma interface -#endif - -#include "LString.h" -#include FORMS_H_LOCATION -#include "form1.h" -#include - -class LyXFindReplace; - -#ifdef SIGC_CXX_NAMESPACES -using SigC::Object; -using SigC::Connection; -#endif - -/** - 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: - - - 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) - -*/ -class SearchForm : public Object { -public: - /// - SearchForm(); - /// - ~SearchForm(); - - /// - bool CaseSensitive() const { - return fl_get_button(search_form->btnCaseSensitive); - } - - /// - bool MatchWord() const { - return fl_get_button(search_form->btnMatchWord); - } - - /// - string const SearchString() const { - return fl_get_input(search_form->input_search); - } - - /// Initialize internal variables and dialog - void StartSearch(LyXFindReplace *); - - /// - void replaceEnabled(bool fEnabled); - /// - bool replaceEnabled() const { return fReplaceEnabled; } - - // Callbacks from form - /// - void SearchCancelCB(); - - // Return values - /// - void SetSearchString(string const & ls); - /// - string const ReplaceString() const; - - /// - bool ValidSearchData() const { return !(SearchString().empty()); } -private: - /** Redraw the form (on receipt of a Signal indicating, for example, - that the xform colors have been re-mapped). - */ - void redraw(); - /// - FD_form_search * search_form; - /// replace buttons enabled? - bool fReplaceEnabled; - /// Redraw connection. - Connection r_; -}; - -#endif diff --git a/src/lyxfr1.C b/src/lyxfr1.C deleted file mode 100644 index f6d575f742..0000000000 --- a/src/lyxfr1.C +++ /dev/null @@ -1,358 +0,0 @@ -/* This file is part of - * ====================================================== - * - * LyX, The Document Processor - * - * Copyright 1995 Matthias Ettrich, - * Copyright 1995-2000 The LyX Team. - * - * ====================================================== */ - -#include - -#ifdef __GNUG__ -#pragma implementation -#endif - -#include "lyxfr1.h" - -#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. -static -string GetCurrentSelectionAsString(LyXText * lt) -{ - string sz; - - 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(); - LyXParagraph::size_type endpos = - lt->sel_end_cursor.pos(); - bool fPrevIsSpace = false; - char ch; - while (pos < par->Last() && pos < endpos) { - ch = par->GetChar(pos); - - //HB??: Maybe (ch <= ' ') - if ((ch == ' ') || (ch <= LyXParagraph::META_INSET)) { - // consecutive spaces --> 1 space char - if (fPrevIsSpace) { - ++pos; // Next text pos - continue; // same search pos - } - sz += ' '; - fPrevIsSpace = true; - } else { - sz += ch; - fPrevIsSpace = false; - } - ++pos; - } - } - return sz; -} - - -// If nothing selected, select the word at the cursor. -// Returns the current selection -static inline -string GetSelectionOrWordAtCursor(BufferView * bv) -{ - 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(BufferView * bv, int len) -{ - bv->text->sel_cursor = bv->text->cursor; - for (int i = 0; i < len; ++i) - bv->text->CursorRight(bv); - bv->text->SetSelection(bv); -} - - -//------------------------------ - - -LyXFindReplace::LyXFindReplace() - : bv(0) -{} - - -LyXFindReplace::~LyXFindReplace() -{} - - -void LyXFindReplace::StartSearch(BufferView * b) -{ - bv = b; - SF.StartSearch(this); - SF.replaceEnabled(!bv->buffer()->isReadonly()); - searchForward = true; - if (SF.SearchString().empty()) - SF.SetSearchString(GetSelectionOrWordAtCursor(bv)); -} - - -// TODO?: the user can insert multiple spaces with this -// routine (1999-01-11, dnaber) -void LyXFindReplace::SearchReplaceCB() -{ - 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 :-( - 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 = SF.ReplaceString(); - - bv->hideCursor(); - bv->update(bv->text, BufferView::SELECT|BufferView::FITCUR); - - LyXText * ltCur = bv->text; - if (ltCur->selection) { - // clear the selection (if there is any) - bv->toggleSelection(false); - bv->text-> - ReplaceSelectionWithString(bv, replacestring); - bv->text-> - SetSelectionOverString(bv, replacestring); - bv->update(bv->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE); - } - - // jump to next match: - SearchCB(searchForward); -} - - -// replaces all occurences of a string (1999-01-15, dnaber@mini.gt.owl.de) -void LyXFindReplace::SearchReplaceAllCB() -{ - 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 :-( - 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 = SF.ReplaceString(); - - bv->hideCursor(); - - // start at top - bv->text->ClearSelection(bv); - bv->text->CursorTop(bv); - - int replace_count = 0; - LyXText * ltCur; - do { - ltCur = bv->text; - if (ltCur->selection) { - bv->update(bv->text, BufferView::SELECT|BufferView::FITCUR); - bv->toggleSelection(false); - bv->text-> - ReplaceSelectionWithString(bv, replacestring); - bv->text-> - SetSelectionOverString(bv, replacestring); - bv->update(bv->text, BufferView::SELECT|BufferView::FITCUR|BufferView::CHANGE); - ++replace_count; - } - } while (SearchCB(true)); - if (replace_count == 0) { - bv->owner()->getMiniBuffer()->Set( - _("String not found!")); - } else { - if (replace_count == 1) { - bv->owner()->getMiniBuffer()->Set( - _("1 string has been replaced.")); - } else { - string str = tostr(replace_count); - str += _(" strings have been replaced."); - bv->owner()->getMiniBuffer()->Set(str); - } - } -} - - -bool LyXFindReplace::SearchCB(bool fForward) -{ - // store search direction - searchForward = fForward; - - if (!bv->available()) - return false; - - bv->hideCursor(); - bv->update(bv->text, BufferView::SELECT|BufferView::FITCUR); - LyXText * ltCur = bv->text; - if (ltCur->selection) - ltCur->cursor = fForward ? ltCur->sel_end_cursor : - ltCur->sel_start_cursor; - - iLenSelected = SF.SearchString().length(); - bool result; - - if (!SF.ValidSearchData() || - (fForward ? SearchForward(bv):SearchBackward(bv))) { - bv->update(bv->text, BufferView::SELECT|BufferView::FITCUR); - - // clear the selection (if there is any) - bv->toggleSelection(); - bv->text->ClearSelection(bv); - - // set the new selection - SetSelectionOverLenChars(bv, iLenSelected); - bv->toggleSelection(false); - bv->owner()->getMiniBuffer()->Set(_("Found.")); - result = true; - } else { - bv->owner()->getMiniBuffer()->Set(_("String not found!")); - result = false; - } - - if (bv->focus()) - bv->showCursor(); - - return result; -} - - -// 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(BufferView * bv) -{ - LyXParagraph * par = bv->text->cursor.par(); - LyXParagraph::size_type pos = bv->text->cursor.pos(); - - while (par && !IsSearchStringInText(par, pos)) { - if (pos < par->Last() - 1) - ++pos; - else { - pos = 0; - par = par->Next(); - } - } - if (par) { - bv->text->SetCursor(bv, par, pos); - return true; - } else - return false; -} - - -// 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(BufferView * bv) -{ - LyXParagraph * par = bv->text->cursor.par(); - int pos = bv->text->cursor.pos(); - - do { - if (pos > 0) - --pos; - else { - // We skip empty paragraphs (Asger) - do { - par = par->Previous(); - if (par) - pos = par->Last() - 1; - } while (par && pos < 0); - } - } while (par && !IsSearchStringInText(par, pos)); - - if (par) { - bv->text->SetCursor(bv, par, pos); - return true; - } else - return false; -} - - -/* Compares 2 char values. -return value is - > 0 if chSearch > ch2 - = 0 if chSearch == ch2 - < 0 if chSearch < ch2 -*/ -int LyXFindReplace::CompareChars(char chSearch, char chText) const -{ - if (SF.CaseSensitive()) - return (chSearch - chText); - return (toupper(chSearch) - toupper(chText)); -} - - -// returns true if the search string is at the specified position -// (Copied from the original "LyXText::IsStringInText" in text2.C ) -bool LyXFindReplace::IsSearchStringInText(LyXParagraph * par, - LyXParagraph::size_type pos) const -{ - if (!par) return false; - - char chSrch = 0; - char chText; - bool fPrevIsSpace = false; - int iText = 0; - string::size_type iSrch = 0; - while (pos + iText < par->Last() && - iSrch < SF.SearchString().length()) { - chSrch = SF.SearchString()[iSrch]; - chText = par->GetChar(pos+iText); - if (chText == ' ') { - if (fPrevIsSpace) { - ++iText; // next Text pos - continue; // same search pos - } - fPrevIsSpace = true; - } else - fPrevIsSpace = false; - if (CompareChars(chSrch, chText) != 0) - break; - - ++iSrch; - ++iText; - } - - if (iSrch < SF.SearchString().length()) - return false; - - if (!SF.MatchWord() - || ((pos <= 0 || !IsLetterCharOrDigit(par->GetChar(pos - 1))) - && (pos + iText >= par->Last() - || !IsLetterCharOrDigit(par->GetChar(pos + iText))))) { - iLenSelected = iText; - return true; - } - - return false; -} diff --git a/src/lyxfr1.h b/src/lyxfr1.h deleted file mode 100644 index 872854ac20..0000000000 --- a/src/lyxfr1.h +++ /dev/null @@ -1,64 +0,0 @@ -// -*- C++ -*- -#ifndef LYXFR1_H -#define LYXFR1_H - -#ifdef __GNUG__ -#pragma interface -#endif - -#include "lyxparagraph.h" -#include "lyxfr0.h" - -class LyXText; - -/** Find and replace in LyXText texts. - - This class implements Find & Replace in LyXText texts. It is based on - LyXFindReplace0, which implements the form related stuff. (see lyxfr0.h) -*/ -class LyXFindReplace { -public: - /// - LyXFindReplace(); - /// - ~LyXFindReplace(); - - /// Initialize internal variables and search form - void StartSearch(BufferView *); - - /// - bool SearchCB(bool fForward); - /// - void SearchReplaceCB(); - /// - void SearchReplaceAllCB(); -private: - /// Set by IsSearchStringInText: - mutable int iLenSelected; - - /// Direction we are searching: - bool searchForward; - - /// - bool SearchForward(BufferView *); - /// - bool SearchBackward(BufferView *); - - /** Compares 2 char values. - return value is - \begin{itemize} - \item > 0 if ch1 > ch2 - \item = 0 if ch1 == ch2 - \item < 0 if ch1 < ch2 - \end{itemize} - */ - 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) const; - /// - SearchForm SF; - /// - BufferView * bv; -}; -#endif diff --git a/src/lyxfunc.C b/src/lyxfunc.C index b44f6c808c..2b1f9e03b6 100644 --- a/src/lyxfunc.C +++ b/src/lyxfunc.C @@ -75,7 +75,6 @@ #include "trans_mgr.h" #include "layout.h" #include "WorkArea.h" -#include "lyxfr1.h" #include "bufferview_funcs.h" #include "frontends/Dialogs.h" #include "frontends/Toolbar.h" @@ -86,6 +85,7 @@ #include "importer.h" #include "FontLoader.h" #include "TextCache.h" +#include "lyxfind.h" using std::pair; using std::endl; @@ -708,8 +708,8 @@ string const LyXFunc::Dispatch(int ac, if (!searched_string.empty() && ((action == LFUN_WORDFINDBACKWARD) ? - TEXT()->SearchBackward(owner->view(), searched_string) : - TEXT()->SearchForward(owner->view(), searched_string))) { + SearchBackward(owner->view(), searched_string) : + SearchForward(owner->view(), searched_string))) { // ??? What is that ??? owner->view()->update(TEXT(), BufferView::SELECT|BufferView::FITCUR); @@ -903,11 +903,8 @@ string const LyXFunc::Dispatch(int ac, case LFUN_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()); + owner->getDialogs()->showSearch(); + break; } break; diff --git a/src/lyxtext.h b/src/lyxtext.h index ed5dd4c804..a2eeb4eb7f 100644 --- a/src/lyxtext.h +++ b/src/lyxtext.h @@ -402,12 +402,6 @@ public: /* these things are for search and replace */ - /** returns true if the specified string is at the specified - position - */ - bool IsStringInText(LyXParagraph * par, - LyXParagraph::size_type pos, - string const & str) const; /** sets the selection over the number of characters of string, no check!! */ @@ -418,12 +412,6 @@ public: */ void ReplaceSelectionWithString(BufferView *, string const & str); - /** if the string can be found: return true and set the cursor to - the new position */ - bool SearchForward(BufferView *, string const & str) const; - /// - bool SearchBackward(BufferView *, string const & str) const; - /// needed to insert the selection void InsertStringA(BufferView *, string const & str); /// needed to insert the selection diff --git a/src/text2.C b/src/text2.C index 458ebe7616..0614935ef1 100644 --- a/src/text2.C +++ b/src/text2.C @@ -2383,26 +2383,6 @@ LyXParagraph * LyXText::FirstParagraph() const } -// returns true if the specified string is at the specified position -bool LyXText::IsStringInText(LyXParagraph * par, - LyXParagraph::size_type pos, - string const & str) const -{ - if (!par) - return false; - - LyXParagraph::size_type i = 0; - while (pos + i < par->Last() - && string::size_type(i) < str.length() - && str[i] == par->GetChar(pos + i)) { - ++i; - } - if (str.length() == string::size_type(i)) - return true; - return false; -} - - // sets the selection over the number of characters of string, no check!! void LyXText::SetSelectionOverString(BufferView * bview, string const & str) { @@ -2444,55 +2424,6 @@ void LyXText::ReplaceSelectionWithString(BufferView * bview, } -// if the string can be found: return true and set the cursor to -// the new position -bool LyXText::SearchForward(BufferView * bview, string const & str) const -{ - LyXParagraph * par = cursor.par(); - LyXParagraph::size_type pos = cursor.pos(); - while (par && !IsStringInText(par, pos, str)) { - if (pos < par->Last() - 1) - ++pos; - else { - pos = 0; - par = par->Next(); - } - } - if (par) { - SetCursor(bview, par, pos); - return true; - } - else - return false; -} - - -bool LyXText::SearchBackward(BufferView * bview, string const & str) const -{ - LyXParagraph * par = cursor.par(); - int pos = cursor.pos(); - - do { - if (pos > 0) - --pos; - else { - // We skip empty paragraphs (Asger) - do { - par = par->Previous(); - if (par) - pos = par->Last() - 1; - } while (par && pos < 0); - } - } while (par && !IsStringInText(par, pos, str)); - - if (par) { - SetCursor(bview, par, pos); - return true; - } else - return false; -} - - // needed to insert the selection void LyXText::InsertStringA(BufferView * bview, string const & str) { -- 2.39.2