]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/controllers/Dialog.C
Rename .C => .cpp for files in src/frontends/controllers, step 1
[lyx.git] / src / frontends / controllers / Dialog.C
index 977379089a5faca6b6123ddde786c8b73f4ec857..6c0aee8d2cbad378cd92b2d35ab03d8b7caf9515 100644 (file)
@@ -1,5 +1,5 @@
 /**
- * \file Dialog.C
+ * \file Dialog.cpp
  * This file is part of LyX, the document processor.
  * Licence details can be found in the file COPYING.
  *
 #include "ButtonController.h"
 #include "BCView.h"
 
+#include "frontends/LyXView.h"
+
+#include "funcrequest.h"
+#include "FuncStatus.h"
+#include "lyxfunc.h"
+
+using lyx::docstring;
 
 using std::string;
 
@@ -167,11 +174,45 @@ 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()) {
+               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();
+}
+
+
 Dialog::Controller & Dialog::controller() const
 {
        BOOST_ASSERT(controller_ptr_.get());
@@ -179,7 +220,7 @@ Dialog::Controller & Dialog::controller() const
 }
 
 
-Dialog::View::View(Dialog & parent, string title) :
+Dialog::View::View(Dialog & parent, docstring title) :
        p_(parent), title_(title)
 {}
 
@@ -191,13 +232,13 @@ Dialog::View & Dialog::view() const
 }
 
 
-void Dialog::View::setTitle(string const & newtitle)
+void Dialog::View::setTitle(docstring const & newtitle)
 {
        title_ = newtitle;
 }
 
 
-string const & Dialog::View::getTitle() const
+docstring const & Dialog::View::getTitle() const
 {
        return title_;
 }