]> git.lyx.org Git - lyx.git/blob - src/frontends/gtk/GUrl.C
Wrap most of the frontend code up inside namespace lyx::frontend.
[lyx.git] / src / frontends / gtk / GUrl.C
1 /**
2  * \file GUrl.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
14 #include <libglademm.h>
15
16 #include "ControlCommand.h"
17 #include "GUrl.h"
18 #include "ghelpers.h"
19 #include "support/lstrings.h"
20
21 using std::string;
22
23 namespace lyx {
24 namespace frontend {
25
26 GUrl::GUrl(Dialog & parent)
27         : GViewCB<ControlCommand, GViewGladeB>(parent, _("URL"))
28 {
29 }
30
31
32 void GUrl::doBuild()
33 {
34         string const gladeName = findGladeFile("url");
35         xml_ = Gnome::Glade::Xml::create(gladeName);
36         Gtk::Button * restore;
37         Gtk::Button * ok;
38         Gtk::Button * apply;
39         Gtk::Button * cancel;
40         xml_->get_widget("Url", url_);
41         xml_->get_widget("Name", name_);
42         xml_->get_widget("Html", htmlType_);
43         xml_->get_widget("Restore", restore);
44         xml_->get_widget("Ok", ok);
45         xml_->get_widget("Apply", apply);
46         xml_->get_widget("Cancel", cancel);
47         setOK(ok);
48         setCancel(cancel);
49         setApply(apply);
50         setRestore(restore);
51         bcview().addReadOnly(name_);
52         bcview().addReadOnly(url_);
53         bcview().addReadOnly(htmlType_);
54
55         url_->signal_changed().connect(
56                 SigC::slot(*this, &GUrl::onEntryChanged));
57         name_->signal_changed().connect(
58                 SigC::slot(*this, &GUrl::onEntryChanged));
59 }
60
61
62 void GUrl::onEntryChanged()
63 {
64         bc().valid(!url_->get_text().empty() || !name_->get_text().empty());
65 }
66
67
68 void GUrl::update()
69 {
70         url_->set_text(Glib::locale_to_utf8(
71                                controller().params().getContents()));
72         name_->set_text(Glib::locale_to_utf8(
73                                 controller().params().getOptions()));
74         if (controller().params().getCmdName() == "url")
75                 htmlType_->set_active(false);
76         else
77                 htmlType_->set_active();
78 }
79
80
81 void GUrl::apply()
82 {
83         controller().params().setContents(
84                 Glib::locale_to_utf8(url_->get_text()));
85         controller().params().setOptions(
86                 Glib::locale_to_utf8(name_->get_text()));
87         if (htmlType_->get_active())
88                 controller().params().setCmdName("htmlurl");
89         else
90                 controller().params().setCmdName("url");
91 }
92
93 } // namespace frontend
94 } // namespace lyx