]> 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 29a4a141c797ee71b291a55b1d1c3ef6869bbb93..6c0aee8d2cbad378cd92b2d35ab03d8b7caf9515 100644 (file)
@@ -1,12 +1,11 @@
-// -*- C++ -*-
 /**
- * \file Dialog.C
+ * \file Dialog.cpp
  * This file is part of LyX, the document processor.
  * Licence details can be found in the file COPYING.
  *
  * \author Angus Leeming
  *
- * Full author contact details are available in file CREDITS
+ * Full author contact details are available in file CREDITS.
  */
 
 #include <config.h>
 
 #include "ButtonController.h"
 #include "BCView.h"
-#include "support/LAssert.h"
 
+#include "frontends/LyXView.h"
+
+#include "funcrequest.h"
+#include "FuncStatus.h"
+#include "lyxfunc.h"
+
+using lyx::docstring;
+
+using std::string;
+
+namespace lyx {
+namespace frontend {
 
 Dialog::Dialog(LyXView & lv, string const & name)
        : is_closing_(false), kernel_(lv), name_(name),
@@ -67,7 +77,13 @@ void Dialog::show(string const & data)
        if (controller().isBufferDependent() && !kernel().isBufferAvailable())
                return;
 
-       controller().initialiseParams(data);
+       if (!controller().initialiseParams(data)) {
+               lyxerr << "Dialog \"" << name_
+                      << "\" failed to translate the data "
+                       "string passed to show()" << std::endl;
+               return;
+       }
+
        bc().readOnly(kernel().isBufferReadonly());
        view().show();
 
@@ -81,7 +97,11 @@ void Dialog::update(string const & data)
        if (controller().isBufferDependent() && !kernel().isBufferAvailable())
                return;
 
-       controller().initialiseParams(data);
+       if (!controller().initialiseParams(data)) {
+               lyxerr << "Dialog \"" << name_
+                      << "\" could not be initialized" << std::endl;
+               return;
+       }
 
        bc().readOnly(kernel().isBufferReadonly());
        view().update();
@@ -98,20 +118,24 @@ void Dialog::hide()
 
        controller().clearParams();
        view().hide();
+       kernel().disconnect(name());
 }
 
 
 void Dialog::apply()
 {
-       if (kernel().isBufferReadonly())
-               return;
+       if (controller().isBufferDependent()) {
+               if (!kernel().isBufferAvailable() ||
+                   kernel().isBufferReadonly())
+                       return;
+       }
 
        view().apply();
        controller().dispatchParams();
 
        if (controller().disconnectOnApply() && !is_closing_) {
                kernel().disconnect(name());
-               controller().initialiseParams(string());
+               controller().initialiseParams(string());
                view().update();
        }
 }
@@ -131,34 +155,97 @@ void Dialog::redraw()
 
 ButtonController & Dialog::bc() const
 {
-       lyx::Assert(bc_ptr_.get());
+       BOOST_ASSERT(bc_ptr_.get());
        return *bc_ptr_.get();
 }
 
 
+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();
+}
+
+
 Dialog::Controller & Dialog::controller() const
 {
-       lyx::Assert(controller_ptr_.get());
+       BOOST_ASSERT(controller_ptr_.get());
        return *controller_ptr_.get();
 }
 
 
+Dialog::View::View(Dialog & parent, docstring title) :
+       p_(parent), title_(title)
+{}
+
+
 Dialog::View & Dialog::view() const
 {
-       lyx::Assert(view_ptr_.get());
+       BOOST_ASSERT(view_ptr_.get());
        return *view_ptr_.get();
 }
 
 
-void Dialog::setController(Controller * i)
+void Dialog::View::setTitle(docstring const & newtitle)
 {
-       lyx::Assert(i && !controller_ptr_.get());
-       controller_ptr_.reset(i);
+       title_ = newtitle;
 }
 
 
-void Dialog::setView(View * v)
+docstring const & Dialog::View::getTitle() const
 {
-       lyx::Assert(v && !view_ptr_.get());
-       view_ptr_.reset(v);
+       return title_;
 }
+
+
+void Dialog::View::partialUpdate(int)
+{}
+
+} // namespace frontend
+} // namespace lyx