+void Dialog::setController(Controller * i)
+{
+ BOOST_ASSERT(i && !controller_ptr_.get());
+ controller_ptr_.reset(i);
+}
+
+
+void Dialog::setView(View * v)
+{
+ BOOST_ASSERT(v && !view_ptr_.get());
+ view_ptr_.reset(v);
+}
+
+
+void Dialog::checkStatus()
+{
+ // buffer independant dialogs are always active.
+ // This check allows us leave canApply unimplemented for some dialogs.
+ if (!controller().isBufferDependent())
+ return;
+
+ // deactivate the dialog if we have no buffer
+ if (!kernel().isBufferAvailable()) {
+ bc().readOnly(true);
+ return;
+ }
+
+ // check whether this dialog may be active
+ if (controller().canApply()) {
+ bool const readonly = kernel().isBufferReadonly();
+ bc().readOnly(readonly);
+ // refreshReadOnly() is too generous in _enabling_ widgets
+ // update dialog to disable disabled widgets again
+ if (!readonly)
+ view().update();
+ } else
+ bc().readOnly(true);
+}
+
+
+Dialog::Controller::Controller(Dialog & parent)
+ : parent_(parent)
+{}
+
+
+bool Dialog::Controller::canApply() const
+{
+ FuncRequest const fr(getLfun(), dialog().name());
+ FuncStatus const fs(lyx::getStatus(fr));
+ return fs.enabled();
+}
+
+