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