]> git.lyx.org Git - lyx.git/blob - src/frontends/xforms/FormSearch.C
fix crash with "save as"
[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 #ifdef __GNUG__
14 #pragma implementation
15 #endif
16
17 #include "xformsBC.h"
18 #include "ControlSearch.h"
19 #include "FormSearch.h"
20 #include "forms/form_search.h"
21 #include "Tooltips.h"
22 #include "xforms_helpers.h"
23
24 #include FORMS_H_LOCATION
25
26 typedef FormCB<ControlSearch, FormDB<FD_search> > base_class;
27
28 FormSearch::FormSearch()
29         : base_class(_("Find and Replace"))
30 {}
31
32
33 void FormSearch::build()
34 {
35         dialog_.reset(build_search(this));
36
37         // Manage the ok, apply and cancel/close buttons
38         bc().setCancel(dialog_->button_close);
39
40         // disable for read-only documents
41         bc().addReadOnly(dialog_->input_replace);
42         bc().addReadOnly(dialog_->button_replace);
43         bc().addReadOnly(dialog_->button_replaceall);
44
45         // set up the tooltips
46         string str = _("Enter the string you want to find.");
47         tooltips().init(dialog_->input_search, str);
48         str = _("Enter the replacement string.");
49         tooltips().init(dialog_->input_replace, str);
50         str = _("Continue to next search result.");
51         tooltips().init(dialog_->button_findnext, str);
52         str = _("Replace search result by replacement string.");
53         tooltips().init(dialog_->button_replace, str);
54         str = _("Replace all by replacement string.");
55         tooltips().init(dialog_->button_replaceall, str);
56         str = _("Do case sensitive search.");
57         tooltips().init(dialog_->check_casesensitive, str);
58         str = _("Search only matching words.");
59         tooltips().init(dialog_->check_matchword, str);
60         str = _("Search backwards.");
61         tooltips().init(dialog_->check_searchbackwards, str);
62 }
63
64
65 void FormSearch::update()
66 {
67         fl_set_input_selected(dialog_->input_search, true);
68         fl_set_focus_object(dialog_->form, dialog_->input_search);
69 }
70
71
72 ButtonPolicy::SMInput FormSearch::input(FL_OBJECT * ob, long)
73 {
74         if (ob == dialog_->button_findnext) {
75                 controller().find(getString(dialog_->input_search),
76                                   fl_get_button(dialog_->check_casesensitive),
77                                   fl_get_button(dialog_->check_matchword),
78                                   !fl_get_button(dialog_->check_searchbackwards));
79
80         } else if (ob == dialog_->button_replace || ob == dialog_->button_replaceall) {
81                 bool const all = (ob == dialog_->button_replaceall);
82
83                 controller().replace(getString(dialog_->input_search),
84                                      getString(dialog_->input_replace),
85                                      fl_get_button(dialog_->check_casesensitive),
86                                      fl_get_button(dialog_->check_matchword),
87                                      all);
88         }
89
90         return ButtonPolicy::SMI_VALID;
91 }