]> git.lyx.org Git - lyx.git/blob - src/frontends/gtk/GSearch.C
fix math fonts with LyX/Mac
[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 #include "GSearch.h"
14 #include "ControlSearch.h"
15 #include "ghelpers.h"
16
17 #include <libglademm.h>
18
19 using std::string;
20
21 namespace lyx {
22 namespace frontend {
23
24 typedef GViewCB<ControlSearch, GViewGladeB> base_class;
25
26
27 GSearch::GSearch(Dialog & parent)
28         : base_class(parent, _("Find and Replace"), false)
29 {}
30
31
32 void GSearch::doBuild()
33 {
34         string const gladeName = findGladeFile("search");
35         xml_ = Gnome::Glade::Xml::create(gladeName);
36
37         Gtk::Button * cancelbutton;
38         xml_->get_widget("Cancel", cancelbutton);
39         setCancel(cancelbutton);
40
41         xml_->get_widget("FindNext", findnextbutton);
42         xml_->get_widget("Replace", replacebutton);
43         xml_->get_widget("ReplaceAll", replaceallbutton);
44         xml_->get_widget("FindEntry", findentry);
45         xml_->get_widget("ReplaceEntry", replaceentry);
46         xml_->get_widget("CaseSensitive", casecheck);
47         xml_->get_widget("MatchWord", matchwordcheck);
48         xml_->get_widget("SearchBackwards", backwardscheck);
49
50         findnextbutton->signal_clicked().connect(
51                 sigc::mem_fun(*this, &GSearch::onFindNext));
52         replacebutton->signal_clicked().connect(
53                 sigc::mem_fun(*this, &GSearch::onReplace));
54         replaceallbutton->signal_clicked().connect(
55                 sigc::mem_fun(*this, &GSearch::onReplaceAll));
56         findentry->signal_changed().connect(
57                 sigc::mem_fun(*this,&GSearch::onFindEntryChanged));
58
59         bcview().addReadOnly(replaceentry);
60         bcview().addReadOnly(replacebutton);
61         bcview().addReadOnly(replaceallbutton);
62 }
63
64
65 void GSearch::update()
66 {
67         bc().refreshReadOnly();
68         onFindEntryChanged();
69 }
70
71
72 void GSearch::onFindNext()
73 {
74         controller().find(findentry->get_text(),
75                           casecheck->get_active(),
76                           matchwordcheck->get_active(),
77                           !backwardscheck->get_active());
78 }
79
80
81 void GSearch::onReplace()
82 {
83         controller().replace(findentry->get_text(),
84                              replaceentry->get_text(),
85                              casecheck->get_active(),
86                              matchwordcheck->get_active(),
87                              !backwardscheck->get_active(),
88                              false);
89 }
90
91
92 void GSearch::onReplaceAll()
93 {
94         controller().replace(findentry->get_text(),
95                              replaceentry->get_text(),
96                              casecheck->get_active(),
97                              matchwordcheck->get_active(),
98                              !backwardscheck->get_active(),
99                              true);
100 }
101
102
103 void GSearch::onFindEntryChanged()
104 {
105         if (findentry->get_text().empty()) {
106                 findnextbutton->set_sensitive(false);
107                 replacebutton->set_sensitive(false);
108                 replaceallbutton->set_sensitive(false);
109         } else {
110                 findnextbutton->set_sensitive(true);
111                 replacebutton->set_sensitive(!readOnly());
112                 replaceallbutton->set_sensitive(!readOnly());
113         }
114 }
115
116 } // namespace frontend
117 } // namespace lyx