]> git.lyx.org Git - lyx.git/blob - src/frontends/gtk/GText.C
Add ShowFile dialog
[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
13 #include "GText.h"
14 #include "ControlCommand.h"
15 #include "ghelpers.h"
16 #include "IdSc.h"
17
18 #include "support/lstrings.h"
19
20 #include <gtkmm.h>
21 #include <libglademm.h>
22
23 using std::string;
24
25 namespace lyx {
26 namespace frontend {
27
28 GText::GText(Dialog & parent, string const & title, string const & label)
29         : GViewCB<ControlCommand, GViewGladeB>(parent, title),
30           label_(label), entry_(0)
31 {
32 }
33
34
35 void GText::apply()
36 {
37         string const contents = Glib::locale_from_utf8(entry_->get_text());
38         controller().params().setContents(contents);
39 }
40
41
42 void GText::update()
43 {
44         string const contents = support::trim(
45                 controller().params().getContents());
46         entry_->set_text(Glib::locale_to_utf8(contents));
47 }
48
49
50 void GText::doBuild()
51 {
52         string const gladeName = findGladeFile("text");
53         xml_ = Gnome::Glade::Xml::create(gladeName);
54         Gtk::Label * label;
55         Gtk::Button * restore;
56         Gtk::Button * cancel;
57         Gtk::Button * apply;
58         Gtk::Button * ok;
59         xml_->get_widget("Label", label);
60         xml_->get_widget("Text", entry_);
61         xml_->get_widget("Restore", restore);
62         xml_->get_widget("Cancel", cancel);
63         xml_->get_widget("Apply", apply);
64         xml_->get_widget("OK", ok);
65         label->set_text(Glib::locale_to_utf8(id_sc::id(label_)));
66         setOK(ok);
67         setApply(apply);
68         setCancel(cancel);
69         setRestore(restore);
70         bcview().addReadOnly(entry_);
71         entry_->signal_changed().connect(
72                 sigc::mem_fun(*this, &GText::onEntryChanged));
73 }
74
75
76 void GText::onEntryChanged()
77 {
78         bc().valid(!entry_->get_text().empty());
79 }
80
81 } // namespace frontend
82 } // namespace lyx