]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/controllers/Dialog.C
refine the logic for checking whether a dialog may apply its data or not
[lyx.git] / src / frontends / controllers / Dialog.C
index 977379089a5faca6b6123ddde786c8b73f4ec857..039c1c4f16b937636db561cbca9f1d692b4b493a 100644 (file)
 #include "ButtonController.h"
 #include "BCView.h"
 
+#include "frontends/LyXView.h"
+
+#include "funcrequest.h"
+#include "FuncStatus.h"
+#include "lyxfunc.h"
+
 
 using std::string;
 
@@ -167,11 +173,40 @@ void Dialog::setView(View * 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())
+               bc().readOnly(kernel().isBufferReadonly());
+       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(kernel().lyxview().getLyXFunc().getStatus(fr));
+       return fs.enabled();
+}
+
+
 Dialog::Controller & Dialog::controller() const
 {
        BOOST_ASSERT(controller_ptr_.get());