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