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