3 * Copyright 2001 The LyX Team.
4 * See the file COPYING.
12 #pragma implementation
15 #include "FormSearch.h"
16 #include "form_search.h"
26 using Liason::setMinibuffer;
29 FormSearch::FormSearch(LyXView * lv, Dialogs * d)
30 : FormBaseBD(lv, d, _("LyX: Find and Replace"))
32 // let the popup be shown
33 // This is a permanent connection so we won't bother
34 // storing a copy because we won't be disconnecting.
35 d->showSearch.connect(slot(this, &FormSearch::show));
36 // perhaps in the future we'd like a
37 // "search again" button/keybinding
38 // d->searchAgain.connect(slot(this, &FormSearch::FindNext));
42 FL_FORM * FormSearch::form() const
49 void FormSearch::build()
51 dialog_.reset(build_search());
52 // Workaround dumb xforms sizing bug
56 // Manage the ok, apply and cancel/close buttons
57 bc_.setCancel(dialog_->button_cancel);
58 bc_.addReadOnly(dialog_->input_replace);
59 bc_.addReadOnly(dialog_->replace);
60 bc_.addReadOnly(dialog_->replaceall);
64 void FormSearch::update()
69 bc_.readOnly(lv_->buffer()->isReadonly());
72 bool FormSearch::input(FL_OBJECT * obj, long)
74 if (obj == dialog_->findnext)
76 else if (obj == dialog_->findprev)
78 else if (obj == dialog_->replace)
80 else if (obj == dialog_->replaceall)
86 void FormSearch::Find(bool const next)
88 bool found = LyXFind(lv_->view(),
89 fl_get_input(dialog_->input_search),
90 fl_get_button(dialog_->casesensitive),
91 fl_get_button(dialog_->matchword),
95 setMinibuffer(lv_, _("String not found!"));
99 void FormSearch::Replace(bool const all)
101 int replace_count = LyXReplace(lv_->view(),
102 fl_get_input(dialog_->input_search),
103 fl_get_input(dialog_->input_replace),
104 fl_get_button(dialog_->casesensitive),
105 fl_get_button(dialog_->matchword),
109 if (replace_count == 0) {
110 setMinibuffer(lv_, _("String not found!"));
112 if (replace_count == 1) {
113 setMinibuffer(lv_, _("String has been replaced."));
115 string str = tostr(replace_count);
116 str += _(" strings have been replaced.");
117 setMinibuffer(lv_, str.c_str());