]> git.lyx.org Git - lyx.git/blob - src/frontends/gnome/FormUrl.C
Clean-up of the button controller.
[lyx.git] / src / frontends / gnome / FormUrl.C
1 /* This file is part of
2  * =================================================
3  * 
4  *          LyX, The Document Processor
5  *          Copyright 1995-2000 The LyX Team.
6  *
7  * ================================================= 
8  *
9  * \author Baruch Even
10  */
11
12 #ifdef __GNUG__
13 #pragma implementation
14 #endif
15
16 #include <config.h>
17
18 #include "gnomeBC.h"
19 #include "FormUrl.h"
20
21 #include <gtk--/entry.h>
22 #include <gtk--/checkbutton.h>
23
24 FormUrl::FormUrl(ControlUrl & c)
25         : FormCB<ControlUrl>(c, "diainserturl.glade", "DiaInsertUrl")
26 {}
27
28
29 FormUrl::~FormUrl()
30 {
31         // Note that there is no need to destroy the class itself, it seems
32         // like everything is managed inside it. Deleting the class itself will
33         // a crash at the end of the program.
34         //dialog_->destroy();
35 }
36
37
38 void FormUrl::build()
39 {
40         // Connect the buttons.
41         ok_btn()->clicked.connect(SigC::slot(this, &FormUrl::OKClicked));
42         cancel_btn()->clicked.connect(SigC::slot(this, &FormUrl::CancelClicked));
43         apply_btn()->clicked.connect(SigC::slot(this, &FormUrl::ApplyClicked));
44         restore_btn()->clicked.connect(SigC::slot(this, &FormUrl::RestoreClicked));
45
46         // Manage the buttons state
47         bc().setOK(ok_btn());
48         bc().setCancel(cancel_btn());
49         bc().setApply(apply_btn());
50         bc().setRestore(restore_btn());
51
52         // Make sure everything is in the correct state.
53         bc().refresh();
54         
55         // Manage the read-only aware widgets.
56         bc().addReadOnly(html());
57         bc().addReadOnly(name());
58         bc().addReadOnly(url());
59 }
60
61
62 void FormUrl::connect_signals()
63 {
64         // Get notifications on input change
65         slot_url_ = url()->changed.connect(SigC::slot(this, &FormUrl::InputChanged));
66         slot_name_ = name()->changed.connect(SigC::slot(this, &FormUrl::InputChanged));
67         slot_html_ = html()->toggled.connect(SigC::slot(this, &FormUrl::InputChanged));
68 }
69
70
71 void FormUrl::disconnect_signals()
72 {
73         slot_url_.disconnect();
74         slot_name_.disconnect();
75         slot_html_.disconnect();
76 }
77
78
79 void FormUrl::apply()
80 {
81         controller().params().setContents(url()->get_text());
82         controller().params().setOptions(name()->get_text());
83
84         string cmdname("url");
85         if (html()->get_active())
86                 cmdname = "htmlurl";
87
88         controller().params().setCmdName(cmdname);
89 }
90
91
92 void FormUrl::update()
93 {
94         // Disconnect signals so we dont trigger the input changed state.
95         // This avoids the problem of having the buttons enabled when the dialog
96         // starts.
97         disconnect_signals();
98         
99         url()->set_text(controller().params().getContents());
100         name()->set_text(controller().params().getOptions());
101
102         html()->set_active("url" != controller().params().getCmdName());
103
104         // Reconnect the signals.
105         connect_signals();
106 }
107
108
109 bool FormUrl::validate() const
110 {
111         // Always valid! (not really so, needs fixing).
112         return true;
113 }
114
115
116 Gtk::Entry * FormUrl::url() const
117 {
118         return getWidget<Gtk::Entry>("url");
119 }
120
121 Gtk::Entry * FormUrl::name() const
122 {
123         return getWidget<Gtk::Entry>("name");
124 }
125
126 Gtk::CheckButton * FormUrl::html() const
127 {
128         return getWidget<Gtk::CheckButton>("html_type");
129 }
130
131
132 Gtk::Button * FormUrl::ok_btn() const
133 {
134         return getWidget<Gtk::Button>("button_ok");
135 }
136
137
138 Gtk::Button * FormUrl::cancel_btn() const
139 {
140         return getWidget<Gtk::Button>("button_cancel");
141 }
142
143
144 Gtk::Button * FormUrl::apply_btn() const
145 {
146         return getWidget<Gtk::Button>("button_apply");
147 }
148
149
150 Gtk::Button * FormUrl::restore_btn() const
151 {
152         return getWidget<Gtk::Button>("button_restore");
153 }