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