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