]> git.lyx.org Git - lyx.git/blob - src/frontends/controllers/Dialog.C
Small clean-up.
[lyx.git] / src / frontends / controllers / Dialog.C
1 /**
2  * \file Dialog.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Angus Leeming
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "Dialog.h"
14
15 #include "ButtonController.h"
16 #include "BCView.h"
17
18
19 Dialog::Dialog(LyXView & lv, string const & name)
20         : is_closing_(false), kernel_(lv), name_(name),
21           bc_ptr_(new ButtonController)
22 {}
23
24
25 Dialog::~Dialog()
26 {}
27
28
29 void Dialog::ApplyButton()
30 {
31         apply();
32         bc().apply();
33 }
34
35
36 void Dialog::OKButton()
37 {
38         is_closing_ = true;
39         apply();
40         is_closing_ = false;
41         hide();
42         bc().ok();
43 }
44
45
46 void Dialog::CancelButton()
47 {
48         hide();
49         bc().cancel();
50 }
51
52
53 void Dialog::RestoreButton()
54 {
55         // Tell the kernel that a request to refresh the dialog's contents
56         // has been received. It's up to the kernel to supply the necessary
57         // info by calling Dialog::update().
58         kernel().updateDialog(name_);
59         bc().restore();
60 }
61
62
63 void Dialog::show(string const & data)
64 {
65         if (controller().isBufferDependent() && !kernel().isBufferAvailable())
66                 return;
67
68         if (!controller().initialiseParams(data)) {
69                 lyxerr << "Dialog \"" << name_
70                        << "\" failed to translate the data "
71                         "string passed to show()" << std::endl;
72                 return;
73         }
74
75         bc().readOnly(kernel().isBufferReadonly());
76         view().show();
77
78         // The widgets may not be valid, so refresh the button controller
79         bc().refresh();
80 }
81
82
83 void Dialog::update(string const & data)
84 {
85         if (controller().isBufferDependent() && !kernel().isBufferAvailable())
86                 return;
87
88         if (!controller().initialiseParams(data)) {
89                 lyxerr << "Dialog \"" << name_
90                        << "\" failed to translate the data "
91                         "string passed to update()" << std::endl;
92                 return;
93         }
94
95         bc().readOnly(kernel().isBufferReadonly());
96         view().update();
97
98         // The widgets may not be valid, so refresh the button controller
99         bc().refresh();
100 }
101
102
103 void Dialog::hide()
104 {
105         if (!view().isVisible())
106                 return;
107
108         controller().clearParams();
109         view().hide();
110 }
111
112
113 void Dialog::apply()
114 {
115         if (kernel().isBufferReadonly())
116                 return;
117
118         view().apply();
119         controller().dispatchParams();
120
121         if (controller().disconnectOnApply() && !is_closing_) {
122                 kernel().disconnect(name());
123                 controller().initialiseParams(string());
124                 view().update();
125         }
126 }
127
128
129 bool Dialog::isVisible() const
130 {
131         return view().isVisible();
132 }
133
134
135 void Dialog::redraw()
136 {
137         view().redraw();
138 }
139
140
141 ButtonController & Dialog::bc() const
142 {
143         BOOST_ASSERT(bc_ptr_.get());
144         return *bc_ptr_.get();
145 }
146
147
148 void Dialog::setController(Controller * i)
149 {
150         BOOST_ASSERT(i && !controller_ptr_.get());
151         controller_ptr_.reset(i);
152 }
153
154
155 void Dialog::setView(View * v)
156 {
157         BOOST_ASSERT(v && !view_ptr_.get());
158         view_ptr_.reset(v);
159 }
160
161
162 Dialog::Controller::Controller(Dialog & parent)
163         : parent_(parent)
164 {}
165
166
167 Dialog::Controller & Dialog::controller() const
168 {
169         BOOST_ASSERT(controller_ptr_.get());
170         return *controller_ptr_.get();
171 }
172
173
174 Dialog::View::View(Dialog & parent, string title) :
175         p_(parent), title_(title)
176 {}
177
178
179 Dialog::View & Dialog::view() const
180 {
181         BOOST_ASSERT(view_ptr_.get());
182         return *view_ptr_.get();
183 }
184
185
186 void Dialog::View::setTitle(string const & newtitle)
187 {
188         title_ = newtitle;
189 }
190
191
192 string const & Dialog::View::getTitle() const
193 {
194         return title_;
195 }
196
197
198 void Dialog::View::partialUpdate(int)
199 {}