3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Angus Leeming
8 * Full author contact details are available in file CREDITS.
15 #include "ButtonController.h"
18 #include "frontends/LyXView.h"
20 #include "FuncRequest.h"
21 #include "FuncStatus.h"
30 Dialog::Dialog(LyXView & lv, string const & name)
31 : is_closing_(false), kernel_(lv), name_(name),
32 bc_ptr_(new ButtonController)
36 void Dialog::ApplyButton()
43 void Dialog::OKButton()
53 void Dialog::CancelButton()
60 void Dialog::RestoreButton()
62 // Tell the kernel that a request to refresh the dialog's contents
63 // has been received. It's up to the kernel to supply the necessary
64 // info by calling Dialog::update().
65 kernel().updateDialog(name_);
70 void Dialog::show(string const & data)
72 if (controller().isBufferDependent() && !kernel().isBufferAvailable())
75 if (!controller().initialiseParams(data)) {
76 lyxerr << "Dialog \"" << name_
77 << "\" failed to translate the data "
78 "string passed to show()" << std::endl;
82 bc().readOnly(kernel().isBufferReadonly());
85 // The widgets may not be valid, so refresh the button controller
90 void Dialog::update(string const & data)
92 if (controller().isBufferDependent() && !kernel().isBufferAvailable())
95 if (!controller().initialiseParams(data)) {
96 lyxerr << "Dialog \"" << name_
97 << "\" could not be initialized" << std::endl;
101 bc().readOnly(kernel().isBufferReadonly());
104 // The widgets may not be valid, so refresh the button controller
111 if (!view().isVisible())
114 controller().clearParams();
116 kernel().disconnect(name());
122 if (controller().isBufferDependent()) {
123 if (!kernel().isBufferAvailable() ||
124 kernel().isBufferReadonly())
129 controller().dispatchParams();
131 if (controller().disconnectOnApply() && !is_closing_) {
132 kernel().disconnect(name());
133 controller().initialiseParams(string());
139 bool Dialog::isVisible() const
141 return view().isVisible();
145 void Dialog::redraw()
151 ButtonController & Dialog::bc() const
153 BOOST_ASSERT(bc_ptr_.get());
154 return *bc_ptr_.get();
158 void Dialog::setController(Controller * i)
160 BOOST_ASSERT(i && !controller_ptr_.get());
161 controller_ptr_.reset(i);
165 void Dialog::setView(View * v)
167 BOOST_ASSERT(v && !view_ptr_.get());
172 void Dialog::checkStatus()
174 // buffer independant dialogs are always active.
175 // This check allows us leave canApply unimplemented for some dialogs.
176 if (!controller().isBufferDependent())
179 // deactivate the dialog if we have no buffer
180 if (!kernel().isBufferAvailable()) {
185 // check whether this dialog may be active
186 if (controller().canApply()) {
187 bool const readonly = kernel().isBufferReadonly();
188 bc().readOnly(readonly);
189 // refreshReadOnly() is too generous in _enabling_ widgets
190 // update dialog to disable disabled widgets again
198 Dialog::Controller::Controller(Dialog & parent)
203 bool Dialog::Controller::canApply() const
205 FuncRequest const fr(getLfun(), dialog().name());
206 FuncStatus const fs(getStatus(fr));
211 Dialog::Controller & Dialog::controller() const
213 BOOST_ASSERT(controller_ptr_.get());
214 return *controller_ptr_.get();
218 Dialog::View::View(Dialog & parent, docstring title) :
219 p_(parent), title_(title)
223 Dialog::View & Dialog::view() const
225 BOOST_ASSERT(view_ptr_.get());
226 return *view_ptr_.get();
230 void Dialog::View::setTitle(docstring const & newtitle)
236 docstring const & Dialog::View::getTitle() const
242 void Dialog::View::partialUpdate(int)
245 } // namespace frontend