]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt4/GuiDialog.cpp
Complete the removal of the embedding stuff. Maybe. It's hard to be sure we got every...
[lyx.git] / src / frontends / qt4 / GuiDialog.cpp
index eb2e9f6a149882397931bf36396d6d5fa07248f6..53a132d5ff987a300eea9908fe3fb81dee4f257f 100644 (file)
 #include <config.h>
 
 #include "GuiDialog.h"
-#include "debug.h"
+#include "GuiView.h"
 #include "qt_helpers.h"
-#include "frontends/LyXView.h"
+#include "FuncRequest.h"
 
-#include <QCloseEvent>\r
-#include <QSettings>\r
-#include <QShowEvent>\r
-\r
-using std::string;
+#include "insets/InsetCommand.h"
 
-namespace lyx {
-namespace frontend {
+#include "support/debug.h"
 
-GuiDialog::GuiDialog(LyXView & lv, std::string const & name)
-       : is_closing_(false), name_(name), controller_(0)
-{
-       lyxview_ = &lv;
-}
+#include <QCloseEvent>
+#include <QMainWindow>
+#include <QSettings>
+#include <QShowEvent>
 
+using namespace std;
 
-GuiDialog::~GuiDialog()
-{
-       delete controller_;
-}
+namespace lyx {
+namespace frontend {
 
+GuiDialog::GuiDialog(GuiView & lv, QString const & name, QString const & title)
+       :  QDialog(&lv), Dialog(lv, name, "LyX: " + title), is_closing_(false)
+{}
 
-void GuiDialog::setViewTitle(docstring const & title)
+
+void GuiDialog::closeEvent(QCloseEvent * ev)
 {
-       setWindowTitle("LyX: " + toqstr(title));
+       slotClose();
+       ev->accept();
 }
 
 
@@ -61,14 +59,14 @@ void GuiDialog::slotOK()
        is_closing_ = true;
        apply();
        is_closing_ = false;
-       QDialog::hide();
+       hideView();
        bc().ok();
 }
 
 
 void GuiDialog::slotClose()
 {
-       QDialog::hide();
+       hideView();
        bc().cancel();
 }
 
@@ -78,76 +76,24 @@ void GuiDialog::slotRestore()
        // Tell the controller that a request to refresh the dialog's contents
        // has been received. It's up to the controller to supply the necessary
        // info by calling GuiDialog::updateView().
-       controller().updateDialog(name_);
+       updateDialog();
        bc().restore();
 }
 
-void GuiDialog::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 (!controller().isBufferAvailable()) {
-               bc().setReadOnly(true);
-               return;
-       }
-
-       // check whether this dialog may be active
-       if (controller().canApply()) {
-               bool const readonly = controller().isBufferReadonly();
-               bc().setReadOnly(readonly);
-               // refreshReadOnly() is too generous in _enabling_ widgets
-               // update dialog to disable disabled widgets again
 
-               if (!readonly || controller().canApplyToReadOnly())
-                       updateView();
-
-       } else {
-               bc().setReadOnly(true);
-       }       
-}
-
-
-bool GuiDialog::isVisibleView() const
-{
-       return QDialog::isVisible();
-}
-
-
-void GuiDialog::showView()
+void GuiDialog::changed()
 {
-       QSize const hint = sizeHint();
-       if (hint.height() >= 0 && hint.width() >= 0)
-               setMinimumSize(hint);
-
-       updateView();  // make sure its up-to-date
-       if (controller().exitEarly())
+       if (updating_)
                return;
-
-       if (QWidget::isVisible()) {
-               raise();
-               activateWindow();
-       } else {
-               QWidget::show();
-       }
-       setFocus();
-}
-
-
-void GuiDialog::hideView()
-{
-       QDialog::hide();
+       bc().setValid(isValid());
 }
 
 
-void GuiDialog::changed()
+void GuiDialog::enableView(bool enable)
 {
-       if (updating_)
-               return;
-       bc().setValid(isValid());
+       bc().setReadOnly(!enable);
+       bc().setValid(enable);
+       Dialog::enableView(enable);
 }
 
 
@@ -155,113 +101,51 @@ void GuiDialog::updateView()
 {
        setUpdatesEnabled(false);
 
+       bc().setReadOnly(isBufferReadonly());
        // protect the BC from unwarranted state transitions
        updating_ = true;
        updateContents();
        updating_ = false;
+       // The widgets may not be valid, so refresh the button controller
+       bc().refresh();
 
        setUpdatesEnabled(true);
-       QDialog::update();
 }
 
 
-void GuiDialog::showData(string const & data)
-{
-       if (controller().isBufferDependent() && !controller().isBufferAvailable())
-               return;
-
-       if (!controller().initialiseParams(data)) {
-               lyxerr << "Dialog \"" << name_
-                      << "\" failed to translate the data "
-                       "string passed to show()" << std::endl;
-               return;
-       }
-
-       bc().setReadOnly(controller().isBufferReadonly());
-       showView();
-       // The widgets may not be valid, so refresh the button controller
-       bc().refresh();
-}
+/////////////////////////////////////////////////////////////////////
+//
+// Command based dialogs
+//
+/////////////////////////////////////////////////////////////////////
 
 
-void GuiDialog::updateData(string const & data)
+GuiCommand::GuiCommand(GuiView & lv, QString const & name,
+       QString const & title)
+       : GuiDialog(lv, name, title), params_(insetCode(fromqstr(name))),
+               lfun_name_(fromqstr(name))
 {
-       if (controller().isBufferDependent() && !controller().isBufferAvailable())
-               return;
-
-       if (!controller().initialiseParams(data)) {
-               lyxerr << "Dialog \"" << name_
-                      << "\" could not be initialized" << std::endl;
-               return;
-       }
-
-       bc().setReadOnly(controller().isBufferReadonly());
-       updateView();
-       // The widgets may not be valid, so refresh the button controller
-       bc().refresh();
 }
 
 
-void GuiDialog::hide()
+bool GuiCommand::initialiseParams(string const & data)
 {
-       if (!isVisibleView())
-               return;
-
-       controller().clearParams();
-       hideView();
-       controller().disconnect(name_);
+       // The name passed with LFUN_INSET_APPLY is also the name
+       // used to identify the mailer.
+       InsetCommand::string2params(lfun_name_, data, params_);
+       return true;
 }
 
 
-void GuiDialog::apply()
+void GuiCommand::dispatchParams()
 {
-       if (controller().isBufferDependent()) {
-               if (!controller().isBufferAvailable() ||
-                   (controller().isBufferReadonly() && !controller().canApplyToReadOnly()))
-                       return;
-       }
-
-       applyView();
-       controller().dispatchParams();
-
-       if (controller().disconnectOnApply() && !is_closing_) {
-               controller().disconnect(name_);
-               controller().initialiseParams(string());
-               updateView();
-       }
-}
-
+       if (lfun_name_.empty())
+               return;
 
-void GuiDialog::setController(Controller * controller)
-{
-       BOOST_ASSERT(controller);
-       BOOST_ASSERT(!controller_);
-       controller_ = controller;
-       controller_->setLyXView(*lyxview_);
+       string const lfun = InsetCommand::params2string(lfun_name_, params_);
+       dispatch(FuncRequest(getLfun(), lfun));
 }
 
-
-void GuiDialog::showEvent(QShowEvent * e)\r
-{\r
-#if (QT_VERSION >= 0x040200)\r
-       QSettings settings;\r
-       string key = name_ + "/geometry";\r
-       restoreGeometry(settings.value(key.c_str()).toByteArray());\r
-#endif\r
-       QDialog::showEvent(e);\r
-}\r
-\r
-\r
-void GuiDialog::closeEvent(QCloseEvent * e)\r
-{\r
-#if (QT_VERSION >= 0x040200)\r
-       QSettings settings;\r
-       string key = name_ + "/geometry";\r
-       settings.setValue(key.c_str(), saveGeometry());\r
-#endif\r
-       QDialog::closeEvent(e);\r
-}\r
-
 } // namespace frontend
 } // namespace lyx