]> git.lyx.org Git - lyx.git/blob - src/frontends/gtk/GSearch.C
some tabular fixes for the problems reported by Helge
[lyx.git] / src / frontends / gtk / GSearch.C
1 /**
2  * \file GSearch.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author John Spray
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 // Too hard to make concept checks work with this file
14 #ifdef _GLIBCXX_CONCEPT_CHECKS
15 #undef _GLIBCXX_CONCEPT_CHECKS
16 #endif
17 #ifdef _GLIBCPP_CONCEPT_CHECKS
18 #undef _GLIBCPP_CONCEPT_CHECKS
19 #endif
20
21 #include "GSearch.h"
22 #include "ControlSearch.h"
23 #include "ghelpers.h"
24
25 #include <libglademm.h>
26
27 using std::string;
28
29 namespace lyx {
30 namespace frontend {
31
32 typedef GViewCB<ControlSearch, GViewGladeB> base_class;
33
34
35 GSearch::GSearch(Dialog & parent)
36         : base_class(parent, _("Find and Replace"), false)
37 {}
38
39
40 void GSearch::doBuild()
41 {
42         string const gladeName = findGladeFile("search");
43         xml_ = Gnome::Glade::Xml::create(gladeName);
44
45         Gtk::Button * cancelbutton;
46         xml_->get_widget("Cancel", cancelbutton);
47         setCancel(cancelbutton);
48
49         xml_->get_widget("FindNext", findnextbutton);
50         xml_->get_widget("Replace", replacebutton);
51         xml_->get_widget("ReplaceAll", replaceallbutton);
52         xml_->get_widget("FindEntry", findentry);
53         xml_->get_widget("ReplaceEntry", replaceentry);
54         xml_->get_widget("CaseSensitive", casecheck);
55         xml_->get_widget("MatchWord", matchwordcheck);
56         xml_->get_widget("SearchBackwards", backwardscheck);
57
58         findnextbutton->signal_clicked().connect(
59                 sigc::mem_fun(*this, &GSearch::onFindNext));
60         replacebutton->signal_clicked().connect(
61                 sigc::mem_fun(*this, &GSearch::onReplace));
62         replaceallbutton->signal_clicked().connect(
63                 sigc::mem_fun(*this, &GSearch::onReplaceAll));
64         findentry->signal_changed().connect(
65                 sigc::mem_fun(*this,&GSearch::onFindEntryChanged));
66
67         bcview().addReadOnly(replaceentry);
68         bcview().addReadOnly(replacebutton);
69         bcview().addReadOnly(replaceallbutton);
70 }
71
72
73 void GSearch::update()
74 {
75         bc().refreshReadOnly();
76         findentry->grab_focus();
77         onFindEntryChanged();
78 }
79
80
81 void GSearch::onFindNext()
82 {
83         controller().find(findentry->get_text(),
84                           casecheck->get_active(),
85                           matchwordcheck->get_active(),
86                           !backwardscheck->get_active());
87 }
88
89
90 void GSearch::onReplace()
91 {
92         controller().replace(findentry->get_text(),
93                              replaceentry->get_text(),
94                              casecheck->get_active(),
95                              matchwordcheck->get_active(),
96                              !backwardscheck->get_active(),
97                              false);
98 }
99
100
101 void GSearch::onReplaceAll()
102 {
103         controller().replace(findentry->get_text(),
104                              replaceentry->get_text(),
105                              casecheck->get_active(),
106                              matchwordcheck->get_active(),
107                              !backwardscheck->get_active(),
108                              true);
109 }
110
111
112 void GSearch::onFindEntryChanged()
113 {
114         if (findentry->get_text().empty()) {
115                 findnextbutton->set_sensitive(false);
116                 replacebutton->set_sensitive(false);
117                 replaceallbutton->set_sensitive(false);
118         } else {
119                 findnextbutton->set_sensitive(true);
120                 replacebutton->set_sensitive(!readOnly());
121                 replaceallbutton->set_sensitive(!readOnly());
122         }
123 }
124
125 } // namespace frontend
126 } // namespace lyx