]> git.lyx.org Git - lyx.git/blob - src/frontends/gtk/GSearch.C
Display accelerator (binding) labels in menus.
[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::onFindNext()
66 {
67         controller().find(findentry->get_text(),
68                           casecheck->get_active(),
69                           matchwordcheck->get_active(),
70                           !backwardscheck->get_active());
71 }
72
73
74 void GSearch::onReplace()
75 {
76         controller().replace(findentry->get_text(),
77                              replaceentry->get_text(),
78                              casecheck->get_active(),
79                              matchwordcheck->get_active(),
80                              !backwardscheck->get_active(),
81                              false);
82 }
83
84
85 void GSearch::onReplaceAll()
86 {
87         controller().replace(findentry->get_text(),
88                              replaceentry->get_text(),
89                              casecheck->get_active(),
90                              matchwordcheck->get_active(),
91                              !backwardscheck->get_active(),
92                              true);
93 }
94
95
96 void GSearch::onFindEntryChanged()
97 {
98         if (findentry->get_text().empty()) {
99                 findnextbutton->set_sensitive(false);
100                 replacebutton->set_sensitive(false);
101                 replaceallbutton->set_sensitive(false);
102         } else {
103                 findnextbutton->set_sensitive(true);
104                 replacebutton->set_sensitive(true);
105                 replaceallbutton->set_sensitive(true);
106         }
107 }
108
109 } // namespace frontend
110 } // namespace lyx