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