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