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"
31 Dialog::Dialog(LyXView & lv, string const & name)
32 : is_closing_(false), kernel_(lv), name_(name),
33 bc_ptr_(new ButtonController)
41 void Dialog::ApplyButton()
48 void Dialog::OKButton()
58 void Dialog::CancelButton()
65 void Dialog::RestoreButton()
67 // Tell the kernel that a request to refresh the dialog's contents
68 // has been received. It's up to the kernel to supply the necessary
69 // info by calling Dialog::update().
70 kernel().updateDialog(name_);
75 void Dialog::show(string const & data)
77 if (controller().isBufferDependent() && !kernel().isBufferAvailable())
80 if (!controller().initialiseParams(data)) {
81 lyxerr << "Dialog \"" << name_
82 << "\" failed to translate the data "
83 "string passed to show()" << std::endl;
87 bc().readOnly(kernel().isBufferReadonly());
90 // The widgets may not be valid, so refresh the button controller
95 void Dialog::update(string const & data)
97 if (controller().isBufferDependent() && !kernel().isBufferAvailable())
100 if (!controller().initialiseParams(data)) {
101 lyxerr << "Dialog \"" << name_
102 << "\" could not be initialized" << std::endl;
106 bc().readOnly(kernel().isBufferReadonly());
109 // The widgets may not be valid, so refresh the button controller
116 if (!view().isVisible())
119 controller().clearParams();
121 kernel().disconnect(name());
127 if (controller().isBufferDependent()) {
128 if (!kernel().isBufferAvailable() ||
129 kernel().isBufferReadonly())
134 controller().dispatchParams();
136 if (controller().disconnectOnApply() && !is_closing_) {
137 kernel().disconnect(name());
138 controller().initialiseParams(string());
144 bool Dialog::isVisible() const
146 return view().isVisible();
150 void Dialog::redraw()
156 ButtonController & Dialog::bc() const
158 BOOST_ASSERT(bc_ptr_.get());
159 return *bc_ptr_.get();
163 void Dialog::setController(Controller * i)
165 BOOST_ASSERT(i && !controller_ptr_.get());
166 controller_ptr_.reset(i);
170 void Dialog::setView(View * v)
172 BOOST_ASSERT(v && !view_ptr_.get());
177 void Dialog::checkStatus()
179 // buffer independant dialogs are always active.
180 // This check allows us leave canApply unimplemented for some dialogs.
181 if (!controller().isBufferDependent())
184 // deactivate the dialog if we have no buffer
185 if (!kernel().isBufferAvailable()) {
190 // check whether this dialog may be active
191 if (controller().canApply()) {
192 bool const readonly = kernel().isBufferReadonly();
193 bc().readOnly(readonly);
194 // refreshReadOnly() is too generous in _enabling_ widgets
195 // update dialog to disable disabled widgets again
203 Dialog::Controller::Controller(Dialog & parent)
208 bool Dialog::Controller::canApply() const
210 FuncRequest const fr(getLfun(), dialog().name());
211 FuncStatus const fs(lyx::getStatus(fr));
216 Dialog::Controller & Dialog::controller() const
218 BOOST_ASSERT(controller_ptr_.get());
219 return *controller_ptr_.get();
223 Dialog::View::View(Dialog & parent, docstring title) :
224 p_(parent), title_(title)
228 Dialog::View & Dialog::view() const
230 BOOST_ASSERT(view_ptr_.get());
231 return *view_ptr_.get();
235 void Dialog::View::setTitle(docstring const & newtitle)
241 docstring const & Dialog::View::getTitle() const
247 void Dialog::View::partialUpdate(int)
250 } // namespace frontend