]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FormSearch.C
Change glob() API to accept a dir parameter.
[lyx.git] / src / frontends / xforms / FormSearch.C
1 /**
2  * \file FormSearch.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Edwin Leuven
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "FormSearch.h"
14 #include "ControlSearch.h"
15 #include "forms/form_search.h"
16
17 #include "Tooltips.h"
18 #include "xforms_helpers.h"
19 #include "xformsBC.h"
20
21 #include "lyx_forms.h"
22
23 using std::string;
24
25 namespace lyx {
26 namespace frontend {
27
28 typedef FormController<ControlSearch, FormView<FD_search> > base_class;
29
30 FormSearch::FormSearch(Dialog & parent)
31         : base_class(parent, _("Find and Replace"))
32 {}
33
34
35 void FormSearch::build()
36 {
37         dialog_.reset(build_search(this));
38
39         // Manage the ok, apply and cancel/close buttons
40         bcview().setCancel(dialog_->button_close);
41
42         // disable for read-only documents
43         bcview().addReadOnly(dialog_->input_replace);
44         bcview().addReadOnly(dialog_->button_replace);
45         bcview().addReadOnly(dialog_->button_replaceall);
46
47         // set up the tooltips
48         string str = _("Enter the string you want to find.");
49         tooltips().init(dialog_->input_search, str);
50         str = _("Enter the replacement string.");
51         tooltips().init(dialog_->input_replace, str);
52         str = _("Continue to next search result.");
53         tooltips().init(dialog_->button_findnext, str);
54         str = _("Replace search result by replacement string.");
55         tooltips().init(dialog_->button_replace, str);
56         str = _("Replace all by replacement string.");
57         tooltips().init(dialog_->button_replaceall, str);
58         str = _("Do case sensitive search.");
59         tooltips().init(dialog_->check_casesensitive, str);
60         str = _("Search only matching words.");
61         tooltips().init(dialog_->check_matchword, str);
62         str = _("Search backwards.");
63         tooltips().init(dialog_->check_searchbackwards, str);
64 }
65
66
67 void FormSearch::update()
68 {
69         fl_set_input_selected(dialog_->input_search, true);
70         fl_set_focus_object(dialog_->form, dialog_->input_search);
71 }
72
73
74 ButtonPolicy::SMInput FormSearch::input(FL_OBJECT * ob, long)
75 {
76         if (ob == dialog_->button_findnext) {
77                 controller().find(getString(dialog_->input_search),
78                                   fl_get_button(dialog_->check_casesensitive),
79                                   fl_get_button(dialog_->check_matchword),
80                                   !fl_get_button(dialog_->check_searchbackwards));
81
82         } else if (ob == dialog_->button_replace || ob == dialog_->button_replaceall) {
83                 bool const all = (ob == dialog_->button_replaceall);
84
85                 controller().replace(getString(dialog_->input_search),
86                                      getString(dialog_->input_replace),
87                                      fl_get_button(dialog_->check_casesensitive),
88                                      fl_get_button(dialog_->check_matchword),
89                                      !fl_get_button(dialog_->check_searchbackwards),
90                                      all);
91         }
92
93         return ButtonPolicy::SMI_VALID;
94 }
95
96 } // namespace frontend
97 } // namespace lyx