3 * Copyright 2001 The LyX Team.
4 * See the file COPYING.
11 #include "FormSearch.h"
12 #include "form_search.h"
22 #ifdef CXX_WORKING_NAMESPACES
23 using Liason::setMinibuffer;
27 FormSearch::FormSearch(LyXView * lv, Dialogs * d)
28 : FormBaseBD(lv, d, _("LyX: Find and Replace"), new NoRepeatedApplyReadOnlyPolicy),
31 // let the popup be shown
32 // This is a permanent connection so we won't bother
33 // storing a copy because we won't be disconnecting.
34 d->showSearch.connect(slot(this, &FormSearch::show));
35 // perhaps in the future we'd like a
36 // "search again" button/keybinding
37 // d->searchAgain.connect(slot(this, &FormSearch::FindNext));
41 FormSearch::~FormSearch()
47 FL_FORM * FormSearch::form() const
54 void FormSearch::build()
56 dialog_ = build_search();
57 // Workaround dumb xforms sizing bug
61 // Manage the ok, apply and cancel/close buttons
62 bc_.setCancel(dialog_->button_cancel);
63 bc_.addReadOnly(dialog_->input_replace);
64 bc_.addReadOnly(dialog_->replace);
65 bc_.addReadOnly(dialog_->replaceall);
69 void FormSearch::update()
74 bc_.readOnly(lv_->buffer()->isReadonly());
77 bool FormSearch::input(FL_OBJECT * obj, long)
79 if (obj == dialog_->findnext)
81 else if (obj == dialog_->findprev)
83 else if (obj == dialog_->replace)
85 else if (obj == dialog_->replaceall)
91 void FormSearch::Find(bool const next)
93 bool found = LyXFind(lv_->view(),
94 fl_get_input(dialog_->input_search),
95 fl_get_button(dialog_->casesensitive),
96 fl_get_button(dialog_->matchword),
100 setMinibuffer(lv_, _("String not found!"));
104 void FormSearch::Replace(bool const all)
106 int replace_count = LyXReplace(lv_->view(),
107 fl_get_input(dialog_->input_search),
108 fl_get_input(dialog_->input_replace),
109 fl_get_button(dialog_->casesensitive),
110 fl_get_button(dialog_->matchword),
114 if (replace_count == 0) {
115 setMinibuffer(lv_, _("String not found!"));
117 if (replace_count == 1) {
118 setMinibuffer(lv_, _("String has been replaced."));
120 string str = tostr(replace_count);
121 str += _(" strings have been replaced.");
122 setMinibuffer(lv_, str.c_str());