#include <config.h>
#include "GuiDialog.h"
-#include "debug.h"
+#include "GuiView.h"
#include "qt_helpers.h"
+#include "FuncRequest.h"
+
+#include "insets/InsetCommand.h"
+
+#include "support/debug.h"
+
+#include <QCloseEvent>
+#include <QMainWindow>
+#include <QSettings>
+#include <QShowEvent>
+
+using namespace std;
namespace lyx {
namespace frontend {
-GuiDialog::GuiDialog(LyXView & lv, std::string const & name)
- : Dialog(lv, name)
+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();
}
}
-void GuiDialog::ApplyButton()
+void GuiDialog::slotApply()
{
apply();
bc().apply();
}
-void GuiDialog::OKButton()
+void GuiDialog::slotOK()
{
is_closing_ = true;
apply();
is_closing_ = false;
- QDialog::hide();
+ hideView();
bc().ok();
}
-void GuiDialog::CancelButton()
+void GuiDialog::slotClose()
{
- QDialog::hide();
+ hideView();
bc().cancel();
}
-void GuiDialog::RestoreButton()
+void GuiDialog::slotRestore()
{
- // Tell the kernel that a request to refresh the dialog's contents
- // has been received. It's up to the kernel to supply the necessary
+ // 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().
- kernel().updateDialog(name_);
+ updateDialog();
bc().restore();
}
-void GuiDialog::preShow()
+void GuiDialog::changed()
{
- bc().setReadOnly(kernel().isBufferReadonly());
+ if (updating_)
+ return;
+ bc().setValid(isValid());
}
-void GuiDialog::postShow()
+void GuiDialog::enableView(bool enable)
{
- // The widgets may not be valid, so refresh the button controller
- bc().refresh();
+ bc().setReadOnly(!enable);
+ bc().setValid(enable);
+ Dialog::enableView(enable);
}
-void GuiDialog::preUpdate()
+void GuiDialog::updateView()
{
- bc().setReadOnly(kernel().isBufferReadonly());
-}
-
+ setUpdatesEnabled(false);
-void GuiDialog::postUpdate()
-{
+ 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();
-}
-
-
-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 (!kernel().isBufferAvailable()) {
- bc().setReadOnly(true);
- return;
- }
-
- // check whether this dialog may be active
- if (controller().canApply()) {
- bool const readonly = kernel().isBufferReadonly();
- bc().setReadOnly(readonly);
- // refreshReadOnly() is too generous in _enabling_ widgets
- // update dialog to disable disabled widgets again
-/*
- * FIXME:
- if (!readonly || controller().canApplyToReadOnly())
- update();
-*/
- } else {
- bc().setReadOnly(true);
- }
-}
-
-bool GuiDialog::isVisibleView() const
-{
- return QDialog::isVisible();
+ setUpdatesEnabled(true);
}
-bool GuiDialog::readOnly() const
-{
- return kernel().isBufferReadonly();
-}
+/////////////////////////////////////////////////////////////////////
+//
+// Command based dialogs
+//
+/////////////////////////////////////////////////////////////////////
-void GuiDialog::showView()
+GuiCommand::GuiCommand(GuiView & lv, QString const & name,
+ QString const & title)
+ : GuiDialog(lv, name, title), params_(insetCode(fromqstr(name))),
+ lfun_name_(fromqstr(name))
{
- QSize const hint = sizeHint();
- if (hint.height() >= 0 && hint.width() >= 0)
- setMinimumSize(hint);
-
- updateView(); // make sure its up-to-date
- if (controller().exitEarly())
- return;
-
- if (QWidget::isVisible()) {
- raise();
- activateWindow();
- } else {
- QWidget::show();
- }
- setFocus();
}
-void GuiDialog::hideView()
-{
- QDialog::hide();
-}
-
-
-bool GuiDialog::isValid()
+bool GuiCommand::initialiseParams(string const & data)
{
+ // The name passed with LFUN_INSET_APPLY is also the name
+ // used to identify the mailer.
+ InsetCommandMailer::string2params(lfun_name_, data, params_);
return true;
}
-void GuiDialog::changed()
+void GuiCommand::dispatchParams()
{
- if (updating_)
+ if (lfun_name_.empty())
return;
- bc().setValid(isValid());
-}
-
-
-void GuiDialog::slotWMHide()
-{
- CancelButton();
-}
-
-
-void GuiDialog::slotApply()
-{
- ApplyButton();
-}
-
-
-void GuiDialog::slotOK()
-{
- OKButton();
-}
-
-void GuiDialog::slotClose()
-{
- CancelButton();
-}
-
-
-void GuiDialog::slotRestore()
-{
- RestoreButton();
-}
-
-void GuiDialog::updateView()
-{
- setUpdatesEnabled(false);
-
- // protect the BC from unwarranted state transitions
- updating_ = true;
- update_contents();
- updating_ = false;
-
- setUpdatesEnabled(true);
- QDialog::update();
+ string const lfun =
+ InsetCommandMailer::params2string(lfun_name_, params_);
+ dispatch(FuncRequest(getLfun(), lfun));
}
} // namespace frontend