]> git.lyx.org Git - lyx.git/blob - src/frontends/gnome/GUrl.C
ws changes
[lyx.git] / src / frontends / gnome / 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 Baruch Even
7  * \author Michael Koziarski
8  *
9  * Full author contact details are available in file CREDITS
10  */
11
12 #ifdef __GNUG__
13 #pragma implementation
14 #endif
15
16 #include <config.h>
17
18 #include "gnomeBC.h"
19 #include "GUrl.h"
20
21 #include <gtkmm/entry.h>
22 #include <gtkmm/checkbutton.h>
23 #include <gtkmm/button.h>
24
25 GUrl::GUrl(ControlUrl & c)
26         : GnomeCB<ControlUrl>(c, "GUrl")
27 {}
28
29
30 GUrl::~GUrl()
31 {}
32
33
34 void GUrl::build()
35 {
36         // Connect the buttons.
37         ok_btn()->signal_clicked().connect(SigC::slot(*this, &GUrl::OKClicked));
38         cancel_btn()->signal_clicked().connect(SigC::slot(*this, &GUrl::CancelClicked));
39         apply_btn()->signal_clicked().connect(SigC::slot(*this, &GUrl::ApplyClicked));
40         restore_btn()->signal_clicked().connect(SigC::slot(*this, &GUrl::RestoreClicked));
41
42         // Manage the buttons state
43         bc().setOK(ok_btn());
44         bc().setCancel(cancel_btn());
45         bc().setApply(apply_btn());
46         bc().setRestore(restore_btn());
47
48         // Manage the read-only aware widgets.
49         bc().addReadOnly(html_cb());
50         bc().addReadOnly(name());
51         bc().addReadOnly(url());
52
53         // Make sure everything is in the correct state.
54         bc().refresh();
55 }
56
57
58 void GUrl::connect_signals()
59 {
60         // Get notifications on input change
61         slot_url_ = url()->signal_changed().connect(SigC::slot(*this, &GUrl::InputChanged));
62         slot_name_ = name()->signal_changed().connect(SigC::slot(*this, &GUrl::InputChanged));
63         slot_html_ = html_cb()->signal_toggled().connect(SigC::slot(*this, &GUrl::InputChanged));
64 }
65
66
67 void GUrl::disconnect_signals()
68 {
69         slot_url_.disconnect();
70         slot_name_.disconnect();
71         slot_html_.disconnect();
72 }
73
74
75 void GUrl::apply()
76 {
77         disconnect_signals();
78         controller().params().setContents(url()->get_text());
79         controller().params().setOptions(name()->get_text());
80
81         string cmdname("url");
82         if (html_cb()->get_active())
83                 cmdname = "htmlurl";
84
85         controller().params().setCmdName(cmdname);
86         connect_signals();
87 }
88
89
90 void GUrl::update()
91 {
92         disconnect_signals();
93
94         url()->set_text(controller().params().getContents());
95         name()->set_text(controller().params().getOptions());
96
97         html_cb()->set_active("url" != controller().params().getCmdName());
98
99         connect_signals();
100 }
101
102
103 bool GUrl::validate() const
104 {
105         return !url()->get_text().empty() && !name()->get_text().empty();
106 }
107
108 Gtk::Button * GUrl::restore_btn() const
109 {
110         return getWidget<Gtk::Button>("r_restore_btn");
111 }
112 Gtk::Button * GUrl::ok_btn() const
113 {
114         return getWidget<Gtk::Button>("r_ok_btn");
115 }
116 Gtk::Button * GUrl::apply_btn() const
117 {
118         return getWidget<Gtk::Button>("r_apply_btn");
119 }
120 Gtk::Button * GUrl::cancel_btn() const
121 {
122         return getWidget<Gtk::Button>("r_cancel_btn");
123 }
124 Gtk::Entry * GUrl::url() const
125 {
126         return getWidget<Gtk::Entry>("r_url");
127 }
128 Gtk::Entry * GUrl::name() const
129 {
130         return getWidget<Gtk::Entry>("r_name");
131 }
132 Gtk::CheckButton * GUrl::html_cb() const
133 {
134         return getWidget<Gtk::CheckButton>("r_html_cb");
135 }