]> git.lyx.org Git - lyx.git/blob - src/frontends/gtk/GText.C
Wrap most of the frontend code up inside namespace lyx::frontend.
[lyx.git] / src / frontends / gtk / GText.C
1 /**
2  * \file GText.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Huang Ying
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12 #include <gtkmm.h>
13 #include <libglademm.h>
14
15 #include "support/lstrings.h"
16 #include "ControlCommand.h"
17 #include "GText.h"
18 #include "ghelpers.h"
19 #include "IdSc.h"
20
21 using std::string;
22
23 namespace lyx {
24 namespace frontend {
25
26 GText::GText(Dialog & parent, string const & title, string const & label)
27         : GViewCB<ControlCommand, GViewGladeB>(parent, title),
28           label_(label), entry_(0)
29 {
30 }
31
32 void GText::apply()
33 {
34         string const contents = Glib::locale_from_utf8(entry_->get_text());
35         controller().params().setContents(contents);
36 }
37
38 void GText::update()
39 {
40         string const contents = support::trim(
41                 controller().params().getContents());
42         entry_->set_text(Glib::locale_to_utf8(contents));
43 }
44
45 void GText::doBuild()
46 {
47         string const gladeName = findGladeFile("text");
48         xml_ = Gnome::Glade::Xml::create(gladeName);
49         Gtk::Label * label;
50         Gtk::Button * restore;
51         Gtk::Button * cancel;
52         Gtk::Button * apply;
53         Gtk::Button * ok;
54         xml_->get_widget("Label", label);
55         xml_->get_widget("Text", entry_);
56         xml_->get_widget("Restore", restore);
57         xml_->get_widget("Cancel", cancel);
58         xml_->get_widget("Apply", apply);
59         xml_->get_widget("OK", ok);
60         label->set_text(Glib::locale_to_utf8(id_sc::id(label_)));
61         setOK(ok);
62         setApply(apply);
63         setCancel(cancel);
64         setRestore(restore);
65         bcview().addReadOnly(entry_);
66         entry_->signal_changed().connect(
67                 SigC::slot(*this, &GText::onEntryChanged));
68 }
69
70 void GText::onEntryChanged()
71 {
72         bc().valid(!entry_->get_text().empty());
73 }
74
75 } // namespace frontend
76 } // namespace lyx