]> git.lyx.org Git - lyx.git/blob - src/frontends/gtk/GUrl.C
Minipage is no more (long live the box inset)
[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         bcview().setOK(ok);
46         bcview().setCancel(cancel);
47         bcview().setApply(apply);
48         bcview().setRestore(restore);
49         bcview().addReadOnly(name_);
50         bcview().addReadOnly(url_);
51         bcview().addReadOnly(htmlType_);
52
53         ok->signal_clicked().connect(
54                 SigC::slot(*this, &GViewBase::onOK));
55         apply->signal_clicked().connect(
56                 SigC::slot(*this, &GViewBase::onApply));
57         cancel->signal_clicked().connect(
58                 SigC::slot(*this, &GViewBase::onCancel));
59         restore->signal_clicked().connect(
60                 SigC::slot(*this, &GViewBase::onRestore));
61         url_->signal_changed().connect(
62                 SigC::slot(*this, &GUrl::onEntryChanged));
63         name_->signal_changed().connect(
64                 SigC::slot(*this, &GUrl::onEntryChanged));
65 }
66
67
68 void GUrl::onEntryChanged()
69 {
70         bc().valid(!url_->get_text().empty() || !name_->get_text().empty());
71 }
72
73
74 void GUrl::update()
75 {
76         url_->set_text(Glib::locale_to_utf8(
77                                controller().params().getContents()));
78         name_->set_text(Glib::locale_to_utf8(
79                                 controller().params().getOptions()));
80         if (controller().params().getCmdName() == "url")
81                 htmlType_->set_active(false);
82         else
83                 htmlType_->set_active();
84 }
85
86
87 void GUrl::apply()
88 {
89         controller().params().setContents(
90                 Glib::locale_to_utf8(url_->get_text()));
91         controller().params().setOptions(
92                 Glib::locale_to_utf8(name_->get_text()));
93         if (htmlType_->get_active())
94                 controller().params().setCmdName("htmlurl");
95         else
96                 controller().params().setCmdName("url");
97 }